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 #52 from jhoch-palantir/jhoch/issue51/no-annotatio…
Browse files Browse the repository at this point in the history
…n-processor-field

Handles missing <annotationProcessing> tag (.idea)
  • Loading branch information
alicederyn authored Jan 6, 2017
2 parents 957e67c + 3cb4a9c commit 2336f24
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/groovy/org/inferred/gradle/ProcessorsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ class ProcessorsPlugin implements Plugin<Project> {
throw new GradleException("Unable to find CompilerConfiguration element")
}

if (compilerConfiguration.annotationProcessing.isEmpty()) {
new Node(compilerConfiguration, "annotationProcessing")
}

compilerConfiguration.annotationProcessing.replaceNode{
annotationProcessing() {
profile(default: 'true', name: 'Default', enabled: 'true') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,93 @@ public class ProcessorsPluginFunctionalTest {
assertEquals(expected, sourceFolderUrls.toSet())
}

@Test
public void testAnnotationProcessingInIdeaCompilerXml() throws IOException {
buildFile << """
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.inferred.processors'
"""

new File(testProjectDir.newFolder('.idea'), 'compiler.xml') << """
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing/>
</component>
</project>
""".trim()

File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.build()

def xml = new XmlSlurper().parse(testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile())

def expected = new XmlSlurper().parseText("""
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="generated_src"/>
<sourceTestOutputDir name="generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
</component>
</project>
""".trim())

assertEquals(expected, xml)
}

@Test
public void testNoAnnotationProcessingInIdeaCompilerXml() throws IOException {
buildFile << """
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.inferred.processors'
"""

new File(testProjectDir.newFolder('.idea'), 'compiler.xml') << """
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
</component>
</project>
""".trim()

File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.build()

def xml = new XmlSlurper().parse(testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile())

def expected = new XmlSlurper().parseText("""
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="generated_src"/>
<sourceTestOutputDir name="generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
</component>
</project>
""".trim())

assertEquals(expected, xml)
}

@Test
public void testOnlyApplyToSubProject() {
testProjectDir.newFolder("projectA")
Expand Down

0 comments on commit 2336f24

Please sign in to comment.