1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse.it;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.InputStreamReader;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Properties;
27
28 import org.apache.maven.plugin.eclipse.Constants;
29 import org.apache.maven.plugin.ide.IdeUtils;
30 import org.apache.maven.project.MavenProject;
31 import org.codehaus.plexus.util.FileUtils;
32 import org.codehaus.plexus.util.xml.Xpp3Dom;
33 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
34
35
36
37
38 public class RadPluginIT
39 extends AbstractEclipsePluginIT
40 {
41
42 private static final String PROJECTS_BASEDIR = "target/test-classes/projects";
43
44 public void testProject1()
45 throws Exception
46 {
47 testProject( "project-rad-1", new Properties(), "rad-clean", "rad" );
48 }
49
50 public void testProject2()
51 throws Exception
52 {
53 testProject( "project-rad-2", new Properties(), "rad-clean", "rad" );
54 File generatedManifest = getTestFile( PROJECTS_BASEDIR + "/project-rad-2/src/main/webapp/META-INF/MANIFEST.MF" );
55 File expectedManifest =
56 getTestFile( PROJECTS_BASEDIR + "/project-rad-2/src/main/webapp/META-INF/expected_MANIFEST.MF" );
57 assertFileEquals( expectedManifest, generatedManifest );
58
59 }
60
61 public void testProject3()
62 throws Exception
63 {
64 testProject( "project-rad-3", new Properties(), "rad-clean", "rad" );
65 File generatedManifest = getTestFile( PROJECTS_BASEDIR + "/project-rad-3/ejbModule/META-INF/MANIFEST.MF" );
66 File expectedManifest =
67 getTestFile( PROJECTS_BASEDIR + "/project-rad-3/ejbModule/META-INF/expected_MANIFEST.MF" );
68 assertFileEquals( expectedManifest, generatedManifest );
69 }
70
71 public void testProject4()
72 throws Exception
73 {
74 testProject( "project-rad-4", new Properties(), "rad-clean", "rad" );
75 }
76
77 public void testProject5()
78 throws Exception
79 {
80 File basedir = getTestFile( "target/test-classes/projects/project-rad-5" );
81
82 FileUtils.deleteDirectory( new File( basedir, "project-rad-1/META-INF" ) );
83 new File( basedir, "project-rad-1/META-INF" ).mkdirs();
84
85 File pom0 = new File( basedir, "pom.xml" );
86
87 MavenProject project = readProject( pom0 );
88
89 String outputDirPath =
90 IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
91 File outputDir;
92
93 if ( outputDirPath == null )
94 {
95 outputDir = basedir;
96 }
97 else
98 {
99 outputDir = new File( basedir, outputDirPath );
100 outputDir.mkdirs();
101 new File( outputDir, project.getArtifactId() );
102 }
103
104 List goals = new ArrayList();
105
106 String pluginSpec = getPluginCLISpecification();
107
108 goals.add( pluginSpec + "rad-clean" );
109 goals.add( pluginSpec + "rad" );
110 goals.add( "install" );
111
112 Properties props = new Properties();
113
114 executeMaven( pom0, props, goals );
115
116 assertTrue( "Expected file not found: project-rad-1/maven-core-98.0.jar",
117 new File( basedir, "project-rad-1/maven-core-98.0.jar" ).exists() );
118
119 Xpp3Dom applicationXml =
120 Xpp3DomBuilder.build( new InputStreamReader(
121 new FileInputStream(
122 new File( basedir,
123 "project-rad-1/META-INF/application.xml" ) ),
124 "UTF-8" ) );
125
126 Xpp3Dom modulesmapsXml =
127 Xpp3DomBuilder.build( new InputStreamReader(
128 new FileInputStream(
129 new File( basedir,
130 "project-rad-1/META-INF/.modulemaps" ) ),
131 "UTF-8" ) );
132
133 assertNotNull( modulesmapsXml );
134
135 Xpp3Dom[] children = applicationXml.getChildren( "module" );
136 assertEquals( 2, children.length );
137
138 boolean ejbVerified = false;
139 boolean warVerified = false;
140 for ( int i = 0; i < children.length; i++ )
141 {
142 Xpp3Dom child = children[i];
143
144 if ( child.getAttribute( "id" ).startsWith( "WebModule_" ) )
145 {
146 assertEquals( "project-rad-5_2.war", child.getChild( "web" ).getChild( "web-uri" ).getValue() );
147 assertEquals( "project-rad-5_2", child.getChild( "web" ).getChild( "context-root" ).getValue() );
148 warVerified = true;
149 }
150 else if ( child.getAttribute( "id" ).startsWith( "EjbModule_" ) )
151 {
152 assertEquals( "project-rad-5_3.jar", child.getChild( Constants.PROJECT_PACKAGING_EJB ).getValue() );
153 ejbVerified = true;
154 }
155 }
156 assertTrue( warVerified );
157 assertTrue( ejbVerified );
158
159 Xpp3Dom websettings =
160 Xpp3DomBuilder.build( new InputStreamReader(
161 new FileInputStream( new File( basedir,
162 "project-rad-2/.websettings" ) ),
163 "UTF-8" ) );
164
165 assertEquals( "project-rad-5_4.jar",
166 websettings.getChild( "lib-modules" ).getChild( "lib-module" ).getChild( "jar" ).getValue() );
167 assertEquals( "project-rad-5_4",
168 websettings.getChild( "lib-modules" ).getChild( "lib-module" ).getChild( "project" ).getValue() );
169 }
170
171 public void testProject6()
172 throws Exception
173 {
174 testProject( "project-rad-6", new Properties(), "rad-clean", "rad" );
175 }
176
177
178
179
180
181
182
183 public void testProject7()
184 throws Exception
185 {
186 testProject( "project-rad-7", new Properties(), "rad-clean", "rad" );
187
188
189
190
191 File basedir = getTestFile( "target/test-classes/projects/project-rad-7" );
192 File pom = new File( basedir, "pom.xml" );
193 MavenProject project = readProject( pom );
194 File outputDir;
195 File projectOutputDir = basedir;
196
197 String outputDirPath =
198 IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
199 if ( outputDirPath == null )
200 {
201 outputDir = basedir;
202 }
203 else
204 {
205 outputDir = new File( basedir, outputDirPath );
206 outputDir.mkdirs();
207 projectOutputDir = new File( outputDir, project.getArtifactId() );
208 }
209
210 compareDirectoryContent( basedir, projectOutputDir );
211 assertFalse( "Default path should not exist because it is overridden!",
212 new File( basedir + "/src/main/webapp" ).exists() );
213
214 }
215
216 public void testProject8()
217 throws Exception
218 {
219 testProject( "project-rad-8", new Properties(), "rad-clean", "rad" );
220 File generatedManifest = getTestFile( PROJECTS_BASEDIR + "/project-rad-8/src/main/webapp/META-INF/MANIFEST.MF" );
221 File expectedManifest =
222 getTestFile( PROJECTS_BASEDIR + "/project-rad-8/src/main/webapp/META-INF/expected_MANIFEST.MF" );
223 assertFileEquals( expectedManifest, generatedManifest );
224
225 }
226 }