static WorkResult execute(ScalaJavaJointCompileSpec spec) { LOGGER.info("Compiling with Zinc Scala compiler."); xsbti.Logger logger = new SbtLoggerAdapter(); com.typesafe.zinc.Compiler compiler = createCompiler(spec.getScalaClasspath(), spec.getZincClasspath(), logger); List<String> scalacOptions = new ScalaCompilerArgumentsGenerator().generate(spec); List<String> javacOptions = new JavaCompilerArgumentsBuilder(spec).includeClasspath(false).build(); Inputs inputs = Inputs.create(ImmutableList.copyOf(spec.getClasspath()), ImmutableList.copyOf(spec.getSource()), spec.getDestinationDir(), scalacOptions, javacOptions, spec.getScalaCompileOptions().getIncrementalOptions().getAnalysisFile(), spec.getAnalysisMap(), "mixed", getIncOptions(), true); if (LOGGER.isDebugEnabled()) { Inputs.debug(inputs, logger); } try { compiler.compile(inputs, logger); } catch (xsbti.CompileFailed e) { throw new CompilationFailedException(e); } return new SimpleWorkResult(true); }
static WorkResult execute(final Iterable<File> scalaClasspath, final Iterable<File> zincClasspath, File gradleUserHome, final ScalaJavaJointCompileSpec spec) { LOGGER.info("Compiling with Zinc Scala compiler."); final xsbti.Logger logger = new SbtLoggerAdapter(); com.typesafe.zinc.Compiler compiler = ZincScalaCompilerFactory.createParallelSafeCompiler(scalaClasspath, zincClasspath, logger, gradleUserHome); List<String> scalacOptions = new ZincScalaCompilerArgumentsGenerator().generate(spec); List<String> javacOptions = new JavaCompilerArgumentsBuilder(spec).includeClasspath(false).build(); Inputs inputs = Inputs.create(ImmutableList.copyOf(spec.getClasspath()), ImmutableList.copyOf(spec.getSource()), spec.getDestinationDir(), scalacOptions, javacOptions, spec.getScalaCompileOptions().getIncrementalOptions().getAnalysisFile(), spec.getAnalysisMap(), "mixed", getIncOptions(), true); if (LOGGER.isDebugEnabled()) { Inputs.debug(inputs, logger); } if (spec.getScalaCompileOptions().isForce()) { GFileUtils.deleteDirectory(spec.getDestinationDir()); } try { compiler.compile(inputs, logger); } catch (xsbti.CompileFailed e) { throw new CompilationFailedException(e); } return new SimpleWorkResult(true); }
private void logCompilerArguments(ScalaJavaJointCompileSpec spec) { if (!LOGGER.isDebugEnabled()) { return; } List<String> compilerArgs = new JavaCompilerArgumentsBuilder(spec).includeLauncherOptions(true).includeSourceFiles(true).build(); String joinedArgs = Joiner.on(' ').join(compilerArgs); LOGGER.debug("Java compiler arguments: {}", joinedArgs); }
private JavaCompiler.CompilationTask createCompileTask(JavaCompileSpec spec) { List<String> options = new JavaCompilerArgumentsBuilder(spec).build(); JavaCompiler compiler = findCompiler(); if(compiler==null){ throw new RuntimeException("Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory."); } CompileOptions compileOptions = spec.getCompileOptions(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, compileOptions.getEncoding() != null ? Charset.forName(compileOptions.getEncoding()) : null); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(spec.getSource()); return compiler.getTask(null, null, null, options, null, compilationUnits); }