Added Installers
This commit is contained in:
parent
31952dc43f
commit
b27896e9df
|
@ -15,7 +15,7 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.google.code.gson:gson:+'
|
compile 'com.google.code.gson:gson:+'
|
||||||
compile 'org.apache.maven:maven-core:+'
|
compile 'org.apache.maven:maven-core:+'
|
||||||
compile 'org.python:jython:2.7.0'
|
compile 'org.python:jython-standalone:2.7.0'
|
||||||
compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
|
compile "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package ley.anvil.addonscript.python;
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.util.IInstaller;
|
||||||
|
import org.python.core.PyString;
|
||||||
|
import org.python.util.PythonInterpreter;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class PythonInstaller implements IInstaller {
|
||||||
|
|
||||||
|
String script;
|
||||||
|
PythonInterpreter python;
|
||||||
|
|
||||||
|
public PythonInstaller(String scriptlink) {
|
||||||
|
script = getScript(scriptlink);
|
||||||
|
python = new PythonInterpreter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void install(String[] params, String filelink) {
|
||||||
|
python.set("link", new PyString(filelink));
|
||||||
|
python.set("params", params);
|
||||||
|
python.exec(script);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScript(String url) {
|
||||||
|
try {
|
||||||
|
URL scripturl = new URL(url);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(scripturl.openStream()));
|
||||||
|
StringBuilder script = new StringBuilder();
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = reader.readLine()) != null)
|
||||||
|
script.append(inputLine);
|
||||||
|
reader.close();
|
||||||
|
return script.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
src/main/java/ley/anvil/addonscript/util/IInstaller.java
Normal file
9
src/main/java/ley/anvil/addonscript/util/IInstaller.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package ley.anvil.addonscript.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public interface IInstaller {
|
||||||
|
|
||||||
|
void install(String[] params, String filelink);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package ley.anvil.addonscript.util;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public class InternalDirInstaller implements IInstaller {
|
||||||
|
|
||||||
|
public static String ID = "internal.dir";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void install(String[] params, String filelink) {
|
||||||
|
if (params.length >= 1) {
|
||||||
|
try {
|
||||||
|
InputStream in = new URL(filelink).openStream();
|
||||||
|
Files.copy(in, Paths.get(params[0]), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("No directory specified for file " + filelink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue