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

Remove custom idea JDK configuration #718

Merged
merged 2 commits into from
Aug 15, 2019
Merged
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-718.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: The `baseline-idea` plugin now generates configuration more closely aligned with Gradle defaults.
links:
- https://github.com/palantir/gradle-baseline/pull/718
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class BaselineIdea extends AbstractBaselinePlugin {
}

// Configure Idea module
addJdkVersion(ideaModuleModel)
markResourcesDirs(ideaModuleModel)
moveProjectReferencesToEnd(ideaModuleModel)
}
Expand Down Expand Up @@ -228,29 +227,6 @@ class BaselineIdea extends AbstractBaselinePlugin {
return base.appendNode(name, attributes + defaults)
}

/**
* Configures JDK and Java language level of the given IdeaModel according to the sourceCompatibility property.
*/
private void addJdkVersion(IdeaModel ideaModel) {
def compileJavaTask = (JavaCompile) project.tasks.findByName('compileJava')
if (compileJavaTask) {
def javaVersion = compileJavaTask.sourceCompatibility
def jdkVersion = 'JDK_' + javaVersion.replaceAll('\\.', '_')
project.logger.debug("BaselineIdea: Configuring IDEA Module for Java version: " + javaVersion)

if (ideaModel.project != null) {
ideaModel.project.languageLevel = javaVersion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably wrong to set project values here since this is called when applying this plugin to each subproject. If subprojects specify different source compatibilities, then we have a race condition (since I don't think Gradle provides guarantees about the ordering plugins are applied to subprojects).

}

ideaModel.module.jdkName = javaVersion
ideaModel.module.iml.withXml {
it.asNode().component.find { it.@name == 'NewModuleRootManager' }.@LANGUAGE_LEVEL = jdkVersion
}
} else {
project.logger.debug("BaselineIdea: No Java version found in sourceCompatibility property.")
}
}

/**
* By default the Idea plugin marks resources dirs as source dirs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,6 @@ class BaselineIdeaIntegrationTest extends AbstractPluginTest {
with('idea').build()
}

def 'Modules for subprojects pick up the correct sourceCompatibility'() {
when:
buildFile << standardBuildFile
buildFile << '''
sourceCompatibility = 1.6
'''.stripIndent()
def subproject = multiProject.create(["subproject1", "subproject2"])
subproject["subproject1"].buildGradle << '''
apply plugin: 'java'
apply plugin: 'com.palantir.baseline-idea'
sourceCompatibility = 1.7
'''.stripIndent()
subproject["subproject2"].buildGradle << '''
apply plugin: 'java'
apply plugin: 'com.palantir.baseline-idea'
sourceCompatibility = 1.8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this change, what's the resulting config in the iml xml?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it on our internal foundry email-service and it gave me this idea.iml file:

<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
      <excludeFolder url="file://$MODULE_DIR$/build" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

'''.stripIndent()

then:
with('idea').build()
def rootIml = Files.asCharSource(new File(projectDir, projectDir.name + ".iml"), Charsets.UTF_8).read()
rootIml ==~ /(?s).*orderEntry[^\\n]*jdkName="1.6".*/
def subproject1Iml = Files.asCharSource(new File(projectDir, "subproject1/subproject1.iml"),
Charsets.UTF_8).read()
subproject1Iml ==~ /(?s).*orderEntry[^\\n]*jdkName="1.7".*/
def subproject2Iml = Files.asCharSource(new File(projectDir, "subproject2/subproject2.iml"),
Charsets.UTF_8).read()
subproject2Iml ==~ /(?s).*orderEntry[^\\n]*jdkName="1.8".*/
}

def 'Idea project has copyright configuration'() {
when:
buildFile << standardBuildFile
Expand Down