| @@ -0,0 +1,8 @@ | ||
| build.xml.data.CRC32=4107b45a | ||
| build.xml.script.CRC32=a52d776d | ||
| build.xml.stylesheet.CRC32=8064a381@1.79.1.48 | ||
| # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
| # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
| nbproject/build-impl.xml.data.CRC32=4107b45a | ||
| nbproject/build-impl.xml.script.CRC32=1a762025 | ||
| nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 |
| @@ -0,0 +1,77 @@ | ||
| annotation.processing.enabled=true | ||
| annotation.processing.enabled.in.editor=false | ||
| annotation.processing.processors.list= | ||
| annotation.processing.run.all.processors=true | ||
| annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output | ||
| application.title=Java Compiler | ||
| application.vendor=natha | ||
| build.classes.dir=${build.dir}/classes | ||
| build.classes.excludes=**/*.java,**/*.form | ||
| # This directory is removed when the project is cleaned: | ||
| build.dir=build | ||
| build.generated.dir=${build.dir}/generated | ||
| build.generated.sources.dir=${build.dir}/generated-sources | ||
| # Only compile against the classpath explicitly listed here: | ||
| build.sysclasspath=ignore | ||
| build.test.classes.dir=${build.dir}/test/classes | ||
| build.test.results.dir=${build.dir}/test/results | ||
| # Uncomment to specify the preferred debugger connection transport: | ||
| #debug.transport=dt_socket | ||
| debug.classpath=\ | ||
| ${run.classpath} | ||
| debug.test.classpath=\ | ||
| ${run.test.classpath} | ||
| # Files in build.classes.dir which should be excluded from distribution jar | ||
| dist.archive.excludes= | ||
| # This directory is removed when the project is cleaned: | ||
| dist.dir=dist | ||
| dist.jar=${dist.dir}/Java_Compiler.jar | ||
| dist.javadoc.dir=${dist.dir}/javadoc | ||
| endorsed.classpath= | ||
| excludes= | ||
| includes=** | ||
| jar.compress=false | ||
| javac.classpath=\ | ||
| ${libs.Gson.classpath} | ||
| # Space-separated list of extra javac options | ||
| javac.compilerargs= | ||
| javac.deprecation=false | ||
| javac.external.vm=true | ||
| javac.processorpath=\ | ||
| ${javac.classpath} | ||
| javac.source=1.8 | ||
| javac.target=1.8 | ||
| javac.test.classpath=\ | ||
| ${javac.classpath}:\ | ||
| ${build.classes.dir} | ||
| javac.test.processorpath=\ | ||
| ${javac.test.classpath} | ||
| javadoc.additionalparam= | ||
| javadoc.author=false | ||
| javadoc.encoding=${source.encoding} | ||
| javadoc.noindex=false | ||
| javadoc.nonavbar=false | ||
| javadoc.notree=false | ||
| javadoc.private=false | ||
| javadoc.splitindex=true | ||
| javadoc.use=true | ||
| javadoc.version=false | ||
| javadoc.windowtitle= | ||
| main.class=sandbox.Main | ||
| manifest.file=manifest.mf | ||
| meta.inf.dir=${src.dir}/META-INF | ||
| mkdist.disabled=false | ||
| platform.active=default_platform | ||
| run.classpath=\ | ||
| ${javac.classpath}:\ | ||
| ${build.classes.dir} | ||
| # Space-separated list of JVM arguments used when running the project. | ||
| # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. | ||
| # To set system properties for unit tests define test-sys-prop.name=value: | ||
| run.jvmargs= | ||
| run.test.classpath=\ | ||
| ${javac.test.classpath}:\ | ||
| ${build.test.classes.dir} | ||
| source.encoding=UTF-8 | ||
| src.dir=src | ||
| test.src.dir=test |
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://www.netbeans.org/ns/project/1"> | ||
| <type>org.netbeans.modules.java.j2seproject</type> | ||
| <configuration> | ||
| <data xmlns="http://www.netbeans.org/ns/j2se-project/3"> | ||
| <name>Java Compiler</name> | ||
| <source-roots> | ||
| <root id="src.dir"/> | ||
| </source-roots> | ||
| <test-roots> | ||
| <root id="test.src.dir"/> | ||
| </test-roots> | ||
| </data> | ||
| <libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1"> | ||
| <definitions>../jlib\nblibraries.properties</definitions> | ||
| </libraries> | ||
| </configuration> | ||
| </project> |
| @@ -0,0 +1,27 @@ | ||
| package org.mdkt.compiler; | ||
|
|
||
| import javax.tools.SimpleJavaFileObject; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.net.URI; | ||
|
|
||
| /** | ||
| * Created by trung on 5/3/15. | ||
| */ | ||
| public class CompiledCode extends SimpleJavaFileObject { | ||
| private ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
|
|
||
| public CompiledCode(String className) throws Exception { | ||
| super(new URI(className), Kind.CLASS); | ||
| } | ||
|
|
||
| @Override | ||
| public OutputStream openOutputStream() throws IOException { | ||
| return baos; | ||
| } | ||
|
|
||
| public byte[] getByteCode() { | ||
| return baos.toByteArray(); | ||
| } | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| package org.mdkt.compiler; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Created by trung on 5/3/15. | ||
| */ | ||
| public class DynamicClassLoader extends ClassLoader { | ||
|
|
||
| private Map<String, CompiledCode> customCompiledCode = new HashMap<>(); | ||
|
|
||
| public DynamicClassLoader(ClassLoader parent) { | ||
| super(parent); | ||
| } | ||
|
|
||
| public void setCode(CompiledCode cc) { | ||
| customCompiledCode.put(cc.getName(), cc); | ||
| } | ||
|
|
||
| @Override | ||
| protected Class<?> findClass(String name) throws ClassNotFoundException { | ||
| CompiledCode cc = customCompiledCode.get(name); | ||
| if (cc == null) { | ||
| return super.findClass(name); | ||
| } | ||
| byte[] byteCode = cc.getByteCode(); | ||
| return defineClass(name, byteCode, 0, byteCode.length); | ||
| } | ||
| } |
| @@ -0,0 +1,39 @@ | ||
| package org.mdkt.compiler; | ||
|
|
||
| import javax.tools.FileObject; | ||
| import javax.tools.ForwardingJavaFileManager; | ||
| import javax.tools.JavaFileManager; | ||
| import javax.tools.JavaFileObject; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Created by trung on 5/3/15. | ||
| */ | ||
| public class ExtendedStandardJavaFileManager extends ForwardingJavaFileManager<JavaFileManager> { | ||
|
|
||
| private CompiledCode compiledCode; | ||
| private DynamicClassLoader cl; | ||
|
|
||
| /** | ||
| * Creates a new instance of ForwardingJavaFileManager. | ||
| * | ||
| * @param fileManager delegate to this file manager | ||
| * @param cl | ||
| */ | ||
| protected ExtendedStandardJavaFileManager(JavaFileManager fileManager, CompiledCode compiledCode, DynamicClassLoader cl) { | ||
| super(fileManager); | ||
| this.compiledCode = compiledCode; | ||
| this.cl = cl; | ||
| this.cl.setCode(compiledCode); | ||
| } | ||
|
|
||
| @Override | ||
| public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { | ||
| return compiledCode; | ||
| } | ||
|
|
||
| @Override | ||
| public ClassLoader getClassLoader(JavaFileManager.Location location) { | ||
| return cl; | ||
| } | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| package org.mdkt.compiler; | ||
|
|
||
| import java.net.URL; | ||
| import java.net.URLClassLoader; | ||
| import javax.tools.JavaCompiler; | ||
| import javax.tools.JavaFileObject; | ||
| import javax.tools.ToolProvider; | ||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Created by trung on 5/3/15. | ||
| */ | ||
| public class InMemoryJavaCompiler { | ||
|
|
||
| static JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); | ||
|
|
||
| public static Class<?> compile(String className, String sourceCodeInText) throws Exception { | ||
| SourceCode sourceCode = new SourceCode(className, sourceCodeInText); | ||
| CompiledCode compiledCode = new CompiledCode(className); | ||
| Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(sourceCode); | ||
| try (URLClassLoader temp = new URLClassLoader(new URL[0])) { | ||
| DynamicClassLoader cl = new DynamicClassLoader(temp); | ||
| ExtendedStandardJavaFileManager fileManager = new ExtendedStandardJavaFileManager(javac.getStandardFileManager(null, null, null), compiledCode, cl); | ||
| JavaCompiler.CompilationTask task = javac.getTask(null, fileManager, null, null, null, compilationUnits); | ||
| boolean result = task.call(); | ||
| return cl.loadClass(className); | ||
| } | ||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,21 @@ | ||
| package org.mdkt.compiler; | ||
|
|
||
| import javax.tools.SimpleJavaFileObject; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
|
|
||
| /** | ||
| * Created by trung on 5/3/15. | ||
| */ | ||
| public class SourceCode extends SimpleJavaFileObject { | ||
| private String contents = null; | ||
|
|
||
| public SourceCode(String className, String contents) throws Exception { | ||
| super(URI.create("string:///" + className.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE); | ||
| this.contents = contents; | ||
| } | ||
|
|
||
| public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { | ||
| return contents; | ||
| } | ||
| } |
| @@ -0,0 +1,88 @@ | ||
| package sandbox; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import java.io.BufferedInputStream; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.PrintStream; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class Main { | ||
|
|
||
| @SuppressWarnings("CallToPrintStackTrace") | ||
| public static void main(String[] args) throws Exception{ | ||
|
|
||
| PrintStream out = System.out; | ||
|
|
||
| System.out.println(System.getenv("test")); | ||
|
|
||
| //UniqueThreadPrintStream stream = new UniqueThreadPrintStream(System.out); | ||
| // System.setOut(stream); | ||
|
|
||
| String src = "import java.util.*;\n" | ||
| + "public class Tester{\n" | ||
| + " public static void main(String[] args){\n" | ||
| + " Scanner yo = new Scanner(System.in);\n" | ||
| + " System.out.println(\"hello world\");\n" | ||
| + " System.out.println(yo.nextLine());\n" | ||
| + " System.out.println(System.getenv(\"test\"));\n" | ||
| + " }\n" | ||
| + "}"; | ||
|
|
||
| String input = "this is a test lol\nwat"; | ||
| int id = -1; | ||
| Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
| String token = "token"; | ||
|
|
||
| SandboxEventListener listener = new gay(); | ||
|
|
||
| SandboxTask task = new SandboxTask(src, listener, id); | ||
|
|
||
| System.setOut(new PrintStream(task.out)); | ||
| System.setIn(new BufferedInputStream(new ByteArrayInputStream(input.getBytes()))); | ||
|
|
||
| out.println("good"); | ||
| System.setSecurityManager(new SandboxSecurityManager()); | ||
| task.start(); | ||
| try { | ||
| synchronized (listener) { | ||
| listener.wait(2 * 1000); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| task.stop(); | ||
|
|
||
| CompeteResponse res = new CompeteResponse(); | ||
| res.response = new SandboxEvent(task).getResponse(); | ||
| res.token = token; | ||
|
|
||
| out.println(gson.toJson(res)); | ||
| send(res); | ||
|
|
||
| } | ||
|
|
||
| static void send(Object o) { | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| class CompeteResponse { | ||
|
|
||
| public CompileResponse response; | ||
| public String token; | ||
|
|
||
| } | ||
|
|
||
| class gay implements SandboxEventListener{ | ||
|
|
||
| @Override | ||
| public void event(SandboxEvent event) { | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,35 @@ | ||
| package sandbox; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class SandboxEvent { | ||
|
|
||
| // public final boolean error; | ||
| // public final String output; | ||
| final SandboxTask task; | ||
|
|
||
| public SandboxEvent(SandboxTask task){ | ||
| // error = task.error; | ||
| // output = task.out.toString(); | ||
| this.task=task; | ||
| } | ||
|
|
||
| public CompileResponse getResponse(){ | ||
| CompileResponse r = new CompileResponse(); | ||
| r.output=task.out.toString(); | ||
| r.error=task.error; | ||
| r.id=task.id; | ||
| return r; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| class CompileResponse{ | ||
|
|
||
| public String output; | ||
| public boolean error; | ||
| public int id; | ||
|
|
||
| } |
| @@ -0,0 +1,11 @@ | ||
| package sandbox; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public interface SandboxEventListener { | ||
|
|
||
| public void event(SandboxEvent event); | ||
|
|
||
| } |
| @@ -0,0 +1,75 @@ | ||
| package sandbox; | ||
|
|
||
| import java.io.FilePermission; | ||
| import java.security.Permission; | ||
| import java.util.Arrays; | ||
| import java.util.PropertyPermission; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class SandboxSecurityManager extends SecurityManager { | ||
|
|
||
| { | ||
| try { | ||
| Class.forName("legit.moscow.sandbox.SandboxTask"); | ||
|
|
||
| } catch (Exception e) { | ||
| System.out.print(""); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPermission(Permission perm) { | ||
| // System.err.println(Arrays.toString(Thread.currentThread().getStackTrace())); | ||
|
|
||
| if (!(Thread.currentThread() instanceof SandboxTask)) { | ||
| return; | ||
| } | ||
| // System.err.println(perm.getName()); | ||
|
|
||
| if (perm instanceof FilePermission) { | ||
| FilePermission fp = (FilePermission) perm; | ||
| if ((fp.getActions().equals("read"))) { | ||
| return; | ||
| } | ||
| } | ||
| if (perm instanceof PropertyPermission) { | ||
| return; | ||
| } | ||
| // System.err.println(perm.toString()); | ||
| String trace = java.util.Arrays.toString(Thread.currentThread().getStackTrace()); | ||
| // System.err.println(trace); | ||
|
|
||
|
|
||
| if (trace.contains("java.lang.invoke.InnerClassLambdaMetafactory")) { | ||
| return; | ||
| } | ||
|
|
||
| if(trace.contains("java.text.NumberFormat.getInstance")){ | ||
| return; | ||
| } | ||
|
|
||
| // if (trace.contains("legit.moscow.compiler.UniqueThreadPrintStream")) { | ||
| // return; | ||
| // } | ||
| // if(trace.contains("com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(")){ | ||
| // return; | ||
| // } | ||
| // UniqueThreadPrintStream.std.println(trace); | ||
| throw new SecurityException(perm.toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkAccess(Thread t) { | ||
|
|
||
| if (!(Thread.currentThread() instanceof SandboxTask)) { | ||
| return; | ||
| } | ||
|
|
||
| throw new SecurityException(t + " tried to make a thread"); | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,112 @@ | ||
| package sandbox; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.OutputStream; | ||
| import java.lang.reflect.Method; | ||
| import javax.tools.ToolProvider; | ||
| import org.mdkt.compiler.InMemoryJavaCompiler; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class SandboxTask extends Thread { | ||
|
|
||
| private Method main; | ||
| boolean error = false; | ||
| private static boolean javapath = ToolProvider.getSystemJavaCompiler() != null; | ||
| private SandboxEventListener listener; | ||
| final OutputStream out; | ||
| final int id; | ||
|
|
||
| SandboxTask(String src, SandboxEventListener listener, int id) { | ||
| super(); | ||
| this.listener = listener; | ||
| this.id = id; | ||
| out = new ByteArrayOutputStream(); | ||
| if (!javapath) { | ||
| throw new IllegalStateException("No java path set! Files will not compile!"); | ||
| } | ||
|
|
||
| int bracecount = 0; | ||
| int dex = 0; | ||
|
|
||
| while (true) { | ||
| if (dex >= src.length() || !src.substring(dex).contains("class")) { | ||
| error = true; | ||
| return; | ||
| } | ||
| String curr = src.substring(dex); | ||
| // System.out.println(dex); | ||
| if (curr.startsWith("public") && curr.substring(0, curr.indexOf("class") + 6) | ||
| .matches("public\\s+class\\s") && bracecount == 0) { | ||
|
|
||
| break; | ||
| } | ||
| if (src.charAt(dex) == '{') { | ||
| bracecount++; | ||
| } | ||
| if (src.charAt(dex) == '}') { | ||
| bracecount--; | ||
| } | ||
| dex++; | ||
|
|
||
| } | ||
|
|
||
| dex = src.substring(dex).indexOf("class") + 5 + dex; | ||
| while (Character.isWhitespace(src.charAt(dex))) { | ||
| dex++; | ||
| } | ||
|
|
||
| int dex2 = dex; | ||
| while (!Character.isWhitespace(src.charAt(dex2)) && !(src.charAt(dex2) == '{')) { | ||
| dex2++; | ||
| } | ||
|
|
||
| String classname = src.substring(dex, dex2); | ||
| System.out.println("Loaded class " + classname); | ||
|
|
||
| try { | ||
| Class clazz = InMemoryJavaCompiler.compile(classname, src); | ||
| main = clazz.getDeclaredMethod("main", String[].class); | ||
|
|
||
| } catch (Throwable t) { | ||
| // t.printStackTrace(); | ||
| error = true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
|
|
||
| try { | ||
| if (error) { | ||
| System.out.println("error"); | ||
| return; | ||
| } | ||
| try { | ||
| main.invoke(null, (Object) null); | ||
| } catch (Exception e) { | ||
| error = true; | ||
| e.printStackTrace(System.out); | ||
| } | ||
| } finally { | ||
| synchronized (listener) { | ||
| listener.notifyAll(); | ||
| } | ||
| listener.event(new SandboxEvent(this)); | ||
| } | ||
| } | ||
|
|
||
| public static void setJavaPath(String path) throws IllegalArgumentException { | ||
| System.setProperty("java.home", path); | ||
| if (javapath = (ToolProvider.getSystemJavaCompiler() != null)) { | ||
|
|
||
| System.out.println("java home successfully set"); | ||
| } else { | ||
| throw new IllegalArgumentException("Invalid java home"); | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,253 @@ | ||
| package sandbox; | ||
|
|
||
| import java.io.File; | ||
| import java.io.OutputStream; | ||
| import java.io.PrintStream; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class UniqueThreadPrintStream extends PrintStream { | ||
|
|
||
| private final Map<Thread, PrintStream> map = new ConcurrentHashMap<>(); | ||
|
|
||
| private final PrintStream parent; | ||
|
|
||
| static PrintStream std = null; | ||
|
|
||
| public UniqueThreadPrintStream(OutputStream out) { | ||
| super(out); | ||
| // new File("out").mkdirs(); | ||
| map.put(Thread.currentThread(), std = parent = new PrintStream(out)); | ||
| } | ||
|
|
||
| void register(SandboxTask caller){ | ||
| if (!map.containsKey(caller)) { | ||
| try { | ||
| map.put(caller, new PrintStream(caller.out)); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void unregister(SandboxTask caller){ | ||
| map.remove(caller); | ||
| } | ||
|
|
||
| private PrintStream out() { | ||
| Thread call = thread(); | ||
| if (!(call instanceof SandboxTask)) { | ||
| return parent; | ||
| } | ||
| // parent.println(caller); | ||
|
|
||
| register((SandboxTask)call); | ||
| return map.get(call); | ||
| } | ||
|
|
||
| private Thread thread() { | ||
| return Thread.currentThread(); | ||
| } | ||
|
|
||
| @Override | ||
| public void flush() { | ||
| out().flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| synchronized (this) { | ||
| super.close(); | ||
| for (PrintStream stream : map.values()) { | ||
| stream.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void write(int b) { | ||
| out().write(b); | ||
| } | ||
|
|
||
| @Override | ||
| public void write(byte buf[], int off, int len) { | ||
| out().write(buf, off, len); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(boolean b) { | ||
| out().print(b ? "true" : "false"); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(char c) { | ||
| out().print(String.valueOf(c)); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(int i) { | ||
| out().print(String.valueOf(i)); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(long l) { | ||
| out().print(String.valueOf(l)); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(float f) { | ||
| out().print(String.valueOf(f)); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(double d) { | ||
| out().print(String.valueOf(d)); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(char s[]) { | ||
| out().print(s); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(String s) { | ||
| if (s == null) { | ||
| s = "null"; | ||
| } | ||
| out().print(s); | ||
| } | ||
|
|
||
| @Override | ||
| public void print(Object obj) { | ||
| out().print(String.valueOf(obj)); | ||
| } | ||
|
|
||
| private void newLine() { | ||
| out().println(); | ||
| } | ||
|
|
||
| @Override | ||
| public void println() { | ||
| newLine(); | ||
| } | ||
|
|
||
| @Override | ||
| public void println(boolean x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(char x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(int x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(long x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(float x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(double x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(char x[]) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(String x) { | ||
| synchronized (this) { | ||
| print(x); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void println(Object x) { | ||
| String s = String.valueOf(x); | ||
| synchronized (this) { | ||
| print(s); | ||
| newLine(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream printf(String format, Object... args) { | ||
| return format(format, args); | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream printf(Locale l, String format, Object... args) { | ||
| return format(l, format, args); | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream format(String format, Object... args) { | ||
| return out().format(format, args); | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream format(Locale l, String format, Object... args) { | ||
| return out().format(l, format, args); | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream append(CharSequence csq) { | ||
| if (csq == null) { | ||
| print("null"); | ||
| } else { | ||
| print(csq.toString()); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream append(CharSequence csq, int start, int end) { | ||
| return out().append(csq, start, end); | ||
| } | ||
|
|
||
| @Override | ||
| public PrintStream append(char c) { | ||
| print(c); | ||
| return this; | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,73 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- You may freely edit this file. See commented blocks below for --> | ||
| <!-- some examples of how to customize the build. --> | ||
| <!-- (If you delete it and reopen the project it will be recreated.) --> | ||
| <!-- By default, only the Clean and Build commands use this build script. --> | ||
| <!-- Commands such as Run, Debug, and Test only use this build script if --> | ||
| <!-- the Compile on Save feature is turned off for the project. --> | ||
| <!-- You can turn off the Compile on Save (or Deploy on Save) setting --> | ||
| <!-- in the project's Project Properties dialog box.--> | ||
| <project name="Worker_Client" default="default" basedir="."> | ||
| <description>Builds, tests, and runs the project Worker Client.</description> | ||
| <import file="nbproject/build-impl.xml"/> | ||
| <!-- | ||
| There exist several targets which are by default empty and which can be | ||
| used for execution of your tasks. These targets are usually executed | ||
| before and after some main targets. They are: | ||
| -pre-init: called before initialization of project properties | ||
| -post-init: called after initialization of project properties | ||
| -pre-compile: called before javac compilation | ||
| -post-compile: called after javac compilation | ||
| -pre-compile-single: called before javac compilation of single file | ||
| -post-compile-single: called after javac compilation of single file | ||
| -pre-compile-test: called before javac compilation of JUnit tests | ||
| -post-compile-test: called after javac compilation of JUnit tests | ||
| -pre-compile-test-single: called before javac compilation of single JUnit test | ||
| -post-compile-test-single: called after javac compilation of single JUunit test | ||
| -pre-jar: called before JAR building | ||
| -post-jar: called after JAR building | ||
| -post-clean: called after cleaning build products | ||
| (Targets beginning with '-' are not intended to be called on their own.) | ||
| Example of inserting an obfuscator after compilation could look like this: | ||
| <target name="-post-compile"> | ||
| <obfuscate> | ||
| <fileset dir="${build.classes.dir}"/> | ||
| </obfuscate> | ||
| </target> | ||
| For list of available properties check the imported | ||
| nbproject/build-impl.xml file. | ||
| Another way to customize the build is by overriding existing main targets. | ||
| The targets of interest are: | ||
| -init-macrodef-javac: defines macro for javac compilation | ||
| -init-macrodef-junit: defines macro for junit execution | ||
| -init-macrodef-debug: defines macro for class debugging | ||
| -init-macrodef-java: defines macro for class execution | ||
| -do-jar: JAR building | ||
| run: execution of project | ||
| -javadoc-build: Javadoc generation | ||
| test-report: JUnit report generation | ||
| An example of overriding the target for project execution could look like this: | ||
| <target name="run" depends="Worker_Client-impl.jar"> | ||
| <exec dir="bin" executable="launcher.exe"> | ||
| <arg file="${dist.jar}"/> | ||
| </exec> | ||
| </target> | ||
| Notice that the overridden target depends on the jar target and not only on | ||
| the compile target as the regular run target does. Again, for a list of available | ||
| properties which you can use, check the target you are overriding in the | ||
| nbproject/build-impl.xml file. | ||
| --> | ||
| </project> |
| @@ -0,0 +1,3 @@ | ||
| Manifest-Version: 1.0 | ||
| X-COMMENT: Main-Class will be added automatically by build | ||
|
|
| @@ -0,0 +1,8 @@ | ||
| build.xml.data.CRC32=9022233f | ||
| build.xml.script.CRC32=e36ceb32 | ||
| build.xml.stylesheet.CRC32=8064a381@1.79.1.48 | ||
| # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
| # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
| nbproject/build-impl.xml.data.CRC32=9022233f | ||
| nbproject/build-impl.xml.script.CRC32=a54a032d | ||
| nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48 |
| @@ -0,0 +1,74 @@ | ||
| annotation.processing.enabled=true | ||
| annotation.processing.enabled.in.editor=false | ||
| annotation.processing.processor.options= | ||
| annotation.processing.processors.list= | ||
| annotation.processing.run.all.processors=true | ||
| annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output | ||
| build.classes.dir=${build.dir}/classes | ||
| build.classes.excludes=**/*.java,**/*.form | ||
| # This directory is removed when the project is cleaned: | ||
| build.dir=build | ||
| build.generated.dir=${build.dir}/generated | ||
| build.generated.sources.dir=${build.dir}/generated-sources | ||
| # Only compile against the classpath explicitly listed here: | ||
| build.sysclasspath=ignore | ||
| build.test.classes.dir=${build.dir}/test/classes | ||
| build.test.results.dir=${build.dir}/test/results | ||
| # Uncomment to specify the preferred debugger connection transport: | ||
| #debug.transport=dt_socket | ||
| debug.classpath=\ | ||
| ${run.classpath} | ||
| debug.test.classpath=\ | ||
| ${run.test.classpath} | ||
| # Files in build.classes.dir which should be excluded from distribution jar | ||
| dist.archive.excludes= | ||
| # This directory is removed when the project is cleaned: | ||
| dist.dir=dist | ||
| dist.jar=${dist.dir}/Worker_Client.jar | ||
| dist.javadoc.dir=${dist.dir}/javadoc | ||
| excludes= | ||
| includes=** | ||
| jar.compress=false | ||
| javac.classpath= | ||
| # Space-separated list of extra javac options | ||
| javac.compilerargs= | ||
| javac.deprecation=false | ||
| javac.external.vm=true | ||
| javac.processorpath=\ | ||
| ${javac.classpath} | ||
| javac.source=1.8 | ||
| javac.target=1.8 | ||
| javac.test.classpath=\ | ||
| ${javac.classpath}:\ | ||
| ${build.classes.dir} | ||
| javac.test.processorpath=\ | ||
| ${javac.test.classpath} | ||
| javadoc.additionalparam= | ||
| javadoc.author=false | ||
| javadoc.encoding=${source.encoding} | ||
| javadoc.noindex=false | ||
| javadoc.nonavbar=false | ||
| javadoc.notree=false | ||
| javadoc.private=false | ||
| javadoc.splitindex=true | ||
| javadoc.use=true | ||
| javadoc.version=false | ||
| javadoc.windowtitle= | ||
| main.class=Main | ||
| manifest.file=manifest.mf | ||
| meta.inf.dir=${src.dir}/META-INF | ||
| mkdist.disabled=false | ||
| platform.active=default_platform | ||
| run.classpath=\ | ||
| ${javac.classpath}:\ | ||
| ${build.classes.dir} | ||
| # Space-separated list of JVM arguments used when running the project. | ||
| # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. | ||
| # To set system properties for unit tests define test-sys-prop.name=value: | ||
| run.jvmargs= | ||
| run.test.classpath=\ | ||
| ${javac.test.classpath}:\ | ||
| ${build.test.classes.dir} | ||
| source.encoding=UTF-8 | ||
| src.dir=src | ||
| test.src.dir=test |
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://www.netbeans.org/ns/project/1"> | ||
| <type>org.netbeans.modules.java.j2seproject</type> | ||
| <configuration> | ||
| <data xmlns="http://www.netbeans.org/ns/j2se-project/3"> | ||
| <name>Worker Client</name> | ||
| <source-roots> | ||
| <root id="src.dir"/> | ||
| </source-roots> | ||
| <test-roots> | ||
| <root id="test.src.dir"/> | ||
| </test-roots> | ||
| </data> | ||
| </configuration> | ||
| </project> |
| @@ -0,0 +1,30 @@ | ||
|
|
||
| import java.lang.ProcessBuilder.Redirect; | ||
|
|
||
|
|
||
| /** | ||
| * | ||
| * @author Nathan Dias {@literal <nathanxyzdias@gmail.com>} | ||
| */ | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
|
|
||
| String jhome = System.getenv("JAVA_HOME"); | ||
|
|
||
| ProcessBuilder builder = new ProcessBuilder(jhome+"/bin/java.exe", "-jar", "C:/users/natha/documents/github/Compete-Engine/Worker/Java Compiler/dist/Java_Compiler.jar"); | ||
|
|
||
| builder.redirectError(Redirect.INHERIT); | ||
| builder.redirectOutput(Redirect.INHERIT); | ||
| builder.redirectInput(Redirect.INHERIT); | ||
|
|
||
|
|
||
| builder.environment().put("test", "works!"); | ||
|
|
||
|
|
||
| builder.start(); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,7 @@ | ||
| libs.CopyLibs.classpath=\ | ||
| ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar | ||
| libs.CopyLibs.displayName=CopyLibs Task | ||
| libs.CopyLibs.prop-version=2.0 | ||
| libs.Gson.classpath=\ | ||
| ${base}/gson-2.6.2.jar | ||
| libs.Gson.displayName=Gson |