1 package org.apache.maven.plugin.idea;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.dom4j.Document;
23 import org.dom4j.Element;
24
25 import java.util.List;
26
27
28
29
30 public class IdeaProjectTest
31 extends AbstractIdeaTestCase
32 {
33 public void testIdeaProjectTestEnvironment()
34 throws Exception
35 {
36 Document iprDocument = executeMojo( "src/test/project-plugin-configs/min-plugin-config.xml" );
37
38 testJdkName( iprDocument, null, null );
39 }
40
41 public void testIdeaProjectVersion4()
42 throws Exception
43 {
44 Document iprDocument = executeMojo( "src/test/project-plugin-configs/plugin-config-idea4.xml" );
45
46 Element root = iprDocument.getRootElement();
47
48 Element component = findComponent( root, "ProjectRootManager" );
49
50 String jdkName = component.attributeValue( "project-jdk-name" );
51
52 String javaVersion = System.getProperty( "java.version" );
53
54 assertEquals( "Default jdkName should be from System.Properties",
55 jdkName, "java version "" + javaVersion + """ );
56
57 component = findComponent( root, "CompilerConfiguration" );
58
59 Element patterns = findElementByNameAttribute( component, "wildcardResourcePatterns", null );
60
61 findElementByNameAttribute( patterns, "entry", "!?*.java" );
62 }
63
64 public void testIdeaProjectJdk11()
65 throws Exception
66 {
67 Document iprDocument = executeMojo( "src/test/project-plugin-configs/plugin-config-jdk11.xml" );
68
69 testJdkName( iprDocument, "1.1", "java version 1.1" );
70 }
71
72 public void testIdeaProjectJdk15()
73 throws Exception
74 {
75 Document iprDocument = executeMojo( "src/test/project-plugin-configs/plugin-config-jdk15.xml" );
76
77 testJdkName( iprDocument, "1.5", "java version 1.5" );
78 }
79
80 public void testIdeaProjectWithModules()
81 throws Exception
82 {
83 Document iprDocument = executeMojo( "src/test/project-plugin-configs/plugin-config-modules.xml" );
84
85 Element component = findComponent( iprDocument.getRootElement(), "ProjectModuleManager" );
86
87 Element el = findElementByNameAttribute( component, "modules", null );
88
89 List modules = findElementsByName( el, "module" );
90
91 assertEquals( "Must have 4 modules", 4, modules.size() );
92
93 el = (Element) modules.get( 0 );
94 assertEquals( "Test project module",
95 "$PROJECT_DIR$/plugin-test-p-mod.iml",
96 el.attributeValue( "filepath" ) );
97
98 el = (Element) modules.get( 1 );
99 assertEquals( "Test module 1",
100 "$PROJECT_DIR$/module-1/module-1.iml",
101 el.attributeValue( "filepath" ) );
102
103 el = (Element) modules.get( 2 );
104 assertEquals( "Test module 2",
105 "$PROJECT_DIR$/module-2/module-2.iml",
106 el.attributeValue( "filepath" ) );
107
108 el = (Element) modules.get( 3 );
109 assertEquals( "Test module 3",
110 "$PROJECT_DIR$/module-3/module-3.iml",
111 el.attributeValue( "filepath" ) );
112 }
113
114 private void testJdkName( Document document, String jdkLevel, String expected )
115 throws Exception
116 {
117 Element root = document.getRootElement();
118
119 Element component = findComponent( root, "ProjectRootManager" );
120
121 String jdkName = component.attributeValue( "project-jdk-name" );
122
123 if ( jdkLevel == null )
124 {
125 jdkLevel = System.getProperty( "java.specification.version" );
126 }
127
128 if ( jdkLevel.startsWith( "1.4" ) )
129 {
130 assertEquals( "assert-keyword must be true for jdk 1.4",
131 "true", component.attributeValue( "assert-keyword" ) );
132
133 assertEquals( "jdk-15 must be false for jdk 1.4",
134 "false", component.attributeValue( "jdk-15") );
135 }
136 else if ( jdkLevel.compareTo( "1.5" ) >= 0 )
137 {
138 assertEquals( "assert-keyword must be true for jdk >= 1.5",
139 "true", component.attributeValue( "assert-keyword" ) );
140
141 assertEquals( "jdk-15 must be true for jdk >= 1.5",
142 "true", component.attributeValue( "jdk-15") );
143 }
144 else
145 {
146 assertEquals( "assert-keyword must be true for jdk >= 1.5",
147 "false", component.attributeValue( "assert-keyword" ) );
148 }
149
150 if ( expected != null )
151 {
152 assertEquals( "Expected jdkName test", jdkName, expected );
153 }
154 }
155
156 protected Document executeMojo( String pluginXml )
157 throws Exception
158 {
159 return super.executeMojo( "project", pluginXml, "ipr" );
160 }
161 }