Search in sources :

Example 1 with ConsoleReporter

use of scala.tools.nsc.reporters.ConsoleReporter in project navajo by Dexels.

the class ScalaCompiler method compileScript.

@Override
protected Set<String> compileScript(File scriptFile, String script, String packagePath, List<Dependency> dependencies, String tenant, boolean hasTenantSpecificFile, boolean forceTenant) throws CompilationException {
    final Set<String> packages = new HashSet<>();
    for (String pkg : standardPackages) {
        packages.add(pkg);
    }
    PackageReportingClassLoader prc = new PackageReportingClassLoader(navajoScriptClassLoader);
    prc.addPackageListener(name -> {
        if (whitelist.contains(name)) {
            packages.add(name);
        }
    });
    File targetDir = new File(navajoIOConfig.getCompiledScriptPath(), packagePath + File.separator + script);
    targetDir.mkdirs();
    Settings settings = new Settings();
    settings.outputDirs().setSingleOutput(targetDir.getAbsolutePath());
    ConsoleReporter reporter = new ConsoleReporter(settings);
    ReflectGlobal g = new ReflectGlobal(settings, reporter, prc);
    Global.Run compiler = g.new Run();
    ListBuffer<String> files = new ListBuffer<>();
    String file = scriptFile.getAbsolutePath();
    addScalaCommon(files);
    files.$plus$eq(file);
    try {
        compiler.compile(files.toList());
    } catch (Exception e) {
        logger.error("Exception on getting scala code! {}", e);
    }
    logger.debug("finished compiling scala for the following files: {}", compiler.compiledFiles());
    return packages;
}
Also used : ConsoleReporter(scala.tools.nsc.reporters.ConsoleReporter) ListBuffer(scala.collection.mutable.ListBuffer) PackageReportingClassLoader(com.dexels.navajo.compiler.tsl.custom.PackageReportingClassLoader) Global(scala.tools.nsc.Global) ReflectGlobal(scala.tools.reflect.ReflectGlobal) IOException(java.io.IOException) CompilationException(com.dexels.navajo.script.api.CompilationException) File(java.io.File) Settings(scala.tools.nsc.Settings) ReflectGlobal(scala.tools.reflect.ReflectGlobal) HashSet(java.util.HashSet)

Aggregations

PackageReportingClassLoader (com.dexels.navajo.compiler.tsl.custom.PackageReportingClassLoader)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ListBuffer (scala.collection.mutable.ListBuffer)1 Global (scala.tools.nsc.Global)1 Settings (scala.tools.nsc.Settings)1 ConsoleReporter (scala.tools.nsc.reporters.ConsoleReporter)1 ReflectGlobal (scala.tools.reflect.ReflectGlobal)1