Skip to content

Instantly share code, notes, and snippets.

@Bombe
Created February 8, 2015 12:10
Show Gist options
  • Save Bombe/a273ea8e6ed495f88bfc to your computer and use it in GitHub Desktop.
Save Bombe/a273ea8e6ed495f88bfc to your computer and use it in GitHub Desktop.
Patch for the retired Maven IDEA plugin (version 2.2.1) to allow setting the language level in the IDEA configuration file.
Index: src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java (revision 1658114)
+++ src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java (working copy)
@@ -161,6 +161,11 @@
setJdkName( module, defaultJdkName );
}
+ if ( jdkLevel != null )
+ {
+ setJdkLevel(module, jdkLevel);
+ }
+
setWildcardResourcePatterns( module, wildcardResourcePatterns );
Element component = findComponent( module, "ProjectModuleManager" );
@@ -258,6 +263,12 @@
}
}
+ private void setJdkLevel( Element content, String jdkLevel )
+ {
+ Element component = findComponent( content, "ProjectRootManager" );
+ component.addAttribute( "languageLevel", "JDK_" + jdkLevel.replace( '.', '_' ) );
+ }
+
/**
* Sets the wilcard resource patterns.
*
Index: src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java
===================================================================
--- src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java (revision 1658114)
+++ src/test/java/org/apache/maven/plugin/idea/IdeaProjectTest.java (working copy)
@@ -75,6 +75,7 @@
Document iprDocument = executeMojo( "src/test/project-plugin-configs/plugin-config-jdk15.xml" );
testJdkName( iprDocument, "1.5", "java version 1.5" );
+ testJdkLevel( iprDocument, "JDK_1_5" );
}
public void testIdeaProjectWithModules()
@@ -153,6 +154,19 @@
}
}
+ private void testJdkLevel( Document document, String expectedJdkLevel )
+ throws Exception
+ {
+ Element root = document.getRootElement();
+
+ Element component = findComponent( root, "ProjectRootManager" );
+
+ String jdkLevel = component.attributeValue( "languageLevel" );
+
+ assertEquals("lagnuageLevel must be set correctly",
+ expectedJdkLevel, jdkLevel);
+ }
+
protected Document executeMojo( String pluginXml )
throws Exception
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment