From 6c02535304234f7b5b7c0905b824f4d45e38ceae Mon Sep 17 00:00:00 2001 From: immibis Date: Sun, 26 Apr 2020 15:04:49 +0200 Subject: [PATCH] Eclipse project fixes (#192) * If the Eclipse project name is overridden by the build script, use the actual name. * Clean up Eclipse launch files after cleanEclipse task. --- .../net/fabricmc/loom/AbstractPlugin.java | 1 + .../net/fabricmc/loom/LoomGradlePlugin.java | 5 ++ .../loom/task/CleanEclipseRunsTask.java | 48 +++++++++++++++++++ .../loom/task/GenEclipseRunsTask.java | 6 ++- .../net/fabricmc/loom/util/RunConfig.java | 3 +- 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/fabricmc/loom/task/CleanEclipseRunsTask.java diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index 6337536..ab71e9d 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -275,6 +275,7 @@ public class AbstractPlugin implements Plugin { project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace")); project1.getTasks().getByName("eclipse").finalizedBy(project1.getTasks().getByName("genEclipseRuns")); + project1.getTasks().getByName("cleanEclipse").finalizedBy(project1.getTasks().getByName("cleanEclipseRuns")); if (extension.autoGenIDERuns && isRootProject(project1)) { SetupIntelijRunConfigs.setup(project1); diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index ca31004..61cffdc 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -37,6 +37,7 @@ import org.gradle.api.tasks.TaskContainer; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftLibraryProvider; import net.fabricmc.loom.task.AbstractDecompileTask; +import net.fabricmc.loom.task.CleanEclipseRunsTask; import net.fabricmc.loom.task.CleanLoomBinaries; import net.fabricmc.loom.task.CleanLoomMappings; import net.fabricmc.loom.task.DownloadAssetsTask; @@ -151,6 +152,10 @@ public class LoomGradlePlugin extends AbstractPlugin { t.setGroup("ide"); }); + tasks.register("cleanEclipseRuns", CleanEclipseRunsTask.class, t -> { + t.setGroup("ide"); + }); + tasks.register("vscode", GenVsCodeProjectTask.class, t -> { t.dependsOn("downloadAssets"); t.setGroup("ide"); diff --git a/src/main/java/net/fabricmc/loom/task/CleanEclipseRunsTask.java b/src/main/java/net/fabricmc/loom/task/CleanEclipseRunsTask.java new file mode 100644 index 0000000..5b11901 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/task/CleanEclipseRunsTask.java @@ -0,0 +1,48 @@ +/* + * 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.task; + +import java.io.File; +import java.io.IOException; + +import org.gradle.api.tasks.TaskAction; +import org.gradle.plugins.ide.eclipse.model.EclipseModel; + +public class CleanEclipseRunsTask extends AbstractLoomTask { + @TaskAction + public void cleanRuns() throws IOException { + EclipseModel eclipseModel = getProject().getExtensions().getByType(EclipseModel.class); + File clientRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_client.launch"); + File serverRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_server.launch"); + + if (clientRunConfigs.exists()) { + clientRunConfigs.delete(); + } + + if (serverRunConfigs.exists()) { + serverRunConfigs.delete(); + } + } +} diff --git a/src/main/java/net/fabricmc/loom/task/GenEclipseRunsTask.java b/src/main/java/net/fabricmc/loom/task/GenEclipseRunsTask.java index a0f0264..11124df 100644 --- a/src/main/java/net/fabricmc/loom/task/GenEclipseRunsTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenEclipseRunsTask.java @@ -30,14 +30,16 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; import org.gradle.api.tasks.TaskAction; +import org.gradle.plugins.ide.eclipse.model.EclipseModel; import net.fabricmc.loom.util.RunConfig; public class GenEclipseRunsTask extends AbstractLoomTask { @TaskAction public void genRuns() throws IOException { - File clientRunConfigs = new File(getProject().getRootDir(), getProject().getName() + "_client.launch"); - File serverRunConfigs = new File(getProject().getRootDir(), getProject().getName() + "_server.launch"); + EclipseModel eclipseModel = getProject().getExtensions().getByType(EclipseModel.class); + File clientRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_client.launch"); + File serverRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_server.launch"); String clientRunConfig = RunConfig.clientRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml"); String serverRunConfig = RunConfig.serverRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml"); diff --git a/src/main/java/net/fabricmc/loom/util/RunConfig.java b/src/main/java/net/fabricmc/loom/util/RunConfig.java index 633796d..8ff824d 100644 --- a/src/main/java/net/fabricmc/loom/util/RunConfig.java +++ b/src/main/java/net/fabricmc/loom/util/RunConfig.java @@ -46,6 +46,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.gradle.api.Project; +import org.gradle.plugins.ide.eclipse.model.EclipseModel; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.providers.MinecraftProvider; @@ -95,7 +96,7 @@ public class RunConfig { } private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) { - runConfig.projectName = project.getName(); + runConfig.projectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName(); runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir; runConfig.vmArgs = "";