From 87c0bb4a8330caa9bedb5160f5f6feb1e17ec769 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Sun, 28 Mar 2021 15:38:56 +0100 Subject: [PATCH] Add creator tools plugin to Curse plugin --- builder-plugin-curse/build.gradle | 5 +++-- .../com/skcraft/plugin/curse/CurseBuildPlugin.java | 6 ++++-- .../plugin/curse/creator/CurseCreatorPlugin.java | 12 ++++++++++++ .../src/main/resources/skcraftcreator.plugin.json | 4 ++++ .../creator/controller/task/PackBuilder.java | 2 +- .../creator/plugin/CreatorPluginLoader.java | 4 ++++ .../skcraft/launcher/builder/PackageBuilder.java | 7 ++++++- .../builder/plugin/BuilderPluginLoader.java | 13 ++++++++++++- 8 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/creator/CurseCreatorPlugin.java create mode 100644 builder-plugin-curse/src/main/resources/skcraftcreator.plugin.json diff --git a/builder-plugin-curse/build.gradle b/builder-plugin-curse/build.gradle index 466330d..9999ee3 100644 --- a/builder-plugin-curse/build.gradle +++ b/builder-plugin-curse/build.gradle @@ -1,11 +1,12 @@ plugins { - id 'application' - id "com.github.johnrengelman.shadow" id 'io.freefair.lombok' } +version = "1.0.0" + dependencies { implementation project(':launcher-builder') + implementation project(':creator-tools') } build.dependsOn(jar) diff --git a/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/CurseBuildPlugin.java b/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/CurseBuildPlugin.java index 64d0a61..a2f4a0c 100644 --- a/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/CurseBuildPlugin.java +++ b/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/CurseBuildPlugin.java @@ -13,7 +13,9 @@ public class CurseBuildPlugin extends BuilderPlugin { @Override public void acceptOptions(BuilderOptions builderOptions, String[] args) { - new JCommander(this.options, args); + JCommander commander = new JCommander(this.options); + commander.setAcceptUnknownOptions(true); + commander.parse(args); if (options.getCachePath() == null) { builderOptions.requireInputPath("--cache"); @@ -22,7 +24,7 @@ public class CurseBuildPlugin extends BuilderPlugin { if (options.getCurseModsPath() == null) { builderOptions.requireInputPath("--curse-mods"); - options.setCachePath(new File(builderOptions.getInputPath(), "cursemods")); + options.setCurseModsPath(new File(builderOptions.getInputPath(), "cursemods")); } } diff --git a/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/creator/CurseCreatorPlugin.java b/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/creator/CurseCreatorPlugin.java new file mode 100644 index 0000000..77abeb4 --- /dev/null +++ b/builder-plugin-curse/src/main/java/com/skcraft/plugin/curse/creator/CurseCreatorPlugin.java @@ -0,0 +1,12 @@ +package com.skcraft.plugin.curse.creator; + +import com.skcraft.launcher.builder.plugin.BuilderPlugin; +import com.skcraft.launcher.creator.plugin.CreatorToolsPlugin; +import com.skcraft.plugin.curse.CurseBuildPlugin; + +public class CurseCreatorPlugin extends CreatorToolsPlugin { + @Override + public Class getBuilderPlugin() { + return CurseBuildPlugin.class; + } +} diff --git a/builder-plugin-curse/src/main/resources/skcraftcreator.plugin.json b/builder-plugin-curse/src/main/resources/skcraftcreator.plugin.json new file mode 100644 index 0000000..9319946 --- /dev/null +++ b/builder-plugin-curse/src/main/resources/skcraftcreator.plugin.json @@ -0,0 +1,4 @@ +{ + "id": "skcraft:plugin/curse", + "pluginClass": "com.skcraft.plugin.curse.creator.CurseCreatorPlugin" +} diff --git a/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/task/PackBuilder.java b/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/task/PackBuilder.java index 05a48ae..d9a57cf 100644 --- a/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/task/PackBuilder.java +++ b/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/task/PackBuilder.java @@ -63,7 +63,7 @@ public class PackBuilder implements Callable, ProgressObservable { for (CreatorToolsPlugin plugin : creator.getPlugins()) { if (plugin.getBuilderPlugin() != null) { - args.add("--plugin"); + args.add("--plugin-class"); args.add(plugin.getBuilderPlugin().getCanonicalName()); } } diff --git a/creator-tools/src/main/java/com/skcraft/launcher/creator/plugin/CreatorPluginLoader.java b/creator-tools/src/main/java/com/skcraft/launcher/creator/plugin/CreatorPluginLoader.java index f7e2c32..17e741e 100644 --- a/creator-tools/src/main/java/com/skcraft/launcher/creator/plugin/CreatorPluginLoader.java +++ b/creator-tools/src/main/java/com/skcraft/launcher/creator/plugin/CreatorPluginLoader.java @@ -3,6 +3,7 @@ package com.skcraft.launcher.creator.plugin; import com.fasterxml.jackson.databind.ObjectMapper; import com.skcraft.launcher.builder.BuilderUtils; import com.skcraft.launcher.builder.DirectoryWalker; +import com.skcraft.launcher.builder.plugin.BuilderPluginLoader; import lombok.Data; import lombok.extern.java.Log; @@ -44,6 +45,9 @@ public class CreatorPluginLoader extends DirectoryWalker { this.getClass().getClassLoader() ); + // Fun hack to make sure the builder can load plugins + BuilderPluginLoader.setClassLoader(pluginClassLoader); + return candidates.stream() .map(candidate -> loadPlugin(pluginClassLoader, candidate)) .collect(Collectors.toList()); diff --git a/launcher-builder/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java b/launcher-builder/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java index 99c668f..f43c8cc 100644 --- a/launcher-builder/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java +++ b/launcher-builder/src/main/java/com/skcraft/launcher/builder/PackageBuilder.java @@ -372,7 +372,10 @@ public class PackageBuilder implements Builder { private static BuilderOptions parseArgs(String[] args) { BuilderOptions options = new BuilderOptions(); - new JCommander(options, args); + JCommander commander = new JCommander(options); + commander.setAcceptUnknownOptions(true); + commander.parse(args); + options.choosePaths(); return options; } @@ -444,6 +447,8 @@ public class PackageBuilder implements Builder { builder.addLoaders(options.getLoadersDir(), options.getLibrariesDir()); builder.downloadLibraries(options.getLibrariesDir()); + logSection("Applying plugins..."); + pluginLoader.dispatchBuild(builder); builder.writeManifest(options.getManifestPath()); diff --git a/launcher-builder/src/main/java/com/skcraft/launcher/builder/plugin/BuilderPluginLoader.java b/launcher-builder/src/main/java/com/skcraft/launcher/builder/plugin/BuilderPluginLoader.java index d9a9e95..23aca35 100644 --- a/launcher-builder/src/main/java/com/skcraft/launcher/builder/plugin/BuilderPluginLoader.java +++ b/launcher-builder/src/main/java/com/skcraft/launcher/builder/plugin/BuilderPluginLoader.java @@ -11,6 +11,7 @@ import java.util.List; @Log public class BuilderPluginLoader { + private static ClassLoader pluginClassLoader; private List loadedPlugins = Lists.newArrayList(); public void loadClasses(List classNames) { @@ -29,7 +30,7 @@ public class BuilderPluginLoader { private T loadClass(String pluginClassName) throws ClassNotFoundException { try { - Class pluginClass = (Class) getClass().getClassLoader().loadClass(pluginClassName); + Class pluginClass = (Class) getClassLoader().loadClass(pluginClassName); return pluginClass.getConstructor().newInstance(); } catch (InstantiationException e) { @@ -50,6 +51,16 @@ public class BuilderPluginLoader { return null; } + private static ClassLoader getClassLoader() { + if (pluginClassLoader != null) return pluginClassLoader; + + return BuilderPluginLoader.class.getClassLoader(); + } + + public static void setClassLoader(ClassLoader loader) { + pluginClassLoader = loader; + } + public void dispatchAcceptOptions(BuilderOptions options, String[] args) { for (BuilderPlugin plugin : loadedPlugins) { plugin.acceptOptions(options, args);