Skip to content

Commit 9a5e1d3

Browse files
authored
Merge pull request #2102 from gradle/sg/findbugs/error
Do not resolve classes dirs as a file tree
2 parents 09db6a2 + 9f84acb commit 9a5e1d3

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

subprojects/code-quality/src/integTest/groovy/org/gradle/api/plugins/quality/AbstractFindBugsPluginIntegrationTest.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,27 @@ abstract class AbstractFindBugsPluginIntegrationTest extends AbstractIntegration
510510
result.assertTaskNotSkipped(":findbugsMain")
511511
}
512512

513+
def "does not fail if resources are generated into classes"() {
514+
given:
515+
goodCode()
516+
buildFile << """
517+
compileJava {
518+
doLast {
519+
def manifest = new File(destinationDir, "META-INF/MANIFEST.MF")
520+
manifest.parentFile.mkdirs()
521+
manifest.text = "manifest"
522+
def properties = new File(destinationDir, "com/example/service.properties")
523+
properties.parentFile.mkdirs()
524+
properties.text = "someProp=value"
525+
}
526+
}
527+
"""
528+
when:
529+
succeeds("check")
530+
then:
531+
!result.error.contains("Wrong magic bytes")
532+
}
533+
513534
private static boolean containsXmlMessages(File xmlReportFile) {
514535
new XmlSlurper().parseText(xmlReportFile.text).BugInstance.children().collect { it.name() }.containsAll(['ShortMessage', 'LongMessage'])
515536
}

subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/FindBugs.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,23 @@ public FileTree getSource() {
328328
@SkipWhenEmpty
329329
@PathSensitive(PathSensitivity.RELATIVE)
330330
@InputFiles
331+
protected FileCollection getCandidateClassFiles() {
332+
// We need to resolve the classes into a set of files so @SkipWhenEmpty will work
333+
// Otherwise, a collection of empty directories is not seen as "empty"
334+
return getClasses().getAsFileTree();
335+
}
336+
337+
/**
338+
* The class directories to be analyzed.
339+
*/
340+
@Internal
331341
public FileCollection getClasses() {
332342
return classes;
333343
}
334344

345+
335346
/**
336-
* The classes to be analyzed.
347+
* The class directories to be analyzed.
337348
*/
338349
public void setClasses(FileCollection classes) {
339350
this.classes = classes;

subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/FindBugsPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected void configureForSourceSet(final SourceSet sourceSet, FindBugs task) {
186186
taskMapping.map("classes", new Callable<FileCollection>() {
187187
@Override
188188
public FileCollection call() {
189-
return sourceSet.getOutput().getClassesDirs().getAsFileTree();
189+
return sourceSet.getOutput().getClassesDirs();
190190
}
191191
});
192192
taskMapping.map("classpath", new Callable<FileCollection>() {

subprojects/code-quality/src/test/groovy/org/gradle/api/plugins/quality/FindBugsPluginTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class FindBugsPluginTest extends AbstractProjectBuilderSpec {
8484
description == "Run FindBugs analysis for ${sourceSet.name} classes"
8585
source as List == sourceSet.allJava as List
8686
findbugsClasspath == project.configurations.findbugs
87-
classes.empty // no classes to analyze
87+
candidateClassFiles.empty // no classes to analyze
8888
reports.xml.destination == project.file("build/reports/findbugs/${sourceSet.name}.xml")
8989
!ignoreFailures
9090
effort == null

subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.FindBugs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</thead>
1111
<tr>
1212
<td>classes</td>
13-
<td><literal><replaceable>sourceSet</replaceable>.output</literal></td>
13+
<td><literal><replaceable>sourceSet</replaceable>.output.classesDirs</literal></td>
1414
</tr>
1515
<tr>
1616
<td>classpath</td>

0 commit comments

Comments
 (0)