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;
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.ide.IdeUtils;
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.plexus.util.FileUtils;
31  import org.codehaus.plexus.util.xml.Xpp3Dom;
32  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
33  
34  
35  
36  
37  public class RadPluginTest
38      extends AbstractEclipsePluginTestCase
39  {
40  
41      private static final String PROJECTS_BASEDIR = "target/test-classes/projects";
42  
43      public void testProject1()
44          throws Exception
45      {
46          testProject( "project-rad-1", new Properties(), "rad-clean", "rad" );
47      }
48  
49      
50  
51  
52  
53  
54  
55  
56  
57      public void testProject3()
58          throws Exception
59      {
60          testProject( "project-rad-3", new Properties(), "rad-clean", "rad" );
61          File generatedManifest = getTestFile( PROJECTS_BASEDIR + "/project-rad-3/ejbModule/META-INF/MANIFEST.MF" );
62          File expectedManifest =
63              getTestFile( PROJECTS_BASEDIR + "/project-rad-3/ejbModule/META-INF/expected_MANIFEST.MF" );
64          assertFileEquals( localRepositoryDirectory.getCanonicalPath(), expectedManifest, generatedManifest );
65      }
66  
67      public void testProject4()
68          throws Exception
69      {
70          testProject( "project-rad-4", new Properties(), "rad-clean", "rad" );
71      }
72  
73      public void testProject5()
74          throws Exception
75      {
76          File basedir = getTestFile( "target/test-classes/projects/project-rad-5" );
77  
78          FileUtils.deleteDirectory( new File( basedir, "project-rad-1/META-INF" ) );
79          new File( basedir, "project-rad-1/META-INF" ).mkdirs();
80  
81          File pom0 = new File( basedir, "pom.xml" );
82  
83          MavenProject project = readProject( pom0 );
84  
85          String outputDirPath =
86              IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
87          File outputDir;
88  
89          if ( outputDirPath == null )
90          {
91              outputDir = basedir;
92          }
93          else
94          {
95              outputDir = new File( basedir, outputDirPath );
96              outputDir.mkdirs();
97              new File( outputDir, project.getArtifactId() );
98          }
99  
100         List goals = new ArrayList();
101 
102         String pluginSpec = getPluginCLISpecification();
103 
104         goals.add( pluginSpec + "rad-clean" );
105         goals.add( pluginSpec + "rad" );
106         goals.add( "install" );
107 
108         Properties props = new Properties();
109 
110         executeMaven( pom0, props, goals );
111 
112         
113         
114         
115         
116         
117         
118         
119         
120         
121         
122         
123         
124 
125         
126         assertTrue( "Expected file not found: project-rad-1/maven-core-98.0.jar",
127                     new File( basedir, "project-rad-1/maven-core-98.0.jar" ).exists() );
128 
129         Xpp3Dom applicationXml =
130             Xpp3DomBuilder.build( new InputStreamReader(
131                                                          new FileInputStream(
132                                                                               new File( basedir,
133                                                                                         "project-rad-1/META-INF/application.xml" ) ),
134                                                          "UTF-8" ) );
135 
136         Xpp3Dom modulesmapsXml =
137             Xpp3DomBuilder.build( new InputStreamReader(
138                                                          new FileInputStream(
139                                                                               new File( basedir,
140                                                                                         "project-rad-1/META-INF/.modulemaps" ) ),
141                                                          "UTF-8" ) );
142 
143         assertNotNull( modulesmapsXml );
144 
145         Xpp3Dom webappModule = applicationXml.getChildren( "module" )[0];
146         Xpp3Dom ejbModule = applicationXml.getChildren( "module" )[1];
147         if ( webappModule.getChild( "web" ) == null )
148         {
149             webappModule = applicationXml.getChildren( "module" )[1];
150             ejbModule = applicationXml.getChildren( "module" )[0];
151         }
152 
153         assertEquals( "project-rad-5_2.war", webappModule.getChild( "web" ).getChild( "web-uri" ).getValue() );
154         assertEquals( "project-rad-5_2", webappModule.getChild( "web" ).getChild( "context-root" ).getValue() );
155         assertEquals( "project-rad-5_3.jar", ejbModule.getChild( Constants.PROJECT_PACKAGING_EJB ).getValue() );
156 
157         Xpp3Dom websettings =
158             Xpp3DomBuilder.build( new InputStreamReader(
159                                                          new FileInputStream( new File( basedir,
160                                                                                         "project-rad-2/.websettings" ) ),
161                                                          "UTF-8" ) );
162 
163         assertEquals( "project-rad-5_4.jar",
164                       websettings.getChild( "lib-modules" ).getChild( "lib-module" ).getChild( "jar" ).getValue() );
165         assertEquals( "project-rad-5_4",
166                       websettings.getChild( "lib-modules" ).getChild( "lib-module" ).getChild( "project" ).getValue() );
167     }
168 
169     public void testProject5_2()
170         throws Exception
171     {
172         File basedir = getTestFile( "target/test-classes/projects/project-rad-5" );
173 
174         FileUtils.deleteDirectory( new File( basedir, "project-rad-1/META-INF" ) );
175 
176         File pom0 = new File( basedir, "pom.xml" );
177 
178         MavenProject project = readProject( pom0 );
179 
180         String outputDirPath =
181             IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
182         File outputDir;
183 
184         if ( outputDirPath == null )
185         {
186             outputDir = basedir;
187         }
188         else
189         {
190             outputDir = new File( basedir, outputDirPath );
191             outputDir.mkdirs();
192             new File( outputDir, project.getArtifactId() );
193         }
194 
195         List goals = new ArrayList();
196 
197         String pluginSpec = getPluginCLISpecification();
198 
199         goals.add( pluginSpec + "rad-clean" );
200         goals.add( pluginSpec + "rad" );
201 
202         Properties props = new Properties();
203 
204         executeMaven( pom0, props, goals );
205 
206         
207         
208         
209         
210         
211         
212         
213         
214         
215         
216         
217         
218         
219 
220         assertTrue( "Expected file not found: project-rad-1/maven-core-98.0.jar",
221                     new File( basedir, "project-rad-1/maven-core-98.0.jar" ).exists() );
222 
223         File modulemaps = new File( basedir, "project-rad-1/META-INF/.modulemaps" );
224 
225         assertNotNull( modulemaps );
226 
227         File application = new File( basedir, "project-rad-1/META-INF/application.xml" );
228 
229         Xpp3Dom applicationXml =
230             Xpp3DomBuilder.build( new InputStreamReader( new FileInputStream( application ), "UTF-8" ) );
231 
232         Xpp3Dom[] children = applicationXml.getChildren( "module" );
233 
234         assertEquals( 2, children.length );
235 
236         boolean ejbVerified = false;
237         boolean warVerified = false;
238 
239         for ( int i = 0; i < children.length; i++ )
240         {
241             Xpp3Dom child = children[i];
242 
243             if ( child.getAttribute( "id" ).startsWith( "WebModule_" ) )
244             {
245                 assertEquals( "project-rad-5_2.war", child.getChild( "web" ).getChild( "web-uri" ).getValue() );
246                 warVerified = true;
247             }
248             else if ( child.getAttribute( "id" ).startsWith( "EjbModule_" ) )
249             {
250                 assertEquals( "project-rad-5_3.jar", child.getChild( Constants.PROJECT_PACKAGING_EJB ).getValue() );
251                 ejbVerified = true;
252             }
253         }
254 
255         assertTrue( warVerified );
256         assertTrue( ejbVerified );
257     }
258 
259     public void testProject6()
260         throws Exception
261     {
262         testProject( "project-rad-6", new Properties(), "rad-clean", "rad" );
263     }
264 
265     
266 
267 
268 
269 
270 
271     public void testProject7()
272         throws Exception
273     {
274         testProject( "project-rad-7", new Properties(), "rad-clean", "rad" );
275 
276         
277 
278 
279         File basedir = getTestFile( "target/test-classes/projects/project-rad-7" );
280         File pom = new File( basedir, "pom.xml" );
281         MavenProject project = readProject( pom );
282         File outputDir;
283         File projectOutputDir = basedir;
284 
285         String outputDirPath =
286             IdeUtils.getPluginSetting( project, "org.apache.maven.plugins:maven-eclipse-plugin", "outputDir", null );
287         if ( outputDirPath == null )
288         {
289             outputDir = basedir;
290         }
291         else
292         {
293             outputDir = new File( basedir, outputDirPath );
294             outputDir.mkdirs();
295             projectOutputDir = new File( outputDir, project.getArtifactId() );
296         }
297 
298         compareDirectoryContent( basedir, projectOutputDir, "WebContent/WEB-INF/lib/" );
299         compareDirectoryContent( basedir, projectOutputDir, "WebContent/META-INF/" );
300         assertFalse( "Default path should not exist because it is overridden!",
301                      new File( basedir + "/src/main/webapp" ).exists() );
302 
303     }
304 
305 }