Generate idea run configs for dir based projects
parent
9d03783792
commit
9ed5dd7a01
|
@ -25,12 +25,12 @@
|
||||||
package net.fabricmc.loom;
|
package net.fabricmc.loom;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
import net.fabricmc.loom.providers.ModRemapperProvider;
|
import net.fabricmc.loom.providers.ModRemapperProvider;
|
||||||
import net.fabricmc.loom.util.*;
|
import net.fabricmc.loom.util.Constants;
|
||||||
|
import net.fabricmc.loom.util.LoomDependencyManager;
|
||||||
|
import net.fabricmc.loom.util.ModRemapper;
|
||||||
|
import net.fabricmc.loom.util.SetupIntelijRunConfigs;
|
||||||
import org.gradle.api.Plugin;
|
import org.gradle.api.Plugin;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
|
@ -41,13 +41,10 @@ import org.gradle.api.plugins.JavaPluginConvention;
|
||||||
import org.gradle.api.tasks.SourceSet;
|
import org.gradle.api.tasks.SourceSet;
|
||||||
import org.gradle.api.tasks.compile.JavaCompile;
|
import org.gradle.api.tasks.compile.JavaCompile;
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||||
import org.gradle.plugins.ide.api.GeneratorTask;
|
|
||||||
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
||||||
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -220,6 +217,8 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
dependencyManager.handleDependencies(project1);
|
dependencyManager.handleDependencies(project1);
|
||||||
|
|
||||||
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
|
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
|
||||||
|
|
||||||
|
SetupIntelijRunConfigs.setup(project1);
|
||||||
});
|
});
|
||||||
|
|
||||||
project.getTasks().getByName("jar").doLast(task -> {
|
project.getTasks().getByName("jar").doLast(task -> {
|
||||||
|
|
|
@ -75,13 +75,6 @@ public class MinecraftLibraryProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//adds the natvies to compile //TODO extract natives
|
|
||||||
versionInfo.libraries.stream().filter(lib -> lib.natives != null).forEach(lib -> minecraftProvider.addDep(lib.getArtifactName(), project));
|
|
||||||
|
|
||||||
// for (File source : getProject().getConfigurations().getByName(Constants.CONFIG_NATIVES)) {
|
|
||||||
// ZipUtil.unpack(source, Constants.MINECRAFT_NATIVES.get(extension));
|
|
||||||
// }
|
|
||||||
|
|
||||||
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
||||||
|
|
||||||
// get existing cache files
|
// get existing cache files
|
||||||
|
@ -155,7 +148,6 @@ public class MinecraftLibraryProvider {
|
||||||
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
|
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MINECRAFT_LIBS = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-libs");
|
MINECRAFT_LIBS = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-libs");
|
||||||
MINECRAFT_NATIVES = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-natives");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,8 @@ package net.fabricmc.loom.task;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.IdeaRunConfig;
|
import net.fabricmc.loom.util.IdeaRunConfig;
|
||||||
import net.fabricmc.loom.util.MinecraftVersionInfo;
|
|
||||||
import org.gradle.api.DefaultTask;
|
import org.gradle.api.DefaultTask;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
@ -49,7 +47,6 @@ import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GenIdeaProjectTask extends DefaultTask {
|
public class GenIdeaProjectTask extends DefaultTask {
|
||||||
|
@ -105,8 +102,7 @@ public class GenIdeaProjectTask extends DefaultTask {
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
|
|
||||||
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
|
|
||||||
|
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
Transformer transformer = transformerFactory.newTransformer();
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
@ -136,25 +132,9 @@ public class GenIdeaProjectTask extends DefaultTask {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdeaRunConfig ideaClient = new IdeaRunConfig();
|
runManager.appendChild(IdeaRunConfig.clientRunConfig(project).genRuns(runManager));
|
||||||
ideaClient.mainClass = "net.minecraft.launchwrapper.Launch";
|
|
||||||
ideaClient.projectName = project.getName();
|
|
||||||
ideaClient.configName = "Minecraft Client";
|
|
||||||
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
|
||||||
ideaClient.vmArgs = "-Djava.library.path=" + extension.getMinecraftProvider().libraryProvider.MINECRAFT_NATIVES.getAbsolutePath() + " -Dfabric.development=true";
|
|
||||||
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.id + " --assetsDir \"" + new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion).getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
|
||||||
|
|
||||||
runManager.appendChild(ideaClient.genRuns(runManager));
|
runManager.appendChild(IdeaRunConfig.serverRunConfig(project).genRuns(runManager));
|
||||||
|
|
||||||
IdeaRunConfig ideaServer = new IdeaRunConfig();
|
|
||||||
ideaServer.mainClass = "net.minecraft.launchwrapper.Launch";
|
|
||||||
ideaServer.projectName = project.getName();
|
|
||||||
ideaServer.configName = "Minecraft Server";
|
|
||||||
ideaServer.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
|
||||||
ideaServer.vmArgs = "-Dfabric.development=true";
|
|
||||||
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
|
||||||
|
|
||||||
runManager.appendChild(ideaServer.genRuns(runManager));
|
|
||||||
|
|
||||||
transformerFactory = TransformerFactory.newInstance();
|
transformerFactory = TransformerFactory.newInstance();
|
||||||
transformer = transformerFactory.newTransformer();
|
transformer = transformerFactory.newTransformer();
|
||||||
|
|
|
@ -77,8 +77,6 @@ public class RunClientTask extends JavaExec {
|
||||||
public List<String> getJvmArgs() {
|
public List<String> getJvmArgs() {
|
||||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("-Djava.library.path=" + extension.getMinecraftProvider().libraryProvider.MINECRAFT_NATIVES.getAbsolutePath());
|
|
||||||
//args.add("-XstartOnFirstThread"); //Fixes lwjgl starting on an incorrect thread
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,20 @@ package net.fabricmc.loom.util;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.gradle.api.Project;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class IdeaRunConfig {
|
public class IdeaRunConfig {
|
||||||
|
@ -74,4 +81,50 @@ public class IdeaRunConfig {
|
||||||
parent.appendChild(e);
|
parent.appendChild(e);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IdeaRunConfig clientRunConfig(Project project){
|
||||||
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
|
||||||
|
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
|
||||||
|
|
||||||
|
IdeaRunConfig ideaClient = new IdeaRunConfig();
|
||||||
|
ideaClient.mainClass = "net.minecraft.launchwrapper.Launch";
|
||||||
|
ideaClient.projectName = project.getName();
|
||||||
|
ideaClient.configName = "Minecraft Client";
|
||||||
|
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||||
|
ideaClient.vmArgs = "-Dfabric.development=true";
|
||||||
|
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.id + " --assetsDir \"" + new File(extension.getUserCache(), "assets-" + minecraftProvider.minecraftVersion).getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
||||||
|
|
||||||
|
return ideaClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IdeaRunConfig serverRunConfig(Project project){
|
||||||
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
|
||||||
|
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
|
||||||
|
|
||||||
|
IdeaRunConfig ideaServer = new IdeaRunConfig();
|
||||||
|
ideaServer.mainClass = "net.minecraft.launchwrapper.Launch";
|
||||||
|
ideaServer.projectName = project.getName();
|
||||||
|
ideaServer.configName = "Minecraft Server";
|
||||||
|
ideaServer.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||||
|
ideaServer.vmArgs = "-Dfabric.development=true";
|
||||||
|
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
|
||||||
|
|
||||||
|
return ideaServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String fromDummy() throws IOException {
|
||||||
|
InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream("dummy_runconfig.xml");
|
||||||
|
String dummyConfig = IOUtils.toString(input, StandardCharsets.UTF_8);
|
||||||
|
input.close();
|
||||||
|
|
||||||
|
dummyConfig = dummyConfig.replace("%NAME%", configName);
|
||||||
|
dummyConfig = dummyConfig.replace("%MAIN_CLASS%", mainClass);
|
||||||
|
dummyConfig = dummyConfig.replace("%MODULE%", projectName);
|
||||||
|
dummyConfig = dummyConfig.replace("%PROGRAM_ARGS%", programArgs.replaceAll("\"", """));
|
||||||
|
dummyConfig = dummyConfig.replace("%VM_ARGS%", vmArgs.replaceAll("\"", """));
|
||||||
|
|
||||||
|
return dummyConfig;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.fabricmc.loom.util;
|
||||||
|
|
||||||
|
import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class SetupIntelijRunConfigs {
|
||||||
|
|
||||||
|
public static void setup(Project project) {
|
||||||
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
||||||
|
File projectDir = new File(".idea");
|
||||||
|
if(!projectDir.exists()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
generate(project);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to generate run configs", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File runDir = new File(Constants.WORKING_DIRECTORY, extension.runDir);
|
||||||
|
if (!runDir.exists()) {
|
||||||
|
runDir.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generate(Project project) throws IOException {
|
||||||
|
File projectDir = new File(".idea");
|
||||||
|
File runConfigsDir = new File(projectDir, "runConfigurations");
|
||||||
|
File clientRunConfigs = new File(runConfigsDir, "Minecraft_Client.xml");
|
||||||
|
File serverRunConfigs = new File(runConfigsDir, "Minecraft_Server.xml");
|
||||||
|
|
||||||
|
if(!runConfigsDir.exists()){
|
||||||
|
runConfigsDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
String clientRunConfig = IdeaRunConfig.clientRunConfig(project).fromDummy();
|
||||||
|
String serverRunConfig = IdeaRunConfig.serverRunConfig(project).fromDummy();
|
||||||
|
|
||||||
|
FileUtils.writeStringToFile(clientRunConfigs, clientRunConfig, StandardCharsets.UTF_8);
|
||||||
|
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="%NAME%" type="Application" factoryName="Application">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="%MAIN_CLASS%" />
|
||||||
|
<module name="%MODULE%" />
|
||||||
|
<option name="PROGRAM_PARAMETERS" value="%PROGRAM_ARGS%" />
|
||||||
|
<option name="VM_PARAMETERS" value="%VM_ARGS%" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
Loading…
Reference in New Issue