org.gradle.api.tasks.incremental.IncrementalTaskInputs Java Examples

The following examples show how to use org.gradle.api.tasks.incremental.IncrementalTaskInputs. 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: CreateOrmLiteConfigTask.java    From ormlite-android-gradle-plugin with Apache License 2.0 6 votes vote down vote up
@TaskAction
protected void exec(IncrementalTaskInputs inputs) throws IOException, SQLException, InterruptedException {
    if (!inputs.isIncremental()) {
        getProject().delete(getOutputFile());
    }

    final Set<String> lastFilesInState = loadFileNames();
    final Set<String> newFilesInState = new HashSet<>(lastFilesInState);

    if (!hasNewState(inputs, lastFilesInState, newFilesInState)) {
        return;
    }
    saveFileNames(newFilesInState);

    final CreateOrmLiteConfigAction createOrmLiteConfigAction
            = new CreateOrmLiteConfigAction(configFileName,
                                            getProject().file(sourceDir),
                                            classpath.getAsPath(), getLogger());

    createOrmLiteConfigAction.execute();

    this.setDidWork(true);
}
 
Example #3
Source File: AbstractNativeCompileTask.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
public void compile(IncrementalTaskInputs inputs) {

    NativeCompileSpec spec = createCompileSpec();
    spec.setTargetPlatform(targetPlatform);
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getObjectFileDir());
    spec.include(getIncludes());
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs());
    spec.setPositionIndependentCode(isPositionIndependentCode());
    spec.setIncrementalCompile(inputs.isIncremental());

    PlatformToolProvider platformToolProvider = toolChain.select(targetPlatform);
    WorkResult result = getIncrementalCompilerBuilder().createIncrementalCompiler(this, platformToolProvider.newCompiler(spec), toolChain).execute(spec);

    setDidWork(result.getDidWork());
}
 
Example #4
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 #5
Source File: RecompilationSpecProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RecompilationSpec provideRecompilationSpec(IncrementalTaskInputs inputs, PreviousCompilation previousCompilation, JarClasspathSnapshot jarClasspathSnapshot) {
    //creating an action that will be executed against all changes
    RecompilationSpec spec = new RecompilationSpec();
    JavaChangeProcessor javaChangeProcessor = new JavaChangeProcessor(previousCompilation, sourceToNameConverter);
    JarChangeProcessor jarChangeProcessor = new JarChangeProcessor(fileOperations, jarClasspathSnapshot, previousCompilation);
    InputChangeAction action = new InputChangeAction(spec, javaChangeProcessor, jarChangeProcessor);

    //go!
    inputs.outOfDate(action);
    if (action.spec.getFullRebuildCause() != null) {
        //short circuit in case we already know that that full rebuild is needed
        return action.spec;
    }
    inputs.removed(action);
    return action.spec;
}
 
Example #6
Source File: AwbAndroidJavaCompile.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
protected void compile(IncrementalTaskInputs inputs) {
    getLogger().info(
            "Compiling with source level {} and target level {}.",
            getSourceCompatibility(),
            getTargetCompatibility());
    if (isPostN()) {
        if (!JavaVersion.current().isJava8Compatible()) {
            throw new RuntimeException("compileSdkVersion '" + compileSdkVersion + "' requires "
                    + "JDK 1.8 or later to compile.");
        }
    }

    if (awbBundle.isDataBindEnabled() && !analyticsed) {
        processAnalytics();
        analyticsed = true;
    }

    // Create directory for output of annotation processor.
    FileUtils.mkdirs(annotationProcessorOutputFolder);

    mInstantRunBuildContext.startRecording(InstantRunBuildContext.TaskType.JAVAC);
    compile();
    mInstantRunBuildContext.stopRecording(InstantRunBuildContext.TaskType.JAVAC);
}
 
Example #7
Source File: DesugarTask.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Gradle's entry-point into this task. Determines whether or not it's possible to do this task
 * incrementally and calls either doIncrementalTaskAction() if an incremental build is possible,
 * and doFullTaskAction() if not.
 */
