Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reproduce the reported issue #732

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,71 @@ class CacheabilityFunctionalTest extends Specification {
hashKeyLine1 == hashKeyLine2
}

/**
* @see <a href="https://github.com/spotbugs/spotbugs-gradle-plugin/issues/710">GitHub Issue</a>
*/
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.UP_TO_DATE
}

private static String getHashKeyLine(BuildResult result) {
return result.output.find('Build cache key for task \':spotbugsMain\' is .*')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.resources.TextResource;
import org.gradle.api.tasks.Input;

public abstract class SpotBugsHtmlReport extends SpotBugsReport {
private final Property<TextResource> stylesheet;
Expand Down Expand Up @@ -56,6 +57,7 @@ public String getName() {
}

@Override
@Input
public TextResource getStylesheet() {
if (stylesheet.isPresent()) {
return stylesheet.get();
Expand Down