1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-30 13:13:58 +01:00

Add creator tools plugin to Curse plugin

This commit is contained in:
Henry Le Grys 2021-03-28 15:38:56 +01:00
parent e0a242cedc
commit 87c0bb4a83
8 changed files with 46 additions and 7 deletions

View File

@ -1,11 +1,12 @@
plugins { plugins {
id 'application'
id "com.github.johnrengelman.shadow"
id 'io.freefair.lombok' id 'io.freefair.lombok'
} }
version = "1.0.0"
dependencies { dependencies {
implementation project(':launcher-builder') implementation project(':launcher-builder')
implementation project(':creator-tools')
} }
build.dependsOn(jar) build.dependsOn(jar)

View File

@ -13,7 +13,9 @@ public class CurseBuildPlugin extends BuilderPlugin {
@Override @Override
public void acceptOptions(BuilderOptions builderOptions, String[] args) { 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) { if (options.getCachePath() == null) {
builderOptions.requireInputPath("--cache"); builderOptions.requireInputPath("--cache");
@ -22,7 +24,7 @@ public class CurseBuildPlugin extends BuilderPlugin {
if (options.getCurseModsPath() == null) { if (options.getCurseModsPath() == null) {
builderOptions.requireInputPath("--curse-mods"); builderOptions.requireInputPath("--curse-mods");
options.setCachePath(new File(builderOptions.getInputPath(), "cursemods")); options.setCurseModsPath(new File(builderOptions.getInputPath(), "cursemods"));
} }
} }

View File

@ -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<? extends BuilderPlugin> getBuilderPlugin() {
return CurseBuildPlugin.class;
}
}

View File

@ -0,0 +1,4 @@
{
"id": "skcraft:plugin/curse",
"pluginClass": "com.skcraft.plugin.curse.creator.CurseCreatorPlugin"
}

View File

@ -63,7 +63,7 @@ public class PackBuilder implements Callable<PackBuilder>, ProgressObservable {
for (CreatorToolsPlugin plugin : creator.getPlugins()) { for (CreatorToolsPlugin plugin : creator.getPlugins()) {
if (plugin.getBuilderPlugin() != null) { if (plugin.getBuilderPlugin() != null) {
args.add("--plugin"); args.add("--plugin-class");
args.add(plugin.getBuilderPlugin().getCanonicalName()); args.add(plugin.getBuilderPlugin().getCanonicalName());
} }
} }

View File

@ -3,6 +3,7 @@ package com.skcraft.launcher.creator.plugin;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.skcraft.launcher.builder.BuilderUtils; import com.skcraft.launcher.builder.BuilderUtils;
import com.skcraft.launcher.builder.DirectoryWalker; import com.skcraft.launcher.builder.DirectoryWalker;
import com.skcraft.launcher.builder.plugin.BuilderPluginLoader;
import lombok.Data; import lombok.Data;
import lombok.extern.java.Log; import lombok.extern.java.Log;
@ -44,6 +45,9 @@ public class CreatorPluginLoader extends DirectoryWalker {
this.getClass().getClassLoader() this.getClass().getClassLoader()
); );
// Fun hack to make sure the builder can load plugins
BuilderPluginLoader.setClassLoader(pluginClassLoader);
return candidates.stream() return candidates.stream()
.map(candidate -> loadPlugin(pluginClassLoader, candidate)) .map(candidate -> loadPlugin(pluginClassLoader, candidate))
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -372,7 +372,10 @@ public class PackageBuilder implements Builder {
private static BuilderOptions parseArgs(String[] args) { private static BuilderOptions parseArgs(String[] args) {
BuilderOptions options = new BuilderOptions(); BuilderOptions options = new BuilderOptions();
new JCommander(options, args); JCommander commander = new JCommander(options);
commander.setAcceptUnknownOptions(true);
commander.parse(args);
options.choosePaths(); options.choosePaths();
return options; return options;
} }
@ -444,6 +447,8 @@ public class PackageBuilder implements Builder {
builder.addLoaders(options.getLoadersDir(), options.getLibrariesDir()); builder.addLoaders(options.getLoadersDir(), options.getLibrariesDir());
builder.downloadLibraries(options.getLibrariesDir()); builder.downloadLibraries(options.getLibrariesDir());
logSection("Applying plugins...");
pluginLoader.dispatchBuild(builder); pluginLoader.dispatchBuild(builder);
builder.writeManifest(options.getManifestPath()); builder.writeManifest(options.getManifestPath());

View File

@ -11,6 +11,7 @@ import java.util.List;
@Log @Log
public class BuilderPluginLoader { public class BuilderPluginLoader {
private static ClassLoader pluginClassLoader;
private List<BuilderPlugin> loadedPlugins = Lists.newArrayList(); private List<BuilderPlugin> loadedPlugins = Lists.newArrayList();
public void loadClasses(List<String> classNames) { public void loadClasses(List<String> classNames) {
@ -29,7 +30,7 @@ public class BuilderPluginLoader {
private <T extends BuilderPlugin> T loadClass(String pluginClassName) throws ClassNotFoundException { private <T extends BuilderPlugin> T loadClass(String pluginClassName) throws ClassNotFoundException {
try { try {
Class<T> pluginClass = (Class<T>) getClass().getClassLoader().loadClass(pluginClassName); Class<T> pluginClass = (Class<T>) getClassLoader().loadClass(pluginClassName);
return pluginClass.getConstructor().newInstance(); return pluginClass.getConstructor().newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
@ -50,6 +51,16 @@ public class BuilderPluginLoader {
return null; 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) { public void dispatchAcceptOptions(BuilderOptions options, String[] args) {
for (BuilderPlugin plugin : loadedPlugins) { for (BuilderPlugin plugin : loadedPlugins) {
plugin.acceptOptions(options, args); plugin.acceptOptions(options, args);