Implemented new installer argument system.
DirInstaller: can now have a custom file name as second argument.
This commit is contained in:
parent
ef27c65480
commit
b081ca9f86
|
@ -0,0 +1,27 @@
|
||||||
|
package ley.anvil.addonscript.installer;
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.wrapper.IInstaller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DefaultInstaller implements IInstaller {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
List<String> arguments;
|
||||||
|
|
||||||
|
public DefaultInstaller(String id, List<String> arguments) {
|
||||||
|
this.id = id;
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String installerID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return arguments.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package ley.anvil.addonscript.installer;
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.util.Utils;
|
||||||
|
import ley.anvil.addonscript.wrapper.IInstaller;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DirInstaller implements IInstaller {
|
||||||
|
|
||||||
|
List<String> arguments;
|
||||||
|
|
||||||
|
public DirInstaller(List<String> arguments) {
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String installerID() {
|
||||||
|
return "internal.dir";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getArguments() {
|
||||||
|
return arguments.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDestination() {
|
||||||
|
return arguments.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDestination(File mcdir) {
|
||||||
|
return new File(Utils.slashEnd(mcdir.getPath()) + getDestination());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldRename() {
|
||||||
|
return arguments.size() == 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String filename() {
|
||||||
|
if (shouldRename()) {
|
||||||
|
return arguments.get(1);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
package ley.anvil.addonscript.installer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public interface IInstaller {
|
|
||||||
|
|
||||||
void install(String[] params, File input);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package ley.anvil.addonscript.installer;
|
|
||||||
|
|
||||||
import ley.anvil.addonscript.installer.IInstaller;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
|
|
||||||
public class InternalDirInstaller implements IInstaller {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void install(String[] params, File input) {
|
|
||||||
if (params.length >= 1) {
|
|
||||||
try {
|
|
||||||
InputStream in = new FileInputStream(input);
|
|
||||||
Files.copy(in, Paths.get(params[0]), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("No directory specified for file " + input.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -200,7 +200,6 @@ public class AddonscriptJSON extends ASBase {
|
||||||
public String installer = "internal.dir";
|
public String installer = "internal.dir";
|
||||||
/**
|
/**
|
||||||
* This are the arguments for the installer
|
* This are the arguments for the installer
|
||||||
* Each installer needs other arguments and others need none.
|
|
||||||
*/
|
*/
|
||||||
@Upcoming
|
@Upcoming
|
||||||
@Expose
|
@Expose
|
||||||
|
|
|
@ -7,8 +7,6 @@ import com.google.gson.JsonElement;
|
||||||
import jdk.nashorn.api.scripting.URLReader;
|
import jdk.nashorn.api.scripting.URLReader;
|
||||||
import ley.anvil.addonscript.curse.CurseMeta;
|
import ley.anvil.addonscript.curse.CurseMeta;
|
||||||
import ley.anvil.addonscript.forge.ForgeMeta;
|
import ley.anvil.addonscript.forge.ForgeMeta;
|
||||||
import ley.anvil.addonscript.installer.IInstaller;
|
|
||||||
import ley.anvil.addonscript.installer.InternalDirInstaller;
|
|
||||||
import ley.anvil.addonscript.util.Utils;
|
import ley.anvil.addonscript.util.Utils;
|
||||||
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
import ley.anvil.addonscript.v1.AddonscriptJSON;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
|
@ -25,7 +23,6 @@ public class ASWrapper {
|
||||||
|
|
||||||
AddonscriptJSON json;
|
AddonscriptJSON json;
|
||||||
Map<String, String> REPOSITORIES;
|
Map<String, String> REPOSITORIES;
|
||||||
public Map<String, IInstaller> INSTALLERS;
|
|
||||||
public Map<String, AddonscriptJSON> ADDONS;
|
public Map<String, AddonscriptJSON> ADDONS;
|
||||||
public Map<Integer, ASWrapper.VersionWrapper> VERSIONS;
|
public Map<Integer, ASWrapper.VersionWrapper> VERSIONS;
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -34,10 +31,8 @@ public class ASWrapper {
|
||||||
public ASWrapper(AddonscriptJSON json) {
|
public ASWrapper(AddonscriptJSON json) {
|
||||||
this.json = json;
|
this.json = json;
|
||||||
REPOSITORIES = new HashMap<>();
|
REPOSITORIES = new HashMap<>();
|
||||||
INSTALLERS = new HashMap<>();
|
|
||||||
ADDONS = new HashMap<>();
|
ADDONS = new HashMap<>();
|
||||||
VERSIONS = new HashMap<>();
|
VERSIONS = new HashMap<>();
|
||||||
INSTALLERS.put("internal.dir", new InternalDirInstaller());
|
|
||||||
if (json.repositories != null) {
|
if (json.repositories != null) {
|
||||||
for (AddonscriptJSON.Repository r : json.repositories) {
|
for (AddonscriptJSON.Repository r : json.repositories) {
|
||||||
REPOSITORIES.put(r.id, r.url);
|
REPOSITORIES.put(r.id, r.url);
|
||||||
|
@ -217,7 +212,7 @@ public class ASWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileOrLink get() {
|
public FileOrLink get() {
|
||||||
return new FileOrLink(getLink(), file.installer).setASDir(asdir);
|
return new FileOrLink(getLink(), IInstaller.create(file.installer, file.arguments)).setASDir(asdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLink() {
|
public String getLink() {
|
||||||
|
|
|
@ -11,14 +11,14 @@ public class FileOrLink {
|
||||||
|
|
||||||
String link;
|
String link;
|
||||||
File asdir;
|
File asdir;
|
||||||
public String installer;
|
public IInstaller installer;
|
||||||
|
|
||||||
|
|
||||||
public FileOrLink(String link) {
|
public FileOrLink(String link) {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileOrLink(String link, String installer) {
|
public FileOrLink(String link, IInstaller installer) {
|
||||||
this.link = link;
|
this.link = link;
|
||||||
this.installer = installer;
|
this.installer = installer;
|
||||||
}
|
}
|
||||||
|
@ -84,4 +84,8 @@ public class FileOrLink {
|
||||||
return asdir != null;
|
return asdir != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IInstaller getInstaller() {
|
||||||
|
return installer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
39
src/main/java/ley/anvil/addonscript/wrapper/IInstaller.java
Normal file
39
src/main/java/ley/anvil/addonscript/wrapper/IInstaller.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package ley.anvil.addonscript.wrapper;
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.installer.DefaultInstaller;
|
||||||
|
import ley.anvil.addonscript.installer.DirInstaller;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IInstaller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the ID of this installer type.
|
||||||
|
* @return the ID
|
||||||
|
*/
|
||||||
|
String installerID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This are the raw arguments of the installer.
|
||||||
|
* @return An array of arguments. The positions are important.
|
||||||
|
*/
|
||||||
|
String[] getArguments();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
static IInstaller create(String id, List<String> arguments) {
|
||||||
|
if (arguments == null || id.contains(":")) {
|
||||||
|
String[] parts = id.split(":");
|
||||||
|
id = parts[0];
|
||||||
|
arguments = new ArrayList<>();
|
||||||
|
arguments.addAll(Arrays.asList(parts).subList(1, parts.length));
|
||||||
|
}
|
||||||
|
switch (id) {
|
||||||
|
case "internal.dir": return new DirInstaller(arguments);
|
||||||
|
default: return new DefaultInstaller(id, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue