@Override public WorkResult execute(JavaCompileSpec spec) { Timer clock = Timers.startTimer(); JarClasspathSnapshot jarClasspathSnapshot = jarClasspathSnapshotProvider.getJarClasspathSnapshot(spec.getClasspath()); RecompilationSpec recompilationSpec = recompilationSpecProvider.provideRecompilationSpec(inputs, previousCompilation, jarClasspathSnapshot); if (recompilationSpec.isFullRebuildNeeded()) { LOG.lifecycle("Full recompilation is required because {}. Analysis took {}.", recompilationSpec.getFullRebuildCause(), clock.getElapsed()); return cleaningCompiler.execute(spec); } incrementalCompilationInitilizer.initializeCompilation(spec, recompilationSpec.getClassNames()); if (spec.getSource().isEmpty()) { LOG.lifecycle("None of the classes needs to be compiled! Analysis took {}. ", clock.getElapsed()); return new RecompilationNotNecessary(); } try { //use the original compiler to avoid cleaning up all the files return cleaningCompiler.getCompiler().execute(spec); } finally { LOG.lifecycle("Incremental compilation of {} classes completed in {}.", recompilationSpec.getClassNames().size(), clock.getElapsed()); } }
private Compiler<JavaCompileSpec> getCompiler(IncrementalTaskInputs inputs, CompilationSourceDirs sourceDirs) { if (!inputs.isIncremental()) { LOG.lifecycle("{} - is not incremental (e.g. outputs have changed, no previous execution, etc.).", displayName); return cleaningCompiler; } if (!sourceDirs.canInferSourceRoots()) { LOG.lifecycle("{} - is not incremental. Unable to infer the source directories.", displayName); return cleaningCompiler; } ClassSetAnalysisData data = compileCaches.getLocalClassSetAnalysisStore().get(); if (data == null) { LOG.lifecycle("{} - is not incremental. No class analysis data available from the previous build.", displayName); return cleaningCompiler; } PreviousCompilation previousCompilation = new PreviousCompilation(new ClassSetAnalysis(data), compileCaches.getLocalJarClasspathSnapshotStore(), compileCaches.getJarSnapshotCache()); return new SelectiveCompiler(inputs, previousCompilation, cleaningCompiler, staleClassDetecter, compilationInitializer, jarClasspathSnapshotMaker); }
public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) { if (staleClasses.isEmpty()) { spec.setSource(new SimpleFileCollection()); return; //do nothing. No classes need recompilation. } Factory<PatternSet> patternSetFactory = fileOperations.getFileResolver().getPatternSetFactory(); PatternSet classesToDelete = patternSetFactory.create(); PatternSet sourceToCompile = patternSetFactory.create(); preparePatterns(staleClasses, classesToDelete, sourceToCompile); //selectively configure the source spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile)); //since we're compiling selectively we need to include the classes compiled previously spec.setClasspath(Iterables.concat(spec.getClasspath(), asList(spec.getDestinationDir()))); //get rid of stale files FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete); fileOperations.delete(deleteMe); }
public WorkResult execute(JavaCompileSpec spec) { Clock clock = new Clock(); JarClasspathSnapshot jarClasspathSnapshot = jarClasspathSnapshotProvider.getJarClasspathSnapshot(spec.getClasspath()); RecompilationSpec recompilationSpec = recompilationSpecProvider.provideRecompilationSpec(inputs, previousCompilation, jarClasspathSnapshot); if (recompilationSpec.isFullRebuildNeeded()) { LOG.lifecycle("Full recompilation is required because {}. Analysis took {}.", recompilationSpec.getFullRebuildCause(), clock.getTime()); return cleaningCompiler.execute(spec); } incrementalCompilationInitilizer.initializeCompilation(spec, recompilationSpec.getClassNames()); if (spec.getSource().isEmpty()) { LOG.lifecycle("None of the classes needs to compiled! Analysis took {}. ", clock.getTime()); return new RecompilationNotNecessary(); } try { //use the original compiler to avoid cleaning up all the files return cleaningCompiler.getCompiler().execute(spec); } finally { LOG.lifecycle("Incremental compilation of {} classes completed in {}.", recompilationSpec.getClassNames().size(), clock.getTime()); } }
private Compiler<JavaCompileSpec> getCompiler(IncrementalTaskInputs inputs, CompilationSourceDirs sourceDirs) { if (!inputs.isIncremental()) { LOG.lifecycle("{} - is not incremental (e.g. outputs have changed, no previous execution, etc.).", displayName); return cleaningCompiler; } if (!sourceDirs.areSourceDirsKnown()) { LOG.lifecycle("{} - is not incremental. Unable to infer the source directories.", displayName); return cleaningCompiler; } ClassSetAnalysisData data = compileCaches.getLocalClassSetAnalysisStore().get(); if (data == null) { LOG.lifecycle("{} - is not incremental. No class analysis data available from the previous build.", displayName); return cleaningCompiler; } PreviousCompilation previousCompilation = new PreviousCompilation(new ClassSetAnalysis(data), compileCaches.getLocalJarClasspathSnapshotStore(), compileCaches.getJarSnapshotCache()); return new SelectiveCompiler(inputs, previousCompilation, cleaningCompiler, staleClassDetecter, compilationInitializer, jarClasspathSnapshotMaker); }
public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) { if (staleClasses.isEmpty()) { spec.setSource(new SimpleFileCollection()); return; //do nothing. No classes need recompilation. } PatternSet classesToDelete = new PatternSet(); PatternSet sourceToCompile = new PatternSet(); preparePatterns(staleClasses, classesToDelete, sourceToCompile); //selectively configure the source spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile)); //since we're compiling selectively we need to include the classes compiled previously spec.setClasspath(Iterables.concat(spec.getClasspath(), asList(spec.getDestinationDir()))); //get rid of stale files FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete); fileOperations.delete(deleteMe); }
@TaskAction protected void compile(IncrementalTaskInputs inputs) { if (!compileOptions.isIncremental()) { compile(); return; } SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation"); DefaultJavaCompileSpec spec = createSpec(); final CacheRepository cacheRepository = getCacheRepository(); final GeneralCompileCaches generalCompileCaches = getGeneralCompileCaches(); CompileCaches compileCaches = new CompileCaches() { private final CacheRepository repository = cacheRepository; private final JavaCompile javaCompile = JavaCompile.this; private final GeneralCompileCaches generalCaches = generalCompileCaches; public ClassAnalysisCache getClassAnalysisCache() { return generalCaches.getClassAnalysisCache(); } public JarSnapshotCache getJarSnapshotCache() { return generalCaches.getJarSnapshotCache(); } public LocalJarClasspathSnapshotStore getLocalJarClasspathSnapshotStore() { return new LocalJarClasspathSnapshotStore(repository, javaCompile); } public LocalClassSetAnalysisStore getLocalClassSetAnalysisStore() { return new LocalClassSetAnalysisStore(repository, javaCompile); } }; IncrementalCompilerFactory factory = new IncrementalCompilerFactory( getFileOperations(), getCachingFileHasher(), getPath(), createCompiler(spec), source, compileCaches, (IncrementalTaskInputsInternal) inputs); Compiler<JavaCompileSpec> compiler = factory.createCompiler(); performCompilation(spec, compiler); }
@Override public WorkResult execute(JavaCompileSpec spec) { WorkResult out = delegate.execute(spec); if (!(out instanceof RecompilationNotNecessary)) { //if recompilation was skipped //there's no point in updating because we have exactly the same output classes) updater.updateAnalysis(spec); } writer.storeJarSnapshots(spec.getClasspath()); return out; }
public void updateAnalysis(JavaCompileSpec spec) { Timer clock = Timers.startTimer(); FileTree tree = fileOperations.fileTree(spec.getDestinationDir()); ClassFilesAnalyzer analyzer = new ClassFilesAnalyzer(this.analyzer); tree.visit(analyzer); ClassSetAnalysisData data = analyzer.getAnalysis(); stash.put(data); LOG.info("Class dependency analysis for incremental compilation took {}.", clock.getElapsed()); }
@TaskAction protected void compile(IncrementalTaskInputs inputs) { if (!compileOptions.isIncremental()) { compile(); return; } SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation"); DefaultJavaCompileSpec spec = createSpec(); final CacheRepository repository1 = getCacheRepository(); final JavaCompile javaCompile1 = this; final GeneralCompileCaches generalCaches1 = getGeneralCompileCaches(); CompileCaches compileCaches = new CompileCaches() { private final CacheRepository repository = repository1; private final JavaCompile javaCompile = javaCompile1; private final GeneralCompileCaches generalCaches = generalCaches1; public ClassAnalysisCache getClassAnalysisCache() { return generalCaches.getClassAnalysisCache(); } public JarSnapshotCache getJarSnapshotCache() { return generalCaches.getJarSnapshotCache(); } public LocalJarClasspathSnapshotStore getLocalJarClasspathSnapshotStore() { return new LocalJarClasspathSnapshotStore(repository, javaCompile); } public LocalClassSetAnalysisStore getLocalClassSetAnalysisStore() { return new LocalClassSetAnalysisStore(repository, javaCompile); } }; IncrementalCompilerFactory factory = new IncrementalCompilerFactory( (FileOperations) getProject(), getPath(), createCompiler(spec), source, compileCaches, (IncrementalTaskInputsInternal) inputs); Compiler<JavaCompileSpec> compiler = factory.createCompiler(); performCompilation(spec, compiler); }
public WorkResult execute(JavaCompileSpec spec) { WorkResult out = delegate.execute(spec); if (!(out instanceof RecompilationNotNecessary)) { //if recompilation was skipped //there's no point in updating because we have exactly the same output classes) updater.updateAnalysis(spec); } writer.storeJarSnapshots(spec.getClasspath()); return out; }
public void updateAnalysis(JavaCompileSpec spec) { Clock clock = new Clock(); FileTree tree = fileOperations.fileTree(spec.getDestinationDir()); ClassFilesAnalyzer analyzer = new ClassFilesAnalyzer(this.analyzer); tree.visit(analyzer); ClassSetAnalysisData data = analyzer.getAnalysis(); stash.put(data); LOG.info("Class dependency analysis for incremental compilation took {}.", clock.getTime()); }
public WorkResult execute(JavaCompileSpec spec) { ForkOptions forkOptions = spec.getCompileOptions().getForkOptions(); DaemonForkOptions daemonForkOptions = new DaemonForkOptions( forkOptions.getMemoryInitialSize(), forkOptions.getMemoryMaximumSize(), forkOptions.getJvmArgs(), Collections.<File>emptyList(), Collections.singleton("com.sun.tools.javac")); CompilerDaemon daemon = compilerDaemonManager.getDaemon(project.getRootProject().getProjectDir(), daemonForkOptions); CompileResult result = daemon.execute(delegate, spec); if (result.isSuccess()) { return result; } throw UncheckedException.throwAsUncheckedException(result.getException()); }
public WorkResult execute(JavaCompileSpec spec) { LOGGER.info("Compiling with JDK Java compiler API."); JavaCompiler.CompilationTask task = createCompileTask(spec); boolean success = task.call(); if (!success) { throw new CompilationFailedException(); } return new SimpleWorkResult(true); }
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); }
@SuppressWarnings("unchecked") @Override public <T extends CompileSpec> Compiler<T> newCompiler(Class<T> spec) { if (JavaCompileSpec.class.isAssignableFrom(spec)) { return (Compiler<T>) new NormalizingJavaCompiler(new ErrorProneCompiler(configuration)); } throw new IllegalArgumentException( String.format("Don't know how to compile using spec of type %s.", spec.getSimpleName())); }
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) { this.scalaCompiler = scalaCompiler; this.javaCompiler = javaCompiler; }
private CleaningJavaCompiler createCompiler(JavaCompileSpec spec) { Compiler<JavaCompileSpec> javaCompiler = CompilerUtil.castCompiler(((JavaToolChainInternal) getToolChain()).select(getPlatform()).newCompiler(spec.getClass())); return new CleaningJavaCompiler(javaCompiler, getAntBuilderFactory(), getOutputs()); }
private void performCompilation(JavaCompileSpec spec, Compiler<JavaCompileSpec> compiler) { WorkResult result = compiler.execute(spec); setDidWork(result.getDidWork()); }
public IncrementalCompilationFinalizer(Compiler<JavaCompileSpec> delegate, JarClasspathSnapshotWriter writer, ClassSetAnalysisUpdater updater) { this.delegate = delegate; this.writer = writer; this.updater = updater; }
public Compiler<JavaCompileSpec> createCompiler() { return incrementalSupport.prepareCompiler(inputs); }
public Compiler<JavaCompileSpec> prepareCompiler(IncrementalTaskInputs inputs) { Compiler<JavaCompileSpec> compiler = getCompiler(inputs, sourceDirs); return new IncrementalCompilationFinalizer(compiler, jarClasspathSnapshotMaker, classSetAnalysisUpdater); }
private CleaningJavaCompiler createCompiler(JavaCompileSpec spec) { // TODO:DAZ Supply the target platform to the task, using the compatibility flags as overrides // Or maybe split the legacy compile task from the new one Compiler<JavaCompileSpec> javaCompiler = ((JavaToolChainInternal) getToolChain()).select(getPlatform()).newCompiler(spec); return new CleaningJavaCompiler(javaCompiler, getAntBuilderFactory(), getOutputs()); }
public Compiler<JavaCompileSpec> prepareCompiler(final IncrementalTaskInputs inputs) { final Compiler<JavaCompileSpec> compiler = getCompiler(inputs, sourceDirs); return new IncrementalCompilationFinalizer(compiler, jarClasspathSnapshotMaker, classSetAnalysisUpdater); }
public DaemonJavaCompiler(ProjectInternal project, Compiler<JavaCompileSpec> delegate, CompilerDaemonManager compilerDaemonManager) { this.project = project; this.delegate = delegate; this.compilerDaemonManager = compilerDaemonManager; }
public SelectiveJavaCompiler(Compiler<JavaCompileSpec> compiler, FileTree destinationDir) { this.compiler = compiler; this.destinationDir = destinationDir; }
public WorkResult execute(JavaCompileSpec spec) { return compiler.execute(spec); }