org.gradle.api.internal.tasks.compile.JavaCompileSpec Java Examples

The following examples show how to use org.gradle.api.internal.tasks.compile.JavaCompileSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaCompile.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@TaskAction
protected void compile(IncrementalTaskInputs inputs) {
    if (!compileOptions.isIncremental()) {
        compile();
        return;
    }

    DefaultJavaCompileSpec spec = createSpec();
    Compiler<JavaCompileSpec> incrementalCompiler = getIncrementalCompilerFactory().makeIncremental(
            createCompiler(spec),
            getPath(),
            inputs,
            getSource()
    );
    performCompilation(spec, incrementalCompiler);
}
 
Example #2
Source File: IncrementalCompilationInitializer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #3
Source File: IncrementalCompilerDecorator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #4
Source File: SelectiveCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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());
    }
}
 
Example #5
Source File: SelectiveCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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());
    }
}
 
Example #6
Source File: IncrementalCompilerDecorator.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #7
Source File: IncrementalCompilationInitializer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example #8
Source File: Jdk6JavaCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #9
Source File: JavaCompile.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #10
Source File: Jdk6JavaCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #11
Source File: JavaCompile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: IncrementalCompilationFinalizer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #13
Source File: ClassSetAnalysisUpdater.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #14
Source File: DaemonJavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #15
Source File: Jdk6JavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #16
Source File: Jdk6JavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}
 
Example #17
Source File: ErrorProneToolChain.java    From gradle-errorprone-plugin-v0.0.x with Apache License 2.0 5 votes vote down vote up
@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()));
}
 
Example #18
Source File: DaemonJavaCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #19
Source File: IncrementalCompilationFinalizer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #20
Source File: ClassSetAnalysisUpdater.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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());
}
 
Example #21
Source File: IncrementalCompilerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Compiler<JavaCompileSpec> createCompiler() {
    return incrementalSupport.prepareCompiler(inputs);
}
 
Example #22
Source File: DefaultScalaJavaJointCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) {
    this.scalaCompiler = scalaCompiler;
    this.javaCompiler = javaCompiler;
}
 
Example #23
Source File: JavaCompile.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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());
}
 
Example #24
Source File: JavaCompile.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void performCompilation(JavaCompileSpec spec, Compiler<JavaCompileSpec> compiler) {
    WorkResult result = compiler.execute(spec);
    setDidWork(result.getDidWork());
}
 
Example #25
Source File: SelectiveJavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult execute(JavaCompileSpec spec) {
    return compiler.execute(spec);
}
 
Example #26
Source File: SelectiveJavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SelectiveJavaCompiler(Compiler<JavaCompileSpec> compiler, FileTree destinationDir) {
    this.compiler = compiler;
    this.destinationDir = destinationDir;
}
 
Example #27
Source File: IncrementalCompilationFinalizer.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public IncrementalCompilationFinalizer(Compiler<JavaCompileSpec> delegate, JarClasspathSnapshotWriter writer,
                                       ClassSetAnalysisUpdater updater) {
    this.delegate = delegate;
    this.writer = writer;
    this.updater = updater;
}
 
Example #28
Source File: DaemonJavaCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DaemonJavaCompiler(ProjectInternal project, Compiler<JavaCompileSpec> delegate, CompilerDaemonManager compilerDaemonManager) {
    this.project = project;
    this.delegate = delegate;
    this.compilerDaemonManager = compilerDaemonManager;
}
 
Example #29
Source File: DefaultScalaJavaJointCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) {
    this.scalaCompiler = scalaCompiler;
    this.javaCompiler = javaCompiler;
}
 
Example #30
Source File: IncrementalCompilerDecorator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Compiler<JavaCompileSpec> prepareCompiler(final IncrementalTaskInputs inputs) {
    final Compiler<JavaCompileSpec> compiler = getCompiler(inputs, sourceDirs);
    return new IncrementalCompilationFinalizer(compiler, jarClasspathSnapshotMaker, classSetAnalysisUpdater);
}