Add option to specify extra classpath

This commit is contained in:
konsoletyper 2015-03-14 16:11:12 +03:00
parent cff5460ac3
commit 73998d57a9

View File

@ -16,6 +16,9 @@
package org.teavm.cli; package org.teavm.cli;
import java.io.*; import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import org.teavm.tooling.RuntimeCopyOperation; import org.teavm.tooling.RuntimeCopyOperation;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
@ -32,6 +35,7 @@ public final class TeaVMRunner {
private static long startTime; private static long startTime;
private static long phaseStartTime; private static long phaseStartTime;
private static TeaVMPhase currentPhase; private static TeaVMPhase currentPhase;
private static String[] classPath;
private TeaVMRunner() { private TeaVMRunner() {
} }
@ -90,6 +94,12 @@ public final class TeaVMRunner {
.withDescription("Wait for command after compilation, in order to enable hot recompilation") .withDescription("Wait for command after compilation, in order to enable hot recompilation")
.withLongOpt("--wait") .withLongOpt("--wait")
.create('w')); .create('w'));
options.addOption(OptionBuilder
.withArgName("classpath")
.hasArgs()
.withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode")
.withLongOpt("--classpath")
.create('p'));
if (args.length == 0) { if (args.length == 0) {
printUsage(options); printUsage(options);
@ -151,6 +161,9 @@ public final class TeaVMRunner {
} else { } else {
tool.setCacheDirectory(new File(tool.getTargetDirectory(), "teavm-cache")); tool.setCacheDirectory(new File(tool.getTargetDirectory(), "teavm-cache"));
} }
if (commandLine.hasOption('p')) {
classPath = commandLine.getOptionValues('p');
}
boolean interactive = commandLine.hasOption('w'); boolean interactive = commandLine.hasOption('w');
args = commandLine.getArgs(); args = commandLine.getArgs();
if (args.length > 1) { if (args.length > 1) {
@ -209,6 +222,7 @@ public final class TeaVMRunner {
} }
private static void build(TeaVMTool tool) throws TeaVMToolException { private static void build(TeaVMTool tool) throws TeaVMToolException {
resetClassLoader(tool);
currentPhase = null; currentPhase = null;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
phaseStartTime = System.currentTimeMillis(); phaseStartTime = System.currentTimeMillis();
@ -217,6 +231,24 @@ public final class TeaVMRunner {
System.out.println("Build complete for " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds"); System.out.println("Build complete for " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds");
} }
private static void resetClassLoader(TeaVMTool tool) {
if (classPath.length == 0) {
return;
}
URL[] urls = new URL[classPath.length];
for (int i = 0; i < classPath.length; ++i) {
try {
urls[i] = new File(classPath[i]).toURI().toURL();
} catch (MalformedURLException e) {
System.err.println("Illegal classpath entry: " + classPath[i]);
System.exit(-1);
return;
}
}
tool.setClassLoader(new URLClassLoader(urls, TeaVMRunner.class.getClassLoader()));
}
private static TeaVMProgressListener progressListener = new TeaVMProgressListener() { private static TeaVMProgressListener progressListener = new TeaVMProgressListener() {
@Override @Override
public TeaVMProgressFeedback progressReached(int progress) { public TeaVMProgressFeedback progressReached(int progress) {