Allow IDEA run configs to be generated for non-root projects (#236)
parent
d7f61512b5
commit
4aa840adfe
|
@ -230,7 +230,7 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
project1.getTasks().getByName("eclipse").finalizedBy(project1.getTasks().getByName("genEclipseRuns"));
|
project1.getTasks().getByName("eclipse").finalizedBy(project1.getTasks().getByName("genEclipseRuns"));
|
||||||
project1.getTasks().getByName("cleanEclipse").finalizedBy(project1.getTasks().getByName("cleanEclipseRuns"));
|
project1.getTasks().getByName("cleanEclipse").finalizedBy(project1.getTasks().getByName("cleanEclipseRuns"));
|
||||||
|
|
||||||
if (extension.autoGenIDERuns && isRootProject(project1)) {
|
if (extension.autoGenIDERuns) {
|
||||||
SetupIntelijRunConfigs.setup(project1);
|
SetupIntelijRunConfigs.setup(project1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class LoomGradleExtension {
|
||||||
public String refmapName;
|
public String refmapName;
|
||||||
public String loaderLaunchMethod;
|
public String loaderLaunchMethod;
|
||||||
public boolean remapMod = true;
|
public boolean remapMod = true;
|
||||||
public boolean autoGenIDERuns = true;
|
public boolean autoGenIDERuns;
|
||||||
public String customManifest = null;
|
public String customManifest = null;
|
||||||
public File accessWidener = null;
|
public File accessWidener = null;
|
||||||
public Function<String, Object> intermediaryUrl = mcVer -> "https://maven.fabricmc.net/net/fabricmc/intermediary/" + mcVer + "/intermediary-" + mcVer + "-v2.jar";
|
public Function<String, Object> intermediaryUrl = mcVer -> "https://maven.fabricmc.net/net/fabricmc/intermediary/" + mcVer + "/intermediary-" + mcVer + "-v2.jar";
|
||||||
|
@ -93,6 +93,7 @@ public class LoomGradleExtension {
|
||||||
|
|
||||||
public LoomGradleExtension(Project project) {
|
public LoomGradleExtension(Project project) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
this.autoGenIDERuns = AbstractPlugin.isRootProject(project);
|
||||||
this.unmappedMods = project.files();
|
this.unmappedMods = project.files();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +223,7 @@ public class LoomGradleExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getDevLauncherConfig() {
|
public File getDevLauncherConfig() {
|
||||||
return new File(getRootProjectPersistentCache(), "launch.cfg");
|
return new File(getProjectPersistentCache(), "launch.cfg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
package net.fabricmc.loom.util;
|
package net.fabricmc.loom.util;
|
||||||
|
|
||||||
|
import static net.fabricmc.loom.AbstractPlugin.isRootProject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -53,7 +55,8 @@ import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
|
|
||||||
public class RunConfig {
|
public class RunConfig {
|
||||||
public String configName;
|
public String configName;
|
||||||
public String projectName;
|
public String eclipseProjectName;
|
||||||
|
public String ideaModuleName;
|
||||||
public String mainClass;
|
public String mainClass;
|
||||||
public String runDir;
|
public String runDir;
|
||||||
public String vmArgs;
|
public String vmArgs;
|
||||||
|
@ -63,7 +66,7 @@ public class RunConfig {
|
||||||
Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
|
Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
|
||||||
root = addXml(root, "configuration", ImmutableMap.of("default", "false", "name", configName, "type", "Application", "factoryName", "Application"));
|
root = addXml(root, "configuration", ImmutableMap.of("default", "false", "name", configName, "type", "Application", "factoryName", "Application"));
|
||||||
|
|
||||||
this.addXml(root, "module", ImmutableMap.of("name", projectName));
|
this.addXml(root, "module", ImmutableMap.of("name", ideaModuleName));
|
||||||
this.addXml(root, "option", ImmutableMap.of("name", "MAIN_CLASS_NAME", "value", mainClass));
|
this.addXml(root, "option", ImmutableMap.of("name", "MAIN_CLASS_NAME", "value", mainClass));
|
||||||
this.addXml(root, "option", ImmutableMap.of("name", "WORKING_DIRECTORY", "value", runDir));
|
this.addXml(root, "option", ImmutableMap.of("name", "WORKING_DIRECTORY", "value", runDir));
|
||||||
|
|
||||||
|
@ -95,8 +98,20 @@ public class RunConfig {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getIdeaModuleName(Project project) {
|
||||||
|
String module = project.getName() + ".main";
|
||||||
|
|
||||||
|
while ((project = project.getParent()) != null) {
|
||||||
|
module = project.getName() + "." + module;
|
||||||
|
}
|
||||||
|
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
|
||||||
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) {
|
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) {
|
||||||
runConfig.projectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
|
runConfig.configName += isRootProject(project) ? "" : " (" + project.getPath() + ")";
|
||||||
|
runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
|
||||||
|
runConfig.ideaModuleName = getIdeaModuleName(project);
|
||||||
runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||||
runConfig.vmArgs = "";
|
runConfig.vmArgs = "";
|
||||||
|
|
||||||
|
@ -148,8 +163,8 @@ public class RunConfig {
|
||||||
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.getVersionInfo();
|
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.getVersionInfo();
|
||||||
|
|
||||||
RunConfig ideaClient = new RunConfig();
|
RunConfig ideaClient = new RunConfig();
|
||||||
populate(project, extension, ideaClient, "client");
|
|
||||||
ideaClient.configName = "Minecraft Client";
|
ideaClient.configName = "Minecraft Client";
|
||||||
|
populate(project, extension, ideaClient, "client");
|
||||||
ideaClient.vmArgs += getOSClientJVMArgs();
|
ideaClient.vmArgs += getOSClientJVMArgs();
|
||||||
ideaClient.vmArgs += " -Dfabric.dli.main=" + getMainClass("client", extension);
|
ideaClient.vmArgs += " -Dfabric.dli.main=" + getMainClass("client", extension);
|
||||||
|
|
||||||
|
@ -160,8 +175,8 @@ public class RunConfig {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
||||||
RunConfig ideaServer = new RunConfig();
|
RunConfig ideaServer = new RunConfig();
|
||||||
populate(project, extension, ideaServer, "server");
|
|
||||||
ideaServer.configName = "Minecraft Server";
|
ideaServer.configName = "Minecraft Server";
|
||||||
|
populate(project, extension, ideaServer, "server");
|
||||||
ideaServer.vmArgs += " -Dfabric.dli.main=" + getMainClass("server", extension);
|
ideaServer.vmArgs += " -Dfabric.dli.main=" + getMainClass("server", extension);
|
||||||
|
|
||||||
return ideaServer;
|
return ideaServer;
|
||||||
|
@ -182,7 +197,8 @@ public class RunConfig {
|
||||||
|
|
||||||
dummyConfig = dummyConfig.replace("%NAME%", configName);
|
dummyConfig = dummyConfig.replace("%NAME%", configName);
|
||||||
dummyConfig = dummyConfig.replace("%MAIN_CLASS%", mainClass);
|
dummyConfig = dummyConfig.replace("%MAIN_CLASS%", mainClass);
|
||||||
dummyConfig = dummyConfig.replace("%MODULE%", projectName);
|
dummyConfig = dummyConfig.replace("%ECLIPSE_PROJECT%", eclipseProjectName);
|
||||||
|
dummyConfig = dummyConfig.replace("%IDEA_MODULE%", ideaModuleName);
|
||||||
dummyConfig = dummyConfig.replace("%PROGRAM_ARGS%", programArgs.replaceAll("\"", """));
|
dummyConfig = dummyConfig.replace("%PROGRAM_ARGS%", programArgs.replaceAll("\"", """));
|
||||||
dummyConfig = dummyConfig.replace("%VM_ARGS%", vmArgs.replaceAll("\"", """));
|
dummyConfig = dummyConfig.replace("%VM_ARGS%", vmArgs.replaceAll("\"", """));
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class SetupIntelijRunConfigs {
|
||||||
public static void setup(Project project) {
|
public static void setup(Project project) {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
||||||
File projectDir = project.file(".idea");
|
File projectDir = project.getRootProject().file(".idea");
|
||||||
|
|
||||||
if (!projectDir.exists()) {
|
if (!projectDir.exists()) {
|
||||||
return;
|
return;
|
||||||
|
@ -59,6 +59,7 @@ public class SetupIntelijRunConfigs {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generate(Project project) throws IOException {
|
private static void generate(Project project) throws IOException {
|
||||||
|
Project rootProject = project.getRootProject();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
||||||
if (extension.ideSync()) {
|
if (extension.ideSync()) {
|
||||||
|
@ -67,10 +68,12 @@ public class SetupIntelijRunConfigs {
|
||||||
MinecraftNativesProvider.provide(extension.getMinecraftProvider(), project);
|
MinecraftNativesProvider.provide(extension.getMinecraftProvider(), project);
|
||||||
}
|
}
|
||||||
|
|
||||||
File projectDir = project.file(".idea");
|
String projectPath = project == rootProject ? "" : project.getPath().replace(':', '_');
|
||||||
|
|
||||||
|
File projectDir = rootProject.file(".idea");
|
||||||
File runConfigsDir = new File(projectDir, "runConfigurations");
|
File runConfigsDir = new File(projectDir, "runConfigurations");
|
||||||
File clientRunConfigs = new File(runConfigsDir, "Minecraft_Client.xml");
|
File clientRunConfigs = new File(runConfigsDir, "Minecraft_Client" + projectPath + ".xml");
|
||||||
File serverRunConfigs = new File(runConfigsDir, "Minecraft_Server.xml");
|
File serverRunConfigs = new File(runConfigsDir, "Minecraft_Server" + projectPath + ".xml");
|
||||||
|
|
||||||
if (!runConfigsDir.exists()) {
|
if (!runConfigsDir.exists()) {
|
||||||
runConfigsDir.mkdirs();
|
runConfigsDir.mkdirs();
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.buildship.core.classpathprovider"/>
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.buildship.core.classpathprovider"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="%MAIN_CLASS%"/>
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="%MAIN_CLASS%"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="%PROGRAM_ARGS%"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="%PROGRAM_ARGS%"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%MODULE%"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%ECLIPSE_PROJECT%"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="%VM_ARGS%"/>
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="%VM_ARGS%"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:%MODULE%}/run"/>
|
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:%MODULE%}/run"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="%NAME%" type="Application" factoryName="Application">
|
<configuration default="false" name="%NAME%" type="Application" factoryName="Application">
|
||||||
<option name="MAIN_CLASS_NAME" value="%MAIN_CLASS%" />
|
<option name="MAIN_CLASS_NAME" value="%MAIN_CLASS%" />
|
||||||
<module name="%MODULE%.main" />
|
<module name="%IDEA_MODULE%" />
|
||||||
<option name="PROGRAM_PARAMETERS" value="%PROGRAM_ARGS%" />
|
<option name="PROGRAM_PARAMETERS" value="%PROGRAM_ARGS%" />
|
||||||
<option name="VM_PARAMETERS" value="%VM_ARGS%" />
|
<option name="VM_PARAMETERS" value="%VM_ARGS%" />
|
||||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/" />
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/" />
|
||||||
|
|
Loading…
Reference in New Issue