Use Dev Launch Injector to ensure that the launch options are always kept upto date. (#138)
* Generate pre-launch classes to set the run args and system property's Will remove the need to regen the run configs each time the game is updated * fix minor thing. * Small cleanup * Another small rename + remove testing code * Remove import * Add basic auto upgrade path, put the launch classes in a package * Suggested cleanups * Use dev-launch-wrapper * Remove old classes * Rename to dev-launch-injector * Update more things I forgot aboutdev/0.11
parent
c8ef934bda
commit
b69d0db1c2
|
@ -53,6 +53,7 @@ import org.gradle.api.tasks.scala.ScalaCompile;
|
|||
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
||||
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||
|
||||
import net.fabricmc.loom.providers.LaunchProvider;
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.task.RemapJarTask;
|
||||
|
@ -278,6 +279,7 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
|
||||
dependencyManager.addProvider(new MinecraftProvider());
|
||||
dependencyManager.addProvider(new MappingsProvider());
|
||||
dependencyManager.addProvider(new LaunchProvider());
|
||||
|
||||
dependencyManager.handleDependencies(project1);
|
||||
|
||||
|
|
|
@ -179,6 +179,10 @@ public class LoomGradleExtension {
|
|||
return natives;
|
||||
}
|
||||
|
||||
public File getDevLauncherConfig() {
|
||||
return new File(getRootProjectPersistentCache(), "launch.cfg");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Dependency findDependency(Project p, Collection<Configuration> configs, BiPredicate<String, String> groupNameFilter) {
|
||||
for (Configuration config : configs) {
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* 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.providers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DependencyProvider;
|
||||
|
||||
public class LaunchProvider extends DependencyProvider {
|
||||
@Override
|
||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws IOException {
|
||||
final LaunchConfig launchConfig = new LaunchConfig()
|
||||
.property("fabric.development", "true")
|
||||
|
||||
.property("client", "java.library.path", extension.getNativesDirectory().getAbsolutePath())
|
||||
.property("client", "org.lwjgl.librarypath", extension.getNativesDirectory().getAbsolutePath())
|
||||
|
||||
.argument("client", "--assetIndex")
|
||||
.argument("client", extension.getMinecraftProvider().versionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion))
|
||||
.argument("client", "--assetsDir")
|
||||
.argument("client", new File(extension.getUserCache(), "assets").getAbsolutePath());
|
||||
|
||||
FileUtils.writeStringToFile(extension.getDevLauncherConfig(), launchConfig.asString(), StandardCharsets.UTF_8);
|
||||
|
||||
addDependency("net.fabricmc:dev-launch-injector:" + Constants.DEV_LAUNCH_INJECTOR_VERSION, project, "runtimeOnly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetConfig() {
|
||||
return Constants.MINECRAFT_NAMED;
|
||||
}
|
||||
|
||||
public static class LaunchConfig {
|
||||
private final Map<String, List<String>> values = new HashMap<>();
|
||||
|
||||
public LaunchConfig property(String key, String value) {
|
||||
return property("common", key, value);
|
||||
}
|
||||
|
||||
public LaunchConfig property(String side, String key, String value) {
|
||||
values.computeIfAbsent(side + "Properties", (s -> new ArrayList<>()))
|
||||
.add(String.format("%s=%s", key, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public LaunchConfig argument(String value) {
|
||||
return argument("common", value);
|
||||
}
|
||||
|
||||
public LaunchConfig argument(String side, String value) {
|
||||
values.computeIfAbsent(side + "Args", (s -> new ArrayList<>()))
|
||||
.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
StringJoiner stringJoiner = new StringJoiner("\n");
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : values.entrySet()) {
|
||||
stringJoiner.add(entry.getKey());
|
||||
|
||||
for (String s : entry.getValue()) {
|
||||
stringJoiner.add("\t" + s);
|
||||
}
|
||||
}
|
||||
|
||||
return stringJoiner.toString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,11 +43,11 @@ public class GenEclipseRunsTask extends AbstractLoomTask {
|
|||
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()) {
|
||||
if (!clientRunConfigs.exists() || RunConfig.needsUpgrade(clientRunConfigs)) {
|
||||
FileUtils.writeStringToFile(clientRunConfigs, clientRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
if (!serverRunConfigs.exists()) {
|
||||
if (!serverRunConfigs.exists() || RunConfig.needsUpgrade(serverRunConfigs)) {
|
||||
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,4 +57,5 @@ public class Constants {
|
|||
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
||||
|
||||
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.2.0.3";
|
||||
public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.1.0+build.3";
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -40,6 +39,7 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -96,7 +96,7 @@ public class RunConfig {
|
|||
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) {
|
||||
runConfig.projectName = project.getName();
|
||||
runConfig.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
|
||||
runConfig.vmArgs = "-Dfabric.development=true -Djava.library.path=\"" + extension.getNativesDirectory().getAbsolutePath() + "\"";
|
||||
runConfig.vmArgs = "";
|
||||
|
||||
switch (extension.getLoaderLaunchMethod()) {
|
||||
case "launchwrapper":
|
||||
|
@ -104,52 +104,37 @@ public class RunConfig {
|
|||
runConfig.programArgs = "--tweakClass " + ("client".equals(mode) ? Constants.DEFAULT_FABRIC_CLIENT_TWEAKER : Constants.DEFAULT_FABRIC_SERVER_TWEAKER);
|
||||
break;
|
||||
default:
|
||||
runConfig.mainClass = "net.fabricmc.loader.launch.knot.Knot" + mode.substring(0, 1).toUpperCase(Locale.ROOT) + mode.substring(1).toLowerCase(Locale.ROOT);
|
||||
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
||||
runConfig.programArgs = "";
|
||||
runConfig.vmArgs = "-Dfabric.dli.config=\"" + extension.getDevLauncherConfig().getAbsolutePath() + "\" -Dfabric.dli.env=" + mode.toLowerCase();
|
||||
break;
|
||||
}
|
||||
|
||||
// if installer.json found...
|
||||
JsonObject installerJson = extension.getInstallerJson();
|
||||
if (extension.getLoaderLaunchMethod().equals("launchwrapper")) {
|
||||
// if installer.json found...
|
||||
JsonObject installerJson = extension.getInstallerJson();
|
||||
|
||||
if (installerJson != null) {
|
||||
List<String> sideKeys = ImmutableList.of(mode, "common");
|
||||
if (installerJson != null) {
|
||||
List<String> sideKeys = ImmutableList.of(mode, "common");
|
||||
|
||||
// copy main class
|
||||
if (installerJson.has("mainClass")) {
|
||||
JsonElement mainClassJson = installerJson.get("mainClass");
|
||||
// copy launchwrapper tweakers
|
||||
if (installerJson.has("launchwrapper")) {
|
||||
JsonObject launchwrapperJson = installerJson.getAsJsonObject("launchwrapper");
|
||||
|
||||
if (mainClassJson.isJsonObject()) {
|
||||
JsonObject mainClassesJson = mainClassJson.getAsJsonObject();
|
||||
if (launchwrapperJson.has("tweakers")) {
|
||||
JsonObject tweakersJson = launchwrapperJson.getAsJsonObject("tweakers");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (String s : sideKeys) {
|
||||
if (mainClassesJson.has(s)) {
|
||||
runConfig.mainClass = mainClassesJson.get(s).getAsString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runConfig.mainClass = mainClassJson.getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
// copy launchwrapper tweakers
|
||||
if (installerJson.has("launchwrapper")) {
|
||||
JsonObject launchwrapperJson = installerJson.getAsJsonObject("launchwrapper");
|
||||
|
||||
if (launchwrapperJson.has("tweakers")) {
|
||||
JsonObject tweakersJson = launchwrapperJson.getAsJsonObject("tweakers");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (String s : sideKeys) {
|
||||
if (tweakersJson.has(s)) {
|
||||
for (JsonElement element : tweakersJson.getAsJsonArray(s)) {
|
||||
builder.append(" --tweakClass ").append(element.getAsString());
|
||||
for (String s : sideKeys) {
|
||||
if (tweakersJson.has(s)) {
|
||||
for (JsonElement element : tweakersJson.getAsJsonArray(s)) {
|
||||
builder.append(" --tweakClass ").append(element.getAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runConfig.programArgs += builder.toString();
|
||||
runConfig.programArgs += builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +148,8 @@ public class RunConfig {
|
|||
RunConfig ideaClient = new RunConfig();
|
||||
populate(project, extension, ideaClient, "client");
|
||||
ideaClient.configName = "Minecraft Client";
|
||||
ideaClient.programArgs += " --assetIndex \"" + minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion) + "\" --assetsDir \"" + new File(extension.getUserCache(), "assets").getAbsolutePath() + "\"";
|
||||
ideaClient.vmArgs += getOSClientJVMArgs();
|
||||
ideaClient.vmArgs += " -Dfabric.dli.main=" + getMainClass("client", extension);
|
||||
|
||||
return ideaClient;
|
||||
}
|
||||
|
@ -175,10 +160,17 @@ public class RunConfig {
|
|||
RunConfig ideaServer = new RunConfig();
|
||||
populate(project, extension, ideaServer, "server");
|
||||
ideaServer.configName = "Minecraft Server";
|
||||
ideaServer.vmArgs += " -Dfabric.dli.main=" + getMainClass("server", extension);
|
||||
|
||||
return ideaServer;
|
||||
}
|
||||
|
||||
//This can be removed at somepoint, its not ideal but its the best solution I could thing of
|
||||
public static boolean needsUpgrade(File file) throws IOException {
|
||||
String contents = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
return !(contents.contains("net.fabricmc.devlaunchinjector.Main"));
|
||||
}
|
||||
|
||||
public String fromDummy(String dummy) throws IOException {
|
||||
String dummyConfig;
|
||||
|
||||
|
@ -202,4 +194,28 @@ public class RunConfig {
|
|||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getMainClass(String side, LoomGradleExtension extension) {
|
||||
JsonObject installerJson = extension.getInstallerJson();
|
||||
|
||||
if (installerJson != null && installerJson.has("mainClass")) {
|
||||
JsonElement mainClassJson = installerJson.get("mainClass");
|
||||
|
||||
String mainClassName = "";
|
||||
|
||||
if (mainClassJson.isJsonObject()) {
|
||||
JsonObject mainClassesJson = mainClassJson.getAsJsonObject();
|
||||
|
||||
if (mainClassesJson.has(side)) {
|
||||
mainClassName = mainClassesJson.get(side).getAsString();
|
||||
}
|
||||
} else {
|
||||
mainClassName = mainClassJson.getAsString();
|
||||
}
|
||||
|
||||
return mainClassName;
|
||||
}
|
||||
|
||||
throw new RuntimeException("Failed to find mainclass");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,11 +78,11 @@ public class SetupIntelijRunConfigs {
|
|||
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()) {
|
||||
if (!clientRunConfigs.exists() || RunConfig.needsUpgrade(clientRunConfigs)) {
|
||||
FileUtils.writeStringToFile(clientRunConfigs, clientRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
if (!serverRunConfigs.exists()) {
|
||||
if (!serverRunConfigs.exists() || RunConfig.needsUpgrade(serverRunConfigs)) {
|
||||
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue