下面列出了怎么用org.gradle.api.tasks.incremental.IncrementalTaskInputs的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
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);
}
@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());
}
/**
* 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);
}
@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);
}
@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);
}
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;
}
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);
}
@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());
}
@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);
}
@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 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;
}
@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());
}
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());
}
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());
}
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());
}
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);
}
@TaskAction
protected void compile(IncrementalTaskInputs inputs) {
if (!maybeCompileIncrementally(inputs)) {
compile();
}
incrementalCompilation.compilationComplete(compileOptions,
new ClassDependencyInfoExtractor(getDestinationDir()),
getDependencyInfoSerializer(), Collections.<JarArchive>emptyList());
}
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;
}
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());
}
@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 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;
}
@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());
}
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());
}
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());
}
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());
}
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);
}
@TaskAction
protected void compile(IncrementalTaskInputs inputs) {
if (!maybeCompileIncrementally(inputs)) {
compile();
}
incrementalCompilation.compilationComplete(compileOptions,
new ClassDependencyInfoExtractor(getDestinationDir()),
getDependencyInfoSerializer(), Collections.<JarArchive>emptyList());
}
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;
}
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());
}