From 075df48434ce06fe3b98751acd391a22c6af48fd Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Fri, 13 May 2022 09:10:21 +0800 Subject: [PATCH] test: reproduce the reported issue --- .../snom/CacheabilityFunctionalTest.groovy | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy index c561a4064..7003f4722 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy @@ -110,6 +110,71 @@ class CacheabilityFunctionalTest extends Specification { hashKeyLine1 == hashKeyLine2 } + /** + * @see GitHub Issue + */ + def 'build cache is invalidate when user changes stylesheet'() { + given: + def buildDir = Files.createTempDirectory(null).toFile() + def buildFile = new File(buildDir, 'build.gradle') + def version = System.getProperty('snom.test.functional.gradle', GradleVersion.current().version) + def buildFileContent = ''' + |plugins { + | id 'java' + | id 'com.github.spotbugs' + |} + | + |version = 1.0 + | + |repositories { + | mavenCentral() + |} + |spotbugsMain { + | reports { + | html { + | required = true + | stylesheet = 'fancy-hist.xsl' + | } + | } + |} + |'''.stripMargin() + + initializeBuildFile(buildDir) + buildFile.write(buildFileContent) + + when: + GradleRunner.create() + .withProjectDir(buildDir) + .withArguments('--build-cache', ':spotbugsMain') + .withPluginClasspath() + .withGradleVersion(version) + .build() + + buildFile.write(buildFileContent.replace('fancy-hist.xsl', 'plain.xsl')) + BuildResult result1 = + GradleRunner.create() + .withProjectDir(buildDir) + .withArguments('--build-cache', ':spotbugsMain') + .withPluginClasspath() + .withGradleVersion(version) + .build() + + then: + result1.task(':spotbugsMain').outcome == TaskOutcome.SUCCESS + + when: + BuildResult result2 = + GradleRunner.create() + .withProjectDir(buildDir) + .withArguments('--build-cache', ':spotbugsMain') + .withPluginClasspath() + .withGradleVersion(version) + .build() + + then: + result2.task(':spotbugsMain').outcome == TaskOutcome.FROM_CACHE + } + private static String getHashKeyLine(BuildResult result) { return result.output.find('Build cache key for task \':spotbugsMain\' is .*') }