Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tools provider #15

Merged
merged 3 commits into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>minimaven</artifactId>
<version>2.1.5-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>

<name>Minimal support for Maven projects</name>
<description>A minimal build system interpreting Maven-style pom.xml files</description>
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/org/scijava/minimaven/JavaCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
import java.io.Writer;
import java.lang.reflect.Method;

import javax.tools.ToolProvider;

import org.scijava.util.ClassUtils;
import org.scijava.util.FileUtils;
import org.scijava.util.ProcessUtils;

/**
* Encapsulates the Java compiler, falling back to command-line {@code javac}.
*
* @author Johannes Schindelin
* @author Mark Hiner
*/
public class JavaCompiler {
protected PrintStream err, out;
Expand All @@ -57,9 +61,29 @@ public JavaCompiler(PrintStream err, PrintStream out) {

// this function handles the javac singleton
public void call(String[] arguments,
boolean verbose) throws CompileError {
boolean verbose) throws CompileError {
call(arguments, verbose, false);
}

public void call(String[] arguments,
boolean verbose, boolean debug) throws CompileError {
synchronized(this) {
try {
javax.tools.JavaCompiler sysc = ToolProvider.getSystemJavaCompiler();
if (sysc != null) {
if (debug) {
err.print("Found tools compiler: " + sysc.getClass());
err.print(ClassUtils.getLocation(sysc.getClass()));
}
sysc.run(null, out, err, arguments);
return;
}

if (verbose){
err.println(
"No javax.tools.JavaCompiler available. Checking for explicit javac.");
}

if (javac == null) {
JarClassLoader loader = discoverJavac();
Class<?> main = loader == null ?
Expand All @@ -83,9 +107,11 @@ public void call(String[] arguments,
/* re-throw */
throw e;
} catch (Exception e) {
e.printStackTrace(err);
err.println("Could not find javac " + e
+ ", falling back to system javac");
if (verbose) {
e.printStackTrace(err);
err.println("Could not find javac " + e
+ ", falling back to system javac");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scijava/minimaven/MavenProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public void build(boolean makeJar, boolean forceBuild, boolean includeSources) t
}
String[] array = arguments.toArray(new String[arguments.size()]);
if (env.javac != null)
env.javac.call(array, env.verbose);
env.javac.call(array, env.verbose, env.debug);
}

updateRecursively(resources, target, false);
Expand Down