@TaskAction
void taskAction(IncrementalTaskInputs inputs) throws Exception {
    initDesugarJar(getProject().getExtensions().findByType(JFXMobileExtension.class).getAndroidExtension().getBuildCache());

    if (Files.notExists(inputDir.toPath())) {
        PathUtils.deleteIfExists(outputDir.toPath());
    } else {
        processSingle(inputDir.toPath(), outputDir.toPath(), Collections.emptySet());

    }
    waitableExecutor.waitForTasksWithQuickFail(true);

    processNonCachedOnes(getClasspath());
    waitableExecutor.waitForTasksWithQuickFail(true);
}
 
Example #8
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 #9
Source File: RecompilationSpecProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public RecompilationSpec provideRecompilationSpec(IncrementalTaskInputs inputs, PreviousCompilation previousCompilation, JarClasspathSnapshot jarClasspathSnapshot) {
    //creating an action that will be executed against all changes
    RecompilationSpec spec = new RecompilationSpec();
    JavaChangeProcessor javaChangeProcessor = new JavaChangeProcessor(previousCompilation, sourceToNameConverter);
    JarChangeProcessor jarChangeProcessor = new JarChangeProcessor(fileOperations, jarClasspathSnapshot, previousCompilation);
    InputChangeAction action = new InputChangeAction(spec, javaChangeProcessor, jarChangeProcessor);

    //go!
    inputs.outOfDate(action);
    if (action.spec.getFullRebuildCause() != null) {
        //short circuit in case we already know that that full rebuild is needed
        return action.spec;
    }
    inputs.removed(action);
    return action.spec;
}
 
Example #10
Source File: AbstractNativeCompileTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
public void compile(IncrementalTaskInputs inputs) {

    NativeCompileSpec spec = createCompileSpec();
    spec.setTargetPlatform(targetPlatform);
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getObjectFileDir());
    spec.include(getIncludes());
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs());
    spec.setPositionIndependentCode(isPositionIndependentCode());
    spec.setIncrementalCompile(inputs.isIncremental());

    PlatformToolProvider platformToolProvider = toolChain.select(targetPlatform);
    WorkResult result = getIncrementalCompilerBuilder().createIncrementalCompiler(this, platformToolProvider.newCompiler(spec), toolChain).execute(spec);

    setDidWork(result.getDidWork());
}
 
Example #11
Source File: DefaultTaskArtifactStateRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public IncrementalTaskInputs getInputChanges() {
    assert !upToDate : "Should not be here if the task is up-to-date";

    if (canPerformIncrementalBuild()) {
        return instantiator.newInstance(ChangesOnlyIncrementalTaskInputs.class, getStates().getInputFilesChanges());
    }
    return instantiator.newInstance(RebuildIncrementalTaskInputs.class, task);
}
 
