use of xsbti.VirtualFile in project gradle by gradle.
the class ZincScalaCompiler method execute.
public WorkResult execute(final ScalaJavaJointCompileSpec spec) {
LOGGER.info("Compiling with Zinc Scala compiler.");
Timer timer = Time.startTimer();
IncrementalCompilerImpl incremental = new IncrementalCompilerImpl();
Compilers compilers = incremental.compilers(scalaInstance, ClasspathOptionsUtil.boot(), Option.apply(Jvm.current().getJavaHome().toPath()), scalaCompiler);
List<String> scalacOptions = new ZincScalaCompilerArgumentsGenerator().generate(spec);
List<String> javacOptions = new JavaCompilerArgumentsBuilder(spec).includeClasspath(false).noEmptySourcePath().build();
List<VirtualFile> classpath = new LinkedList<>();
for (File classpathEntry : spec.getCompileClasspath()) {
classpath.add(CONVERTER.toVirtualFile(classpathEntry.toPath()));
}
List<VirtualFile> sourceFiles = new LinkedList<>();
for (File f : spec.getSourceFiles()) {
sourceFiles.add(CONVERTER.toVirtualFile(f.toPath()));
}
CompileOptions compileOptions = CompileOptions.create().withSources(Iterables.toArray(sourceFiles, VirtualFile.class)).withClasspath(Iterables.toArray(classpath, VirtualFile.class)).withScalacOptions(scalacOptions.toArray(new String[0])).withClassesDirectory(spec.getDestinationDir().toPath()).withJavacOptions(javacOptions.toArray(new String[0]));
File analysisFile = spec.getAnalysisFile();
Optional<AnalysisStore> analysisStore;
Optional<ClassFileManagerType> classFileManagerType;
if (spec.getScalaCompileOptions().isForce()) {
analysisStore = Optional.empty();
classFileManagerType = IncOptions.defaultClassFileManagerType();
} else {
analysisStore = Optional.of(analysisStoreProvider.get(analysisFile));
classFileManagerType = Optional.of(TransactionalManagerType.of(spec.getClassfileBackupDir(), new SbtLoggerAdapter()));
}
PreviousResult previousResult = analysisStore.flatMap(store -> store.get().map(a -> PreviousResult.of(Optional.of(a.getAnalysis()), Optional.of(a.getMiniSetup())))).orElse(PreviousResult.of(Optional.empty(), Optional.empty()));
IncOptions incOptions = IncOptions.of().withExternalHooks(new LookupOnlyExternalHooks(new ExternalBinariesLookup())).withRecompileOnMacroDef(Optional.of(false)).withClassfileManagerType(classFileManagerType).withTransitiveStep(5);
Setup setup = incremental.setup(new EntryLookup(spec), false, analysisFile.toPath(), CompilerCache.fresh(), incOptions, // MappedPosition is used to make sure toString returns proper error messages
new LoggedReporter(100, new SbtLoggerAdapter(), MappedPosition::new), Option.empty(), Option.empty(), getExtra());
Inputs inputs = incremental.inputs(compileOptions, compilers, setup, previousResult);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(inputs.toString());
}
if (spec.getScalaCompileOptions().isForce()) {
// TODO This should use Deleter
GFileUtils.deleteDirectory(spec.getDestinationDir());
GFileUtils.deleteQuietly(spec.getAnalysisFile());
}
LOGGER.info("Prepared Zinc Scala inputs: {}", timer.getElapsed());
try {
CompileResult compile = incremental.compile(inputs, new SbtLoggerAdapter());
if (analysisStore.isPresent()) {
AnalysisContents contentNext = AnalysisContents.create(compile.analysis(), compile.setup());
analysisStore.get().set(contentNext);
}
} catch (xsbti.CompileFailed e) {
throw new CompilationFailedException(e);
}
LOGGER.info("Completed Scala compilation: {}", timer.getElapsed());
return WorkResults.didWork(true);
}
Aggregations