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 #67 from palantir/module.output.directory
Browse files Browse the repository at this point in the history
Use "Output relative to content root" again
  • Loading branch information
alicederyn authored May 10, 2017
2 parents 0a16a4c + a8263e2 commit 8b6dc71
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
16 changes: 11 additions & 5 deletions src/main/groovy/org/inferred/gradle/ProcessorsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ProcessorsPlugin implements Plugin<Project> {
// This file is only generated in the root project, but the user may not have applied
// the gradle-processors plugin to the root project. Instead, we update it from
// every project idempotently.
updateIdeaCompilerConfiguration(project.rootProject, node)
updateIdeaCompilerConfiguration(project.rootProject, node, false)
}
}
}
Expand All @@ -129,7 +129,7 @@ class ProcessorsPlugin implements Plugin<Project> {
File ideaCompilerXml = project.rootProject.file('.idea/compiler.xml')
if (ideaCompilerXml.isFile()) {
Node parsedProjectXml = (new XmlParser()).parse(ideaCompilerXml)
updateIdeaCompilerConfiguration(project.rootProject, parsedProjectXml)
updateIdeaCompilerConfiguration(project.rootProject, parsedProjectXml, true)
ideaCompilerXml.withWriter { writer ->
XmlNodePrinter nodePrinter = new XmlNodePrinter(new PrintWriter(writer))
nodePrinter.setPreserveWhitespace(true)
Expand Down Expand Up @@ -252,7 +252,10 @@ class ProcessorsPlugin implements Plugin<Project> {
}
}

static void updateIdeaCompilerConfiguration(Project project, Node projectConfiguration) {
static void updateIdeaCompilerConfiguration(
Project project,
Node projectConfiguration,
boolean directoryBasedProject) {
Object compilerConfiguration = projectConfiguration.component
.find { it.@name == 'CompilerConfiguration' }

Expand All @@ -264,11 +267,14 @@ class ProcessorsPlugin implements Plugin<Project> {
new Node(compilerConfiguration, "annotationProcessing")
}

def dirPrefix = (directoryBasedProject ? '../' : '')

compilerConfiguration.annotationProcessing.replaceNode{
annotationProcessing() {
profile(default: 'true', name: 'Default', enabled: 'true') {
sourceOutputDir(name: '../../../' + getIdeaSourceOutputDir(project))
sourceTestOutputDir(name: '../../../' + getIdeaSourceTestOutputDir(project))
sourceOutputDir(name: dirPrefix + getIdeaSourceOutputDir(project))
sourceTestOutputDir(name: dirPrefix + getIdeaSourceTestOutputDir(project))
outputRelativeToContentRoot(value: 'true')
processorPath(useClasspath: 'true')
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public class ProcessorsPluginFunctionalTest {
File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.withArguments("tasks", "--stacktrace")
.build()

def xml = testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile().text.trim()
Expand All @@ -679,8 +679,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../generated_src"/>
<sourceTestOutputDir name="../../../generated_testSrc"/>
<sourceOutputDir name="../generated_src"/>
<sourceTestOutputDir name="../generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand Down Expand Up @@ -710,7 +711,7 @@ public class ProcessorsPluginFunctionalTest {
File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.withArguments("tasks", "--stacktrace")
.build()

def xml = testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile().text.trim()
Expand All @@ -720,8 +721,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../generated_src"/>
<sourceTestOutputDir name="../../../generated_testSrc"/>
<sourceOutputDir name="../generated_src"/>
<sourceTestOutputDir name="../generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand All @@ -732,6 +734,32 @@ public class ProcessorsPluginFunctionalTest {
assertEquals(expected, xml)
}

@Test
public void testUserSpecifiedDirectoriesUsedInIdeaIprFile() throws IOException {
buildFile << """
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.inferred.processors'
idea.processors {
outputDir = 'foo'
testOutputDir = 'bar'
}
"""

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

def xml = new XmlSlurper().parse(testProjectDirRoot.toPath().resolve("${testProjectDirRoot.name}.ipr").toFile())
def compilerConfiguration = xml.component.findResult { it.@name == "CompilerConfiguration" ? it : null }
def profile = compilerConfiguration.annotationProcessing.profile.findResult { it.@name == "Default" ? it : null }
assertEquals(profile.sourceOutputDir.first().@name, "foo")
assertEquals(profile.sourceTestOutputDir.first().@name, "bar")
}

@Test
public void testUserSpecifiedDirectoriesUsedInIdeaCompilerXml() throws IOException {
buildFile << """
Expand All @@ -757,7 +785,7 @@ public class ProcessorsPluginFunctionalTest {
File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.withArguments("tasks", "--stacktrace")
.build()

def xml = testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile().text.trim()
Expand All @@ -767,8 +795,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../foo"/>
<sourceTestOutputDir name="../../../bar"/>
<sourceOutputDir name="../foo"/>
<sourceTestOutputDir name="../bar"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand Down Expand Up @@ -820,7 +849,7 @@ public class ProcessorsPluginFunctionalTest {
def xml = new XmlSlurper().parse(testProjectDirRoot.toPath().resolve("${testProjectDirRoot.name}.ipr").toFile())
def compilerConfiguration = xml.component.findResult { it.@name == "CompilerConfiguration" ? it : null }
def profile = compilerConfiguration.annotationProcessing.profile.findResult { it.@name == "Default" ? it : null }
assertEquals(profile.sourceOutputDir.first().@name, "../../../generated_src")
assertEquals(profile.sourceOutputDir.first().@name, "generated_src")
}

/** @see https://github.com/palantir/gradle-processors/issues/12 */
Expand Down Expand Up @@ -897,8 +926,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../generated_src"/>
<sourceTestOutputDir name="../../../generated_testSrc"/>
<sourceOutputDir name="../generated_src"/>
<sourceTestOutputDir name="../generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand Down Expand Up @@ -935,7 +965,7 @@ public class ProcessorsPluginFunctionalTest {
File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.withArguments("tasks", "--stacktrace")
.build()

def xml = testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile().text.trim()
Expand All @@ -945,8 +975,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../foo"/>
<sourceTestOutputDir name="../../../bar"/>
<sourceOutputDir name="../foo"/>
<sourceTestOutputDir name="../bar"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand Down Expand Up @@ -986,7 +1017,7 @@ public class ProcessorsPluginFunctionalTest {
File testProjectDirRoot = testProjectDir.getRoot()
GradleRunner.create()
.withProjectDir(testProjectDirRoot)
.withArguments("idea", "--stacktrace")
.withArguments("tasks", "--stacktrace")
.build()

def xml = testProjectDirRoot.toPath().resolve(".idea/compiler.xml").toFile().text.trim()
Expand All @@ -996,8 +1027,9 @@ public class ProcessorsPluginFunctionalTest {
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true">
<sourceOutputDir name="../../../generated_src"/>
<sourceTestOutputDir name="../../../generated_testSrc"/>
<sourceOutputDir name="../generated_src"/>
<sourceTestOutputDir name="../generated_testSrc"/>
<outputRelativeToContentRoot value="true"/>
<processorPath useClasspath="true"/>
</profile>
</annotationProcessing>
Expand Down

0 comments on commit 8b6dc71

Please sign in to comment.