Example #12
Source File: AnnotationProcessingTaskFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachTaskAction(final Method method, TaskClassInfo taskClassInfo, Collection<String> processedMethods) {
    if (method.getAnnotation(TaskAction.class) == null) {
        return;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new GradleException(String.format("Cannot use @TaskAction annotation on static method %s.%s().",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }
    final Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length > 1) {
        throw new GradleException(String.format(
                "Cannot use @TaskAction annotation on method %s.%s() as this method takes multiple parameters.",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }

    if (parameterTypes.length == 1) {
        if (!parameterTypes[0].equals(IncrementalTaskInputs.class)) {
            throw new GradleException(String.format(
                    "Cannot use @TaskAction annotation on method %s.%s() because %s is not a valid parameter to an action method.",
                    method.getDeclaringClass().getSimpleName(), method.getName(), parameterTypes[0]));
        }
        if (taskClassInfo.incremental) {
            throw new GradleException(String.format("Cannot have multiple @TaskAction methods accepting an %s parameter.", IncrementalTaskInputs.class.getSimpleName()));
        }
        taskClassInfo.incremental = true;
    }
    if (processedMethods.contains(method.getName())) {
        return;
    }
    taskClassInfo.taskActions.add(createActionFactory(method, parameterTypes));
    processedMethods.add(method.getName());
}
 
Example #13
Source File: WindowsResourceCompile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
public void compile(IncrementalTaskInputs inputs) {
    NativeCompileSpec spec = new DefaultWindowsResourceCompileSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getOutputDir());
    spec.include(getIncludes());
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs());
    spec.setIncrementalCompile(inputs.isIncremental());

    PlatformToolProvider platformToolProvider = toolChain.select(targetPlatform);
    WorkResult result = getIncrementalCompilerBuilder().createIncrementalCompiler(this, platformToolProvider.newCompiler(spec), toolChain).execute(spec);
    setDidWork(result.getDidWork());
}
 
Example #14
Source File: SelectiveCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SelectiveCompiler(IncrementalTaskInputs inputs, PreviousCompilation previousCompilation, CleaningJavaCompiler cleaningCompiler,
                         RecompilationSpecProvider recompilationSpecProvider, IncrementalCompilationInitializer compilationInitializer, JarClasspathSnapshotProvider jarClasspathSnapshotProvider) {
    this.inputs = inputs;
    this.previousCompilation = previousCompilation;
    this.cleaningCompiler = cleaningCompiler;
    this.recompilationSpecProvider = recompilationSpecProvider;
    this.incrementalCompilationInitilizer = compilationInitializer;
    this.jarClasspathSnapshotProvider = jarClasspathSnapshotProvider;
}
 
Example #15
Source File: DefaultTaskArtifactStateRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public IncrementalTaskInputs getInputChanges() {
    assert !upToDate : "Should not be here if the task is up-to-date";

    if (canPerformIncrementalBuild()) {
        return instantiator.newInstance(ChangesOnlyIncrementalTaskInputs.class, getStates().getInputFilesChanges(), getStates().getInputFilesSnapshot());
    }
    return instantiator.newInstance(RebuildIncrementalTaskInputs.class, task, getStates().getInputFilesSnapshot());
}
 
Example #16
Source File: SelectiveCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SelectiveCompiler(IncrementalTaskInputs inputs, PreviousCompilation previousCompilation, CleaningJavaCompiler cleaningCompiler,
                         RecompilationSpecProvider recompilationSpecProvider, IncrementalCompilationInitializer compilationInitializer, JarClasspathSnapshotProvider jarClasspathSnapshotProvider) {
    this.inputs = inputs;
    this.previousCompilation = previousCompilation;
    this.cleaningCompiler = cleaningCompiler;
    this.recompilationSpecProvider = recompilationSpecProvider;
    this.incrementalCompilationInitilizer = compilationInitializer;
    this.jarClasspathSnapshotProvider = jarClasspathSnapshotProvider;
}
 
Example #17
Source File: AnnotationProcessingTaskFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachTaskAction(final Method method, TaskClassInfo taskClassInfo, Collection<String> processedMethods) {
    if (method.getAnnotation(TaskAction.class) == null) {
        return;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new GradleException(String.format("Cannot use @TaskAction annotation on static method %s.%s().",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }
    final Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length > 1) {
        throw new GradleException(String.format(
                "Cannot use @TaskAction annotation on method %s.%s() as this method takes multiple parameters.",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }

    if (parameterTypes.length == 1) {
        if (!parameterTypes[0].equals(IncrementalTaskInputs.class)) {
            throw new GradleException(String.format(
                    "Cannot use @TaskAction annotation on method %s.%s() because %s is not a valid parameter to an action method.",
                    method.getDeclaringClass().getSimpleName(), method.getName(), parameterTypes[0]));
        }
        if (taskClassInfo.incremental) {
            throw new GradleException(String.format("Cannot have multiple @TaskAction methods accepting an %s parameter.", IncrementalTaskInputs.class.getSimpleName()));
        }
        taskClassInfo.incremental = true;
    }
    if (processedMethods.contains(method.getName())) {
        return;
    }
    taskClassInfo.taskActions.add(createActionFactory(method, parameterTypes));
    processedMethods.add(method.getName());
}
 
Example #18
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 #19
Source File: AnnotationProcessingTaskFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachTaskAction(final Method method, TaskClassInfo taskClassInfo, Collection<String> processedMethods) {
    if (method.getAnnotation(TaskAction.class) == null) {
        return;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new GradleException(String.format("Cannot use @TaskAction annotation on static method %s.%s().",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }
    final Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length > 1) {
        throw new GradleException(String.format(
                "Cannot use @TaskAction annotation on method %s.%s() as this method takes multiple parameters.",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }

    if (parameterTypes.length == 1) {
        if (!parameterTypes[0].equals(IncrementalTaskInputs.class)) {
            throw new GradleException(String.format(
                    "Cannot use @TaskAction annotation on method %s.%s() because %s is not a valid parameter to an action method.",
                    method.getDeclaringClass().getSimpleName(), method.getName(), parameterTypes[0]));
        }
        if (taskClassInfo.incremental) {
            throw new GradleException(String.format("Cannot have multiple @TaskAction methods accepting an %s parameter.", IncrementalTaskInputs.class.getSimpleName()));
        }
        taskClassInfo.incremental = true;
    }
    if (processedMethods.contains(method.getName())) {
        return;
    }
    taskClassInfo.taskActions.add(createActionFactory(method, parameterTypes));
    processedMethods.add(method.getName());
}
 
Example #20
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 #21
Source File: WindowsResourceCompile.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
public void compile(IncrementalTaskInputs inputs) {
    NativeCompileSpec spec = new DefaultWindowsResourceCompileSpec();
    spec.setTempDir(getTemporaryDir());
    spec.setObjectFileDir(getOutputDir());
    spec.include(getIncludes());
    spec.source(getSource());
    spec.setMacros(getMacros());
    spec.args(getCompilerArgs());
    spec.setIncrementalCompile(inputs.isIncremental());

    PlatformToolProvider platformToolProvider = toolChain.select(targetPlatform);
    WorkResult result = getIncrementalCompilerBuilder().createIncrementalCompiler(this, platformToolProvider.newCompiler(spec), toolChain).execute(spec);
    setDidWork(result.getDidWork());
}
 
Example #22
Source File: SelectiveCompilation.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SelectiveCompilation(IncrementalTaskInputs inputs, FileTree source, FileCollection compileClasspath, final File compileDestination,
                            final ClassDependencyInfoSerializer dependencyInfoSerializer, final JarSnapshotCache jarSnapshotCache, final SelectiveJavaCompiler compiler,
                            Iterable<File> sourceDirs, final FileOperations operations) {
    this.operations = operations;
    this.jarSnapshotFeeder = new JarSnapshotFeeder(jarSnapshotCache, new JarSnapshotter(new DefaultHasher()));
    this.compiler = compiler;

    Clock clock = new Clock();
    final InputOutputMapper mapper = new InputOutputMapper(sourceDirs, compileDestination);

    //load dependency info
    final ClassDependencyInfo dependencyInfo = dependencyInfoSerializer.readInfo();

    //including only source java classes that were changed
    final PatternSet changedSourceOnly = new PatternSet();
    InputFileDetailsAction action = new InputFileDetailsAction(mapper, compiler, changedSourceOnly, dependencyInfo);
    inputs.outOfDate(action);
    inputs.removed(action);
    if (fullRebuildNeeded != null) {
        LOG.lifecycle("Stale classes detection completed in {}. Rebuild needed: {}.", clock.getTime(), fullRebuildNeeded);
        this.classpath = compileClasspath;
        this.source = source;
        return;
    }

    compiler.deleteStaleClasses();
    Set<File> filesToCompile = source.matching(changedSourceOnly).getFiles();
    if (filesToCompile.isEmpty()) {
        this.compilationNeeded = false;
        this.classpath = compileClasspath;
        this.source = source;
    } else {
        this.classpath = compileClasspath.plus(new SimpleFileCollection(compileDestination));
        this.source = source.matching(changedSourceOnly);
    }
    LOG.lifecycle("Stale classes detection completed in {}. Compile include patterns: {}.", clock.getTime(), changedSourceOnly.getIncludes());
}
 
Example #23
Source File: Compile.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean maybeCompileIncrementally(IncrementalTaskInputs inputs) {
    if (!compileOptions.isIncremental()) {
        return false;
    }
    //hack
    List<File> sourceDirs = getSourceDirs();
    if (sourceDirs.isEmpty()) {
        LOG.lifecycle("{} cannot run incrementally because Gradle cannot infer the source directories.", getPath());
        return false;
    }
    if (!inputs.isIncremental()) {
        LOG.lifecycle("{} is not incremental (e.g. outputs have changed, no previous execution, etc). Using regular compile.", getPath());
        return false;
    }
    ClassDependencyInfoSerializer dependencyInfoSerializer = getDependencyInfoSerializer();
    if (!dependencyInfoSerializer.isInfoAvailable()) {
        //TODO SF let's unit test a scenario when after regular compilation incremental compilation is scheduled
        LOG.lifecycle("{} is not incremental because there is no class dependency data left from previous incremental build.", getPath());
        return false;
    }

    SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation");

    SelectiveJavaCompiler compiler = new SelectiveJavaCompiler(javaCompiler, getProject().fileTree(getDestinationDir()));
    SelectiveCompilation selectiveCompilation = new SelectiveCompilation(inputs, getSource(), getClasspath(), getDestinationDir(),
            dependencyInfoSerializer, getJarSnapshotCache(), compiler, sourceDirs, (FileOperations) getProject());

    if (!selectiveCompilation.getCompilationNeeded()) {
        LOG.lifecycle("{} does not require recompilation. Skipping the compiler.", getPath());
        return true;
    }

    Clock clock = new Clock();
    performCompilation(selectiveCompilation.getSource(), selectiveCompilation.getClasspath(), selectiveCompilation.getFullRebuildRequired()? cleaningCompiler : compiler);
    LOG.lifecycle("{} - incremental compilation took {}", getPath(), clock.getTime());

    return true;
}
 
Example #24
Source File: Compile.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
protected void compile(IncrementalTaskInputs inputs) {
    if (!maybeCompileIncrementally(inputs)) {
        compile();
    }
    incrementalCompilation.compilationComplete(compileOptions,
            new ClassDependencyInfoExtractor(getDestinationDir()),
            getDependencyInfoSerializer(), Collections.<JarArchive>emptyList());
}
 
Example #25
Source File: DefaultTaskArtifactStateRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public IncrementalTaskInputs getInputChanges() {
    assert !upToDate : "Should not be here if the task is up-to-date";

    if (canPerformIncrementalBuild()) {
        return instantiator.newInstance(ChangesOnlyIncrementalTaskInputs.class, getStates().getInputFilesChanges());
    }
    return instantiator.newInstance(RebuildIncrementalTaskInputs.class, task);
}
 
Example #26
Source File: Compile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@TaskAction
protected void compile(IncrementalTaskInputs inputs) {
    if (!maybeCompileIncrementally(inputs)) {
        compile();
    }
    incrementalCompilation.compilationComplete(compileOptions,
            new ClassDependencyInfoExtractor(getDestinationDir()),
            getDependencyInfoSerializer(), Collections.<JarArchive>emptyList());
}
 
Example #27
Source File: Compile.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean maybeCompileIncrementally(IncrementalTaskInputs inputs) {
    if (!compileOptions.isIncremental()) {
        return false;
    }
    //hack
    List<File> sourceDirs = getSourceDirs();
    if (sourceDirs.isEmpty()) {
        LOG.lifecycle("{} cannot run incrementally because Gradle cannot infer the source directories.", getPath());
        return false;
    }
    if (!inputs.isIncremental()) {
        LOG.lifecycle("{} is not incremental (e.g. outputs have changed, no previous execution, etc). Using regular compile.", getPath());
        return false;
    }
    ClassDependencyInfoSerializer dependencyInfoSerializer = getDependencyInfoSerializer();
    if (!dependencyInfoSerializer.isInfoAvailable()) {
        //TODO SF let's unit test a scenario when after regular compilation incremental compilation is scheduled
        LOG.lifecycle("{} is not incremental because there is no class dependency data left from previous incremental build.", getPath());
        return false;
    }

    SingleMessageLogger.incubatingFeatureUsed("Incremental java compilation");

    SelectiveJavaCompiler compiler = new SelectiveJavaCompiler(javaCompiler, getProject().fileTree(getDestinationDir()));
    SelectiveCompilation selectiveCompilation = new SelectiveCompilation(inputs, getSource(), getClasspath(), getDestinationDir(),
            dependencyInfoSerializer, getJarSnapshotCache(), compiler, sourceDirs, (FileOperations) getProject());

    if (!selectiveCompilation.getCompilationNeeded()) {
        LOG.lifecycle("{} does not require recompilation. Skipping the compiler.", getPath());
        return true;
    }

    Clock clock = new Clock();
    performCompilation(selectiveCompilation.getSource(), selectiveCompilation.getClasspath(), selectiveCompilation.getFullRebuildRequired()? cleaningCompiler : compiler);
    LOG.lifecycle("{} - incremental compilation took {}", getPath(), clock.getTime());

    return true;
}
 
Example #28
Source File: AnnotationProcessingTaskFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void attachTaskAction(final Method method, TaskClassInfo taskClassInfo, Collection<String> processedMethods) {
    if (method.getAnnotation(TaskAction.class) == null) {
        return;
    }
    if (Modifier.isStatic(method.getModifiers())) {
        throw new GradleException(String.format("Cannot use @TaskAction annotation on static method %s.%s().",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }
    final Class<?>[] parameterTypes = method.getParameterTypes();
    if (parameterTypes.length > 1) {
        throw new GradleException(String.format(
                "Cannot use @TaskAction annotation on method %s.%s() as this method takes multiple parameters.",
                method.getDeclaringClass().getSimpleName(), method.getName()));
    }

    if (parameterTypes.length == 1) {
        if (!parameterTypes[0].equals(IncrementalTaskInputs.class)) {
            throw new GradleException(String.format(
                    "Cannot use @TaskAction annotation on method %s.%s() because %s is not a valid parameter to an action method.",
                    method.getDeclaringClass().getSimpleName(), method.getName(), parameterTypes[0]));
        }
        if (taskClassInfo.incremental) {
            throw new GradleException(String.format("Cannot have multiple @TaskAction methods accepting an %s parameter.", IncrementalTaskInputs.class.getSimpleName()));
        }
        taskClassInfo.incremental = true;
    }
    if (processedMethods.contains(method.getName())) {
        return;
    }
    taskClassInfo.taskActions.add(createActionFactory(method, parameterTypes));
    processedMethods.add(method.getName());
}
 
Example #29
Source File: SelectiveCompilation.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public SelectiveCompilation(IncrementalTaskInputs inputs, FileTree source, FileCollection compileClasspath, final File compileDestination,
                            final ClassDependencyInfoSerializer dependencyInfoSerializer, final JarSnapshotCache jarSnapshotCache, final SelectiveJavaCompiler compiler,
                            Iterable<File> sourceDirs, final FileOperations operations) {
    this.operations = operations;
    this.jarSnapshotFeeder = new JarSnapshotFeeder(jarSnapshotCache, new JarSnapshotter(new DefaultHasher()));
    this.compiler = compiler;

    Clock clock = new Clock();
    final InputOutputMapper mapper = new InputOutputMapper(sourceDirs, compileDestination);

    //load dependency info
    final ClassDependencyInfo dependencyInfo = dependencyInfoSerializer.readInfo();

    //including only source java classes that were changed
    final PatternSet changedSourceOnly = new PatternSet();
    InputFileDetailsAction action = new InputFileDetailsAction(mapper, compiler, changedSourceOnly, dependencyInfo);
    inputs.outOfDate(action);
    inputs.removed(action);
    if (fullRebuildNeeded != null) {
        LOG.lifecycle("Stale classes detection completed in {}. Rebuild needed: {}.", clock.getTime(), fullRebuildNeeded);
        this.classpath = compileClasspath;
        this.source = source;
        return;
    }

    compiler.deleteStaleClasses();
    Set<File> filesToCompile = source.matching(changedSourceOnly).getFiles();
    if (filesToCompile.isEmpty()) {
        this.compilationNeeded = false;
        this.classpath = compileClasspath;
        this.source = source;
    } else {
        this.classpath = compileClasspath.plus(new SimpleFileCollection(compileDestination));
        this.source = source.matching(changedSourceOnly);
    }
    LOG.lifecycle("Stale classes detection completed in {}. Compile include patterns: {}.", clock.getTime(), changedSourceOnly.getIncludes());
}
 
Example #30
Source File: DefaultTaskArtifactStateRepository.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public IncrementalTaskInputs getInputChanges() {
    assert !upToDate : "Should not be here if the task is up-to-date";

    if (canPerformIncrementalBuild()) {
        return instantiator.newInstance(ChangesOnlyIncrementalTaskInputs.class, getStates().getInputFilesChanges(), getStates().getInputFilesSnapshot());
    }
    return instantiator.newInstance(RebuildIncrementalTaskInputs.class, task, getStates().getInputFilesSnapshot());
}