Skip to content

Instantly share code, notes, and snippets.

@lptr
Created August 29, 2024 08:59
Show Gist options
  • Select an option

  • Save lptr/7c0bf6805496bc8fd53a1c3d56845ea4 to your computer and use it in GitHub Desktop.

Select an option

Save lptr/7c0bf6805496bc8fd53a1c3d56845ea4 to your computer and use it in GitHub Desktop.
diff --git a/platforms/jvm/language-java/src/main/java/org/gradle/api/tasks/compile/JavaCompile.java b/platforms/jvm/language-java/src/main/java/org/gradle/api/tasks/compile/JavaCompile.java
index 2c3335c55e2..e7923b75bc0 100644
--- a/platforms/jvm/language-java/src/main/java/org/gradle/api/tasks/compile/JavaCompile.java
+++ b/platforms/jvm/language-java/src/main/java/org/gradle/api/tasks/compile/JavaCompile.java
@@ -19,6 +19,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import org.gradle.api.JavaVersion;
+import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.ProjectLayout;
@@ -44,15 +45,11 @@
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.CompileClasspath;
-import org.gradle.api.tasks.IgnoreEmptyDirectories;
import org.gradle.api.tasks.Input;
-import org.gradle.api.tasks.InputFiles;
-import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
-import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.WorkResult;
import org.gradle.internal.file.Deleter;
@@ -69,7 +66,6 @@
import org.gradle.language.base.internal.compile.Compiler;
import org.gradle.work.Incremental;
import org.gradle.work.InputChanges;
-import org.gradle.work.NormalizeLineEndings;
import javax.inject.Inject;
import java.io.File;
@@ -117,11 +113,8 @@ public JavaCompile() {
* {@inheritDoc}
*/
@Override
- @Internal("tracked via stableSources")
- @ToBeReplacedByLazyProperty
- public FileTree getSource() {
- return super.getSource();
- }
+ @PathSensitive(PathSensitivity.RELATIVE)
+ public abstract ConfigurableFileTree getSource();
/**
* Configures the java compiler to be used to compile the Java source.
@@ -159,7 +152,7 @@ private void performIncrementalCompilation(InputChanges inputs, DefaultJavaCompi
spec.getCompileOptions().setPreviousCompilationDataFile(getPreviousCompilationData());
Compiler<JavaCompileSpec> compiler = createCompiler();
- compiler = makeIncremental(inputs, (CleaningJavaCompiler<JavaCompileSpec>) compiler, getStableSources());
+ compiler = makeIncremental(inputs, (CleaningJavaCompiler<JavaCompileSpec>) compiler, getSource());
performCompilation(spec, compiler);
}
@@ -178,7 +171,7 @@ private JavaRecompilationSpecProvider createRecompilationSpec(InputChanges input
getServices().get(FileOperations.class),
sources,
inputs.isIncremental(),
- () -> inputs.getFileChanges(getStableSources()).iterator()
+ () -> inputs.getFileChanges(getSource()).iterator()
);
}
@@ -188,7 +181,7 @@ private boolean isUsingCliCompiler(DefaultJavaCompileSpec spec) {
private void performFullCompilation(DefaultJavaCompileSpec spec) {
Compiler<JavaCompileSpec> compiler;
- spec.setSourceFiles(getStableSources());
+ spec.setSourceFiles(getSource());
compiler = createCompiler();
performCompilation(spec, compiler);
}
@@ -226,7 +219,7 @@ private void performCompilation(JavaCompileSpec spec, Compiler<JavaCompileSpec>
@VisibleForTesting
DefaultJavaCompileSpec createSpec() {
validateForkOptionsMatchToolchain();
- List<File> sourcesRoots = CompilationSourceDirs.inferSourceRoots((FileTreeInternal) getStableSources().getAsFileTree());
+ List<File> sourcesRoots = CompilationSourceDirs.inferSourceRoots((FileTreeInternal) getSource().getAsFileTree());
JavaModuleDetector javaModuleDetector = getJavaModuleDetector();
boolean isModule = JavaModuleDetector.isModuleSource(modularity.getInferModulePath().get(), sourcesRoots);
boolean isSourcepathUserDefined = compileOptions.getSourcepath() != null && !compileOptions.getSourcepath().isEmpty();
@@ -350,20 +343,6 @@ public FileCollection getClasspath() {
return super.getClasspath();
}
- /**
- * The sources for incremental change detection.
- *
- * @since 6.0
- */
- @SkipWhenEmpty
- @IgnoreEmptyDirectories
- @NormalizeLineEndings
- @PathSensitive(PathSensitivity.RELATIVE)
- @InputFiles
- protected FileCollection getStableSources() {
- return stableSources;
- }
-
@Inject
protected ObjectFactory getObjectFactory() {
throw new UnsupportedOperationException();
diff --git a/subprojects/core-api/src/main/java/org/gradle/api/file/ConfigurableFileTree.java b/subprojects/core-api/src/main/java/org/gradle/api/file/ConfigurableFileTree.java
index 54ceeb252c8..a908581e273 100644
--- a/subprojects/core-api/src/main/java/org/gradle/api/file/ConfigurableFileTree.java
+++ b/subprojects/core-api/src/main/java/org/gradle/api/file/ConfigurableFileTree.java
@@ -18,15 +18,12 @@
import org.gradle.api.Buildable;
import org.gradle.api.tasks.util.PatternFilterable;
-import java.io.File;
-import java.util.Set;
-
/**
- * <p>A {@link FileTree} with a single base directory, which can be configured and modified.</p>
+ * <p>A configurable {@link FileTree}.</p>
*
* <p>You can obtain a {@code ConfigurableFileTree} instance by calling {@link org.gradle.api.Project#fileTree(java.util.Map)}.</p>
*/
-public interface ConfigurableFileTree extends FileTree, DirectoryTree, PatternFilterable, Buildable {
+public interface ConfigurableFileTree extends FileTree, ConfigurableFileCollection, PatternFilterable, Buildable {
/**
* Specifies base directory for this file tree using the given path. The path is evaluated as per {@link
* org.gradle.api.Project#file(Object)}.
@@ -34,31 +31,14 @@ public interface ConfigurableFileTree extends FileTree, DirectoryTree, PatternFi
* @param dir The base directory.
* @return this
*/
- ConfigurableFileTree from(Object dir);
-
- /**
- * Returns the base directory of this file tree.
- *
- * @return The base directory. Never returns null.
- */
@Override
- File getDir();
+ ConfigurableFileTree from(Object... dir);
- /**
- * Specifies base directory for this file tree using the given path. The path is evaluated as per {@link
- * org.gradle.api.Project#file(Object)}.
- *
- * @param dir The base directory.
- * @return this
- */
- ConfigurableFileTree setDir(Object dir);
+ @Override
+ ConfigurableFileTree convention(Iterable<?> paths);
- /**
- * Returns the set of tasks which build the files of this collection.
- *
- * @return The set. Returns an empty set when there are no such tasks.
- */
- Set<Object> getBuiltBy();
+ @Override
+ ConfigurableFileTree convention(Object... paths);
/**
* Sets the tasks which build the files of this collection.
@@ -66,6 +46,7 @@ public interface ConfigurableFileTree extends FileTree, DirectoryTree, PatternFi
* @param tasks The tasks. These are evaluated as per {@link org.gradle.api.Task#dependsOn(Object...)}.
* @return this
*/
+ @Override
ConfigurableFileTree setBuiltBy(Iterable<?> tasks);
/**
@@ -74,5 +55,6 @@ public interface ConfigurableFileTree extends FileTree, DirectoryTree, PatternFi
* @param tasks The tasks. These are evaluated as per {@link org.gradle.api.Task#dependsOn(Object...)}.
* @return this
*/
+ @Override
ConfigurableFileTree builtBy(Object... tasks);
}
diff --git a/subprojects/core/src/main/java/org/gradle/api/tasks/SourceTask.java b/subprojects/core/src/main/java/org/gradle/api/tasks/SourceTask.java
index fac51e0be21..87ce502685c 100644
--- a/subprojects/core/src/main/java/org/gradle/api/tasks/SourceTask.java
+++ b/subprojects/core/src/main/java/org/gradle/api/tasks/SourceTask.java
@@ -18,18 +18,16 @@
import groovy.lang.Closure;
import org.gradle.api.NonNullApi;
-import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.ConfigurableFileTree;
import org.gradle.api.file.FileTree;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.internal.ConventionTask;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.util.PatternFilterable;
-import org.gradle.api.tasks.util.PatternSet;
-import org.gradle.internal.Factory;
+import org.gradle.internal.instrumentation.api.annotations.ReplacesEagerProperty;
import org.gradle.internal.instrumentation.api.annotations.ToBeReplacedByLazyProperty;
import org.gradle.work.DisableCachingByDefault;
-import javax.inject.Inject;
import java.util.Set;
/**
@@ -38,23 +36,6 @@
@NonNullApi
@DisableCachingByDefault(because = "Super-class, not to be instantiated directly")
public abstract class SourceTask extends ConventionTask implements PatternFilterable {
- private ConfigurableFileCollection sourceFiles = getProject().getObjects().fileCollection();
- private final PatternFilterable patternSet;
-
- public SourceTask() {
- patternSet = getPatternSetFactory().create();
- }
-
- @Inject
- protected Factory<PatternSet> getPatternSetFactory() {
- throw new UnsupportedOperationException();
- }
-
- @Internal
- protected PatternFilterable getPatternSet() {
- return patternSet;
- }
-
/**
* Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.
*
@@ -68,11 +49,10 @@ protected PatternFilterable getPatternSet() {
@InputFiles
@SkipWhenEmpty
@IgnoreEmptyDirectories
- @ToBeReplacedByLazyProperty
+ // TODO ???
+ @ReplacesEagerProperty
@PathSensitive(PathSensitivity.ABSOLUTE)
- public FileTree getSource() {
- return sourceFiles.getAsFileTree().matching(patternSet);
- }
+ public abstract ConfigurableFileTree getSource();
/**
* Sets the source for this task.
@@ -90,7 +70,7 @@ public void setSource(FileTree source) {
* @param source The source.
*/
public void setSource(Object source) {
- sourceFiles = getProject().getObjects().fileCollection().from(source);
+ getSource().setFrom(source);
}
/**
@@ -100,7 +80,7 @@ public void setSource(Object source) {
* @return this
*/
public SourceTask source(Object... sources) {
- sourceFiles.from(sources);
+ getSource().from(sources);
return this;
}
@@ -109,7 +89,7 @@ public SourceTask source(Object... sources) {
*/
@Override
public SourceTask include(String... includes) {
- patternSet.include(includes);
+ getSource().include(includes);
return this;
}
@@ -118,7 +98,7 @@ public SourceTask include(String... includes) {
*/
@Override
public SourceTask include(Iterable<String> includes) {
- patternSet.include(includes);
+ getSource().include(includes);
return this;
}
@@ -127,7 +107,7 @@ public SourceTask include(Iterable<String> includes) {
*/
@Override
public SourceTask include(Spec<FileTreeElement> includeSpec) {
- patternSet.include(includeSpec);
+ getSource().include(includeSpec);
return this;
}
@@ -136,7 +116,7 @@ public SourceTask include(Spec<FileTreeElement> includeSpec) {
*/
@Override
public SourceTask include(Closure includeSpec) {
- patternSet.include(includeSpec);
+ getSource().include(includeSpec);
return this;
}
@@ -145,7 +125,7 @@ public SourceTask include(Closure includeSpec) {
*/
@Override
public SourceTask exclude(String... excludes) {
- patternSet.exclude(excludes);
+ getSource().exclude(excludes);
return this;
}
@@ -154,7 +134,7 @@ public SourceTask exclude(String... excludes) {
*/
@Override
public SourceTask exclude(Iterable<String> excludes) {
- patternSet.exclude(excludes);
+ getSource().exclude(excludes);
return this;
}
@@ -163,7 +143,7 @@ public SourceTask exclude(Iterable<String> excludes) {
*/
@Override
public SourceTask exclude(Spec<FileTreeElement> excludeSpec) {
- patternSet.exclude(excludeSpec);
+ getSource().exclude(excludeSpec);
return this;
}
@@ -172,7 +152,7 @@ public SourceTask exclude(Spec<FileTreeElement> excludeSpec) {
*/
@Override
public SourceTask exclude(Closure excludeSpec) {
- patternSet.exclude(excludeSpec);
+ getSource().exclude(excludeSpec);
return this;
}
@@ -183,7 +163,7 @@ public SourceTask exclude(Closure excludeSpec) {
@Internal
@ToBeReplacedByLazyProperty
public Set<String> getIncludes() {
- return patternSet.getIncludes();
+ return getSource().getIncludes();
}
/**
@@ -191,7 +171,7 @@ public Set<String> getIncludes() {
*/
@Override
public SourceTask setIncludes(Iterable<String> includes) {
- patternSet.setIncludes(includes);
+ getSource().setIncludes(includes);
return this;
}
@@ -202,7 +182,7 @@ public SourceTask setIncludes(Iterable<String> includes) {
@Internal
@ToBeReplacedByLazyProperty
public Set<String> getExcludes() {
- return patternSet.getExcludes();
+ return getSource().getExcludes();
}
/**
@@ -210,7 +190,7 @@ public Set<String> getExcludes() {
*/
@Override
public SourceTask setExcludes(Iterable<String> excludes) {
- patternSet.setExcludes(excludes);
+ getSource().setExcludes(excludes);
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment