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:
parent
e0a242cedc
commit
87c0bb4a83
@ -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)
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"id": "skcraft:plugin/curse",
|
||||
"pluginClass": "com.skcraft.plugin.curse.creator.CurseCreatorPlugin"
|
||||
}
|
@ -63,7 +63,7 @@ public class PackBuilder implements Callable<PackBuilder>, ProgressObservable {
|
||||
|
||||
for (CreatorToolsPlugin plugin : creator.getPlugins()) {
|
||||
if (plugin.getBuilderPlugin() != null) {
|
||||
args.add("--plugin");
|
||||
args.add("--plugin-class");
|
||||
args.add(plugin.getBuilderPlugin().getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
@Log
|
||||
public class BuilderPluginLoader {
|
||||
private static ClassLoader pluginClassLoader;
|
||||
private List<BuilderPlugin> loadedPlugins = Lists.newArrayList();
|
||||
|
||||
public void loadClasses(List<String> classNames) {
|
||||
@ -29,7 +30,7 @@ public class BuilderPluginLoader {
|
||||
|
||||
private <T extends BuilderPlugin> T loadClass(String pluginClassName) throws ClassNotFoundException {
|
||||
try {
|
||||
Class<T> pluginClass = (Class<T>) getClass().getClassLoader().loadClass(pluginClassName);
|
||||
Class<T> pluginClass = (Class<T>) 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);
|
||||
|
Loading…
Reference in New Issue
Block a user