Skip to content

Commit

Permalink
fix: use internal property to avoid issues with configuration cache (#…
Browse files Browse the repository at this point in the history
…857)

* use internal property to avoid issues with configuration cache

fixes #670

* remove redundant "path" in property name
  • Loading branch information
C-Otto committed Mar 22, 2023
1 parent c22537f commit d068aa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.VerificationTask
import org.gradle.internal.enterprise.test.FileProperty
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService;
import org.gradle.util.ClosureBackedAction
Expand All @@ -61,6 +60,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory

import javax.inject.Inject
import java.nio.file.Path

/**
* The Gradle task to run the SpotBugs analysis. All properties are optional.
Expand Down Expand Up @@ -264,6 +264,8 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
@NonNull
final Property<Boolean> useAuxclasspathFile

@Internal
private Path auxclasspathFile;
private FileCollection classes;

private boolean enableWorkerApi;
Expand Down Expand Up @@ -386,6 +388,9 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
* @param extension the source extension to copy the properties.
*/
void init(SpotBugsExtension extension, boolean enableWorkerApi, boolean enableHybridWorker) {
def taskName = getName()
auxclasspathFile = project.layout.buildDirectory.file("spotbugs/auxclasspath/$taskName").get().getAsFile().toPath()

ignoreFailures.convention(extension.ignoreFailures)
showStackTraces.convention(extension.showStackTraces)
showProgress.convention(extension.showProgress)
Expand All @@ -399,7 +404,7 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
excludeFilter.convention(extension.excludeFilter)
baselineFile.convention(extension.baselineFile)
onlyAnalyze.convention(extension.onlyAnalyze)
projectName.convention(extension.projectName.map({p -> String.format("%s (%s)", p, getName())}))
projectName.convention(extension.projectName.map({p -> String.format("%s (%s)", p, taskName)}))
release.convention(extension.release)
jvmArgs.convention(extension.jvmArgs)
extraArgs.convention(extension.extraArgs)
Expand Down Expand Up @@ -535,4 +540,8 @@ abstract class SpotBugsTask extends DefaultTask implements VerificationTask {
}
return new StringBuilder().append(Character.toLowerCase(prunedName.charAt(0))).append(prunedName.substring(1)).toString()
}

Path getAuxclasspathFile() {
return auxclasspathFile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -139,12 +138,7 @@ private String createFileForAuxClasspath(SpotBugsTask task) {
.map(File::getAbsolutePath)
.collect(Collectors.joining("\n"));
try {
Path auxClasspathFile =
Paths.get(
task.getProject().getBuildDir().getAbsolutePath(),
"spotbugs",
"auxclasspath",
task.getName());
Path auxClasspathFile = task.getAuxclasspathFile();
try {
Files.createDirectories(auxClasspathFile.getParent());
if (!Files.exists(auxClasspathFile)) {
Expand Down

0 comments on commit d068aa2

Please sign in to comment.