Make Run Config run dir relative to the project and not the root project. Move eclipse launch config files out of the root project. Closes #509
parent
d57f61a38a
commit
ce0a3308ff
|
@ -27,6 +27,7 @@ package net.fabricmc.loom.configuration.ide;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -181,13 +182,23 @@ public class RunConfig {
|
|||
return runConfig;
|
||||
}
|
||||
|
||||
public String fromDummy(String dummy) throws IOException {
|
||||
public String fromDummy(String dummy, boolean relativeDir, Project project) throws IOException {
|
||||
String dummyConfig;
|
||||
|
||||
try (InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream(dummy)) {
|
||||
dummyConfig = new String(input.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
String runDir = this.runDir;
|
||||
|
||||
if (relativeDir && project.getRootProject() != project) {
|
||||
Path rootPath = project.getRootDir().toPath();
|
||||
Path projectPath = project.getProjectDir().toPath();
|
||||
String relativePath = rootPath.relativize(projectPath).toString();
|
||||
|
||||
runDir = relativePath + "/" + runDir;
|
||||
}
|
||||
|
||||
dummyConfig = dummyConfig.replace("%NAME%", configName);
|
||||
dummyConfig = dummyConfig.replace("%MAIN_CLASS%", mainClass);
|
||||
dummyConfig = dummyConfig.replace("%ECLIPSE_PROJECT%", eclipseProjectName);
|
||||
|
|
|
@ -289,7 +289,7 @@ public final class RunConfigSettings implements Named {
|
|||
}
|
||||
|
||||
public void makeRunDir() {
|
||||
File file = new File(getProject().getRootDir(), runDir);
|
||||
File file = new File(getProject().getProjectDir(), runDir);
|
||||
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
|
|
|
@ -37,8 +37,6 @@ import net.fabricmc.loom.configuration.providers.minecraft.assets.MinecraftAsset
|
|||
|
||||
public class SetupIntelijRunConfigs {
|
||||
public static void setup(Project project) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
File projectDir = project.getRootProject().file(".idea");
|
||||
|
||||
if (!projectDir.exists()) {
|
||||
|
@ -80,7 +78,7 @@ public class SetupIntelijRunConfigs {
|
|||
String name = config.configName.replaceAll("[^a-zA-Z0-9$_]", "_");
|
||||
|
||||
File runConfigs = new File(runConfigsDir, name + projectPath + ".xml");
|
||||
String runConfigXml = config.fromDummy("idea_run_config_template.xml");
|
||||
String runConfigXml = config.fromDummy("idea_run_config_template.xml", true, project);
|
||||
|
||||
if (!runConfigs.exists()) {
|
||||
FileUtils.writeStringToFile(runConfigs, runConfigXml, StandardCharsets.UTF_8);
|
||||
|
|
|
@ -49,9 +49,9 @@ public class GenEclipseRunsTask extends AbstractLoomTask {
|
|||
|
||||
String name = settings.getName();
|
||||
|
||||
File configs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_" + name + ".launch");
|
||||
File configs = new File(getProject().getProjectDir(), eclipseModel.getProject().getName() + "_" + name + ".launch");
|
||||
RunConfig configInst = RunConfig.runConfig(getProject(), settings);
|
||||
String config = configInst.fromDummy("eclipse_run_config_template.xml");
|
||||
String config = configInst.fromDummy("eclipse_run_config_template.xml", false, getProject());
|
||||
|
||||
if (!configs.exists()) {
|
||||
FileUtils.writeStringToFile(configs, config, StandardCharsets.UTF_8);
|
||||
|
|
|
@ -27,6 +27,7 @@ package net.fabricmc.loom.task;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -78,7 +79,7 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
|||
}
|
||||
}
|
||||
|
||||
private static class VsCodeLaunch {
|
||||
private class VsCodeLaunch {
|
||||
public String version = "0.2.0";
|
||||
public List<VsCodeConfiguration> configurations = new ArrayList<>();
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class VsCodeConfiguration {
|
||||
private class VsCodeConfiguration {
|
||||
public String type = "java";
|
||||
public String name;
|
||||
public String request = "launch";
|
||||
|
@ -105,6 +106,14 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
|||
this.vmArgs = runConfig.vmArgs;
|
||||
this.args = runConfig.programArgs;
|
||||
this.cwd = "${workspaceFolder}/" + runConfig.runDir;
|
||||
|
||||
if (getProject().getRootProject() != getProject()) {
|
||||
Path rootPath = getProject().getRootDir().toPath();
|
||||
Path projectPath = getProject().getProjectDir().toPath();
|
||||
String relativePath = rootPath.relativize(projectPath).toString();
|
||||
|
||||
this.cwd = "${workspaceFolder}/%s/%s".formatted(relativePath, runConfig.runDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class MultiProjectTest extends Specification implements GradleProjectTestTrait {
|
|||
def gradle = gradleProject(project: "multiproject", version: version)
|
||||
|
||||
when:
|
||||
def result = gradle.run(task: "build")
|
||||
def result = gradle.run(tasks: ["build", "eclipse", "vscode", "idea"])
|
||||
|
||||
then:
|
||||
result.task(":build").outcome == SUCCESS
|
||||
|
|
|
@ -2,4 +2,10 @@ archivesBaseName = "example"
|
|||
|
||||
dependencies {
|
||||
implementation project(path: ":core", configuration: "dev")
|
||||
}
|
||||
|
||||
loom {
|
||||
runConfigs.configureEach {
|
||||
ideConfigGenerated = true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue