Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from henryptung/master
Browse files Browse the repository at this point in the history
Make Findbugs workaround configurable
  • Loading branch information
alicederyn authored Apr 10, 2017
2 parents 72c682d + 70ffcc7 commit 6665626
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/main/groovy/org/inferred/gradle/ProcessorsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ProcessorsPlugin implements Plugin<Project> {
void apply(Project project) {

project.configurations.create('processor')
project.extensions.create('processors', ProcessorsExtension)

/**** javac, groovy, etc. *********************************************************************/
project.plugins.withType(JavaPlugin, { plugin ->
Expand Down Expand Up @@ -139,18 +140,20 @@ class ProcessorsPlugin implements Plugin<Project> {

/**** FindBugs ********************************************************************************/
project.tasks.withType(FindBugs, { task -> task.doFirst {
// Exclude generated sources from FindBugs' traversal.
// This trick relies on javac putting the generated .java files next to the .class files.
def generatedSources = task.classes.filter {
it.path.endsWith '.java'
}
task.classes = task.classes.filter {
File javaFile = new File(it.path
.replaceFirst(/\$\w+\.class$/, '')
.replaceFirst(/\.class$/, '')
+ '.java')
boolean isGenerated = generatedSources.contains(javaFile)
return !isGenerated
if (project.processors.suppressFindbugs) {
// Exclude generated sources from FindBugs' traversal.
// This trick relies on javac putting the generated .java files next to the .class files.
def generatedSources = task.classes.filter {
it.path.endsWith '.java'
}
task.classes = task.classes.filter {
File javaFile = new File(it.path
.replaceFirst(/\$\w+\.class$/, '')
.replaceFirst(/\.class$/, '')
+ '.java')
boolean isGenerated = generatedSources.contains(javaFile)
return !isGenerated
}
}
}})
}
Expand Down Expand Up @@ -281,6 +284,10 @@ class ProcessorsPlugin implements Plugin<Project> {

}

class ProcessorsExtension {
boolean suppressFindbugs = true
}

class EclipseProcessorsExtension {
Object outputDir
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,45 @@ public class ProcessorsPluginFunctionalTest {
.build()
}

@Test
public void testFindBugsIntegrationImmutablesEnclosing() throws IOException {
buildFile << """
apply plugin: 'java'
apply plugin: 'findbugs'
apply plugin: 'org.inferred.processors'
processors {
suppressFindbugs = false
}
dependencies {
processor 'com.google.code.findbugs:findbugs-annotations:3.0.1'
processor 'org.immutables:value:2.4.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.6'
}
"""

new File(testProjectDir.newFolder('src', 'main', 'java'), 'MyClass.java') << """
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.immutables.value.Value;
@Value.Enclosing
public interface MyClass {
@Value.Immutable
@JsonDeserialize(as = ImmutableMyClass.Inner.class)
interface Inner {
@Value.Parameter String getValue();
}
}
"""

GradleRunner.create()
.withProjectDir(testProjectDir.getRoot())
.withArguments("findbugsMain")
.build()
}

/** @see https://github.com/palantir/gradle-processors/issues/3 */
@Test
public void testProcessorJarsNotExported() throws IOException {
Expand Down

0 comments on commit 6665626

Please sign in to comment.