use of com.dexels.navajo.script.api.CompilationException in project navajo by Dexels.
the class BundleQueueComponent method ensureScriptDependencies.
// ensure that dependencies of the current script are satisfied. If dependencies
// are not satisfied, create them
private void ensureScriptDependencies(String script) {
String rpcName = script;
String bareScript = script.substring(script.lastIndexOf('/') + 1);
if (bareScript.indexOf('_') >= 0) {
rpcName = script.substring(0, script.lastIndexOf('_'));
}
// For now, only entity dependencies are relevant script dependencies.
// For instance, in the case the server runs in DEVELOP_MODE where
// entities are lazily loaded, all bundles for super entities also need
// to be installed
List<Dependency> dependencies = depanalyzer.getDependencies(rpcName, Dependency.ENTITY_DEPENDENCY);
for (Dependency dependency : dependencies) {
String depScript = dependency.getDependee();
try {
// do an on demand call to the bundle creator, we only need the script to be
// compiled, if it wasn't there yet
bundleCreator.getOnDemandScriptService(depScript, null);
ensureScriptDependencies(depScript);
} catch (CompilationException e) {
logger.info("Failed to compile {} after a change in {}: {}", depScript, script, e);
}
}
}
use of com.dexels.navajo.script.api.CompilationException in project navajo by Dexels.
the class OSGiJavaCompilerImplementation method compile.
@Override
public byte[] compile(String className, InputStream source) throws IOException, CompilationException {
JavaFileObject javaSource = getJavaSourceFileObject(className, source);
Iterable<? extends JavaFileObject> fileObjects = Arrays.asList(javaSource);
final Writer sw = new StringWriter();
DiagnosticListener<JavaFileObject> compilerOutputListener = jfo -> {
try {
sw.write("Compilation problem. Line in .java file: " + jfo.getLineNumber() + ", error: " + jfo.getMessage(Locale.ENGLISH) + "\n");
} catch (IOException e) {
logger.error("Compilation problem: ", e);
}
};
StringWriter swe = new StringWriter();
List<String> options = new ArrayList<>();
options.add("-nowarn");
options.add("-target");
options.add("1.8");
CompilationTask task = compiler.getTask(swe, customJavaFileManager, compilerOutputListener, options, null, fileObjects);
boolean success = task.call();
if (!success) {
throw new CompilationException(sw.toString() + "\n" + swe.toString());
}
CustomJavaFileObject jfo = (CustomJavaFileObject) customJavaFileManager.getJavaFileForInput(StandardLocation.CLASS_OUTPUT, className, Kind.CLASS);
if (jfo == null) {
logger.error("Compilation failed: {} \n {}", sw, swe);
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(jfo.openInputStream(), baos);
return baos.toByteArray();
}
Aggregations