Java 类org.gradle.api.internal.tasks.compile.JavaCompileSpec 实例源码

项目:Reer    文件:SelectiveCompiler.java   
@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());
    }
}
项目:Reer    文件:IncrementalCompilerDecorator.java   
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);
}
项目:Reer    文件:IncrementalCompilationInitializer.java   
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);
}
项目:Pushjet-Android    文件:SelectiveCompiler.java   
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());
    }
}
项目:Pushjet-Android    文件:IncrementalCompilerDecorator.java   
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);
}
项目:Pushjet-Android    文件:IncrementalCompilationInitializer.java   
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);
}
项目:Reer    文件:JavaCompile.java   
@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);
}
项目:Reer    文件:IncrementalCompilationFinalizer.java   
@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;
}
项目:Reer    文件:ClassSetAnalysisUpdater.java   
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());
}
项目:Pushjet-Android    文件:JavaCompile.java   
@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);
}
项目:Pushjet-Android    文件:IncrementalCompilationFinalizer.java   
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;
}
项目:Pushjet-Android    文件:ClassSetAnalysisUpdater.java   
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());
}
项目:Pushjet-Android    文件:DaemonJavaCompiler.java   
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());
}
项目:Pushjet-Android    文件:Jdk6JavaCompiler.java   
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);
}
项目:Pushjet-Android    文件:Jdk6JavaCompiler.java   
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);
}
项目:gradle-errorprone-plugin    文件:ErrorProneToolChain.java   
@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()));
}
项目:Reer    文件:DefaultScalaJavaJointCompiler.java   
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) {
    this.scalaCompiler = scalaCompiler;
    this.javaCompiler = javaCompiler;
}
项目:Reer    文件:JavaCompile.java   
private CleaningJavaCompiler createCompiler(JavaCompileSpec spec) {
    Compiler<JavaCompileSpec> javaCompiler = CompilerUtil.castCompiler(((JavaToolChainInternal) getToolChain()).select(getPlatform()).newCompiler(spec.getClass()));
    return new CleaningJavaCompiler(javaCompiler, getAntBuilderFactory(), getOutputs());
}
项目:Reer    文件:JavaCompile.java   
private void performCompilation(JavaCompileSpec spec, Compiler<JavaCompileSpec> compiler) {
    WorkResult result = compiler.execute(spec);
    setDidWork(result.getDidWork());
}
项目:Reer    文件:IncrementalCompilationFinalizer.java   
public IncrementalCompilationFinalizer(Compiler<JavaCompileSpec> delegate, JarClasspathSnapshotWriter writer,
                                       ClassSetAnalysisUpdater updater) {
    this.delegate = delegate;
    this.writer = writer;
    this.updater = updater;
}
项目:Reer    文件:IncrementalCompilerFactory.java   
public Compiler<JavaCompileSpec> createCompiler() {
    return incrementalSupport.prepareCompiler(inputs);
}
项目:Reer    文件:IncrementalCompilerDecorator.java   
public Compiler<JavaCompileSpec> prepareCompiler(IncrementalTaskInputs inputs) {
    Compiler<JavaCompileSpec> compiler = getCompiler(inputs, sourceDirs);
    return new IncrementalCompilationFinalizer(compiler, jarClasspathSnapshotMaker, classSetAnalysisUpdater);
}
项目:Pushjet-Android    文件:DefaultScalaJavaJointCompiler.java   
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) {
    this.scalaCompiler = scalaCompiler;
    this.javaCompiler = javaCompiler;
}
项目:Pushjet-Android    文件:JavaCompile.java   
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());
}
项目:Pushjet-Android    文件:JavaCompile.java   
private void performCompilation(JavaCompileSpec spec, Compiler<JavaCompileSpec> compiler) {
    WorkResult result = compiler.execute(spec);
    setDidWork(result.getDidWork());
}
项目:Pushjet-Android    文件:IncrementalCompilationFinalizer.java   
public IncrementalCompilationFinalizer(Compiler<JavaCompileSpec> delegate, JarClasspathSnapshotWriter writer,
                                       ClassSetAnalysisUpdater updater) {
    this.delegate = delegate;
    this.writer = writer;
    this.updater = updater;
}
项目:Pushjet-Android    文件:IncrementalCompilerFactory.java   
public Compiler<JavaCompileSpec> createCompiler() {
    return incrementalSupport.prepareCompiler(inputs);
}
项目:Pushjet-Android    文件:IncrementalCompilerDecorator.java   
public Compiler<JavaCompileSpec> prepareCompiler(final IncrementalTaskInputs inputs) {
    final Compiler<JavaCompileSpec> compiler = getCompiler(inputs, sourceDirs);
    return new IncrementalCompilationFinalizer(compiler, jarClasspathSnapshotMaker, classSetAnalysisUpdater);
}
项目:Pushjet-Android    文件:DefaultScalaJavaJointCompiler.java   
public DefaultScalaJavaJointCompiler(Compiler<ScalaCompileSpec> scalaCompiler, Compiler<JavaCompileSpec> javaCompiler) {
    this.scalaCompiler = scalaCompiler;
    this.javaCompiler = javaCompiler;
}
项目:Pushjet-Android    文件:DaemonJavaCompiler.java   
public DaemonJavaCompiler(ProjectInternal project, Compiler<JavaCompileSpec> delegate, CompilerDaemonManager compilerDaemonManager) {
    this.project = project;
    this.delegate = delegate;
    this.compilerDaemonManager = compilerDaemonManager;
}
项目:Pushjet-Android    文件:SelectiveJavaCompiler.java   
public SelectiveJavaCompiler(Compiler<JavaCompileSpec> compiler, FileTree destinationDir) {
    this.compiler = compiler;
    this.destinationDir = destinationDir;
}
项目:Pushjet-Android    文件:SelectiveJavaCompiler.java   
public WorkResult execute(JavaCompileSpec spec) {
    return compiler.execute(spec);
}