Auto generate eclipse launch files

dev/0.11
modmuss50 2018-12-12 13:43:42 +00:00
parent f61b06f616
commit 96e0dd30be
9 changed files with 88 additions and 18 deletions

View File

@ -11,7 +11,7 @@ targetCompatibility = 1.8
group = 'net.fabricmc'
archivesBaseName = project.name
version = '0.1.0-SNAPSHOT'
version = '0.1.1-SNAPSHOT'
def build = "local"
def ENV = System.getenv()

View File

@ -222,6 +222,7 @@ public class AbstractPlugin implements Plugin<Project> {
dependencyManager.handleDependencies(project1);
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
project1.getTasks().getByName("eclipse").finalizedBy(project1.getTasks().getByName("genEclipseRuns"));
SetupIntelijRunConfigs.setup(project1);

View File

@ -40,6 +40,7 @@ public class LoomGradlePlugin extends AbstractPlugin {
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
makeTask("vscode", GenVsCodeProjectTask.class).setGroup("ide");
makeTask("genEclipseRuns", GenEclipseRunsTask.class).setGroup("ide");
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraftMapped");
makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded").setGroup("minecraftMapped");

View File

@ -0,0 +1,53 @@
/*
* 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 net.fabricmc.loom.util.RunConfig;
import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class GenEclipseRunsTask extends DefaultTask {
@TaskAction
public void genRuns() throws IOException {
File clientRunConfigs = new File(getProject().getRootDir(), "Minecraft_Client.launch");
File serverRunConfigs = new File(getProject().getRootDir(), "Minecraft_Server.launch");
String clientRunConfig = RunConfig.clientRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml");
String serverRunConfig = RunConfig.serverRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml");
if(!clientRunConfigs.exists())
FileUtils.writeStringToFile(clientRunConfigs, clientRunConfig, StandardCharsets.UTF_8);
if(!serverRunConfigs.exists())
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
}
}

View File

@ -25,7 +25,7 @@
package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.IdeaRunConfig;
import net.fabricmc.loom.util.RunConfig;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
@ -73,8 +73,8 @@ public class GenIdeaProjectTask extends DefaultTask {
throw new RuntimeException("Failed to generate intellij run configurations (runManager was not found)");
}
runManager.appendChild(IdeaRunConfig.clientRunConfig(project).genRuns(runManager));
runManager.appendChild(IdeaRunConfig.serverRunConfig(project).genRuns(runManager));
runManager.appendChild(RunConfig.clientRunConfig(project).genRuns(runManager));
runManager.appendChild(RunConfig.serverRunConfig(project).genRuns(runManager));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();

View File

@ -27,7 +27,7 @@ package net.fabricmc.loom.task;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.IdeaRunConfig;
import net.fabricmc.loom.util.RunConfig;
import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
@ -57,8 +57,8 @@ public class GenVsCodeProjectTask extends DefaultTask {
}
VsCodeLaunch launch = new VsCodeLaunch();
launch.add(IdeaRunConfig.clientRunConfig(getProject()));
launch.add(IdeaRunConfig.serverRunConfig(getProject()));
launch.add(RunConfig.clientRunConfig(getProject()));
launch.add(RunConfig.serverRunConfig(getProject()));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(launch);
@ -79,7 +79,7 @@ public class GenVsCodeProjectTask extends DefaultTask {
public String version = "0.2.0";
public List<VsCodeConfiguration> configurations = new ArrayList<>();
public void add(IdeaRunConfig runConfig) {
public void add(RunConfig runConfig) {
configurations.add(new VsCodeConfiguration(runConfig));
}
}
@ -95,7 +95,7 @@ public class GenVsCodeProjectTask extends DefaultTask {
public String vmArgs;
public String args;
public VsCodeConfiguration(IdeaRunConfig runConfig) {
public VsCodeConfiguration(RunConfig runConfig) {
this.name = runConfig.configName;
this.mainClass = runConfig.mainClass;
this.vmArgs = runConfig.vmArgs;

View File

@ -42,7 +42,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
public class IdeaRunConfig {
public class RunConfig {
public String configName;
public String projectName;
public String mainClass;
@ -82,12 +82,12 @@ public class IdeaRunConfig {
return e;
}
public static IdeaRunConfig clientRunConfig(Project project){
public static RunConfig clientRunConfig(Project project){
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
IdeaRunConfig ideaClient = new IdeaRunConfig();
RunConfig ideaClient = new RunConfig();
ideaClient.mainClass = "net.minecraft.launchwrapper.Launch";
ideaClient.projectName = project.getName();
ideaClient.configName = "Minecraft Client";
@ -98,10 +98,10 @@ public class IdeaRunConfig {
return ideaClient;
}
public static IdeaRunConfig serverRunConfig(Project project){
public static RunConfig serverRunConfig(Project project){
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
IdeaRunConfig ideaServer = new IdeaRunConfig();
RunConfig ideaServer = new RunConfig();
ideaServer.mainClass = "net.minecraft.launchwrapper.Launch";
ideaServer.projectName = project.getName();
ideaServer.configName = "Minecraft Server";
@ -112,8 +112,8 @@ public class IdeaRunConfig {
return ideaServer;
}
public String fromDummy() throws IOException {
InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream("idea_run_config_template.xml");
public String fromDummy(String dummy) throws IOException {
InputStream input = SetupIntelijRunConfigs.class.getClassLoader().getResourceAsStream(dummy);
String dummyConfig = IOUtils.toString(input, StandardCharsets.UTF_8);
input.close();

View File

@ -63,8 +63,8 @@ public class SetupIntelijRunConfigs {
runConfigsDir.mkdirs();
}
String clientRunConfig = IdeaRunConfig.clientRunConfig(project).fromDummy();
String serverRunConfig = IdeaRunConfig.serverRunConfig(project).fromDummy();
String clientRunConfig = RunConfig.clientRunConfig(project).fromDummy("idea_run_config_template.xml");
String serverRunConfig = RunConfig.serverRunConfig(project).fromDummy("idea_run_config_template.xml");
if(!clientRunConfigs.exists())
FileUtils.writeStringToFile(clientRunConfigs, clientRunConfig, StandardCharsets.UTF_8);

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/%NAME%"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<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.PROGRAM_ARGUMENTS" value="%PROGRAM_ARGS%"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="%MODULE%"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="%VM_ARGS%"/>
</launchConfiguration>