use of javax.tools.JavaCompiler in project neo4j by neo4j.
the class DbStructureInvocationTracingAcceptanceTest method compile.
private <T> T compile(String className, String source, CompilationListener<T> listener) {
JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
JavaFileManager manager = new InMemFileManager();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>();
Iterable<? extends JavaFileObject> sources = Arrays.asList(new InMemSource(className, source));
CompilationTask task = systemCompiler.getTask(null, manager, diagnosticsCollector, null, null, sources);
Boolean success = task.call();
return listener.compiled(success, manager, diagnosticsCollector.getDiagnostics());
}
use of javax.tools.JavaCompiler in project jadx by skylot.
the class DynamicCompiler method compile.
public boolean compile() throws Exception {
String fullName = clsNode.getFullName();
String code = clsNode.getCode().toString();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
fileManager = new ClassFileManager(compiler.getStandardFileManager(null, null, null));
List<JavaFileObject> jFiles = new ArrayList<JavaFileObject>(1);
jFiles.add(new CharSequenceJavaFileObject(fullName, code));
CompilationTask compilerTask = compiler.getTask(null, fileManager, null, null, null, jFiles);
return Boolean.TRUE.equals(compilerTask.call());
}
use of javax.tools.JavaCompiler in project DistributedFractalNetwork by Budder21.
the class DynamicCompiler method compile.
/** compile your files by JavaCompiler. If the class was succesfuly compiled, it will print 'Succeded'. Otherwise, it
* will print diagnositc information.
* @param files takes in an Arrays.asList of the JavaFileObject
* @throws NullPointerException this is thrown if the java file is run from a JRE instead of a JDK.
*/
public static void compile(Iterable<? extends JavaFileObject> files) throws NullPointerException {
// get system compiler:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
// for compilation diagnostic message processing on compilation
// WARNING/ERROR
MyDiagnosticListener c = new MyDiagnosticListener();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(c, Locale.ENGLISH, null);
// specify classes output folder
Iterable options = Arrays.asList("-d", classOutputFolder);
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, c, options, null, files);
Boolean result = task.call();
if (result == true) {
System.out.println("Succeeded");
} else
System.out.println("Failed");
}
use of javax.tools.JavaCompiler in project intellij-community by JetBrains.
the class JavacCompilerTool method createCompiler.
@NotNull
@Override
public JavaCompiler createCompiler() throws CannotCreateJavaCompilerException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler != null) {
return compiler;
}
String message = "System Java Compiler was not found in classpath";
// trying to obtain additional diagnostic for the case when compiler.jar is present, but there were problems with compiler class loading:
try {
Class.forName("com.sun.tools.javac.api.JavacTool", false, JavacMain.class.getClassLoader());
} catch (Throwable ex) {
StringWriter stringWriter = new StringWriter();
stringWriter.write(message);
stringWriter.write(":\n");
ex.printStackTrace(new PrintWriter(stringWriter));
message = stringWriter.getBuffer().toString();
}
throw new CannotCreateJavaCompilerException(message);
}
use of javax.tools.JavaCompiler in project intellij-community by JetBrains.
the class EclipseCompilerTool method getDescription.
@NotNull
@Override
public String getDescription() {
String version = myVersion;
if (version == null) {
version = "";
//final File file = findEcjJarFile();
final JavaCompiler compiler = findCompiler();
final String path = compiler != null ? PathManager.getJarPathForClass(compiler.getClass()) : null;
final File file = path != null ? new File(path) : null;
if (file != null) {
final String name = file.getName();
if (name.startsWith(JAR_FILE_NAME_PREFIX) && name.endsWith(JAR_FILE_NAME_SUFFIX)) {
version = " " + name.substring(JAR_FILE_NAME_PREFIX.length(), name.length() - JAR_FILE_NAME_SUFFIX.length());
}
}
myVersion = version;
}
return "Eclipse compiler" + version;
}
Aggregations