1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.eclipse;
20  
21  import java.io.File;
22  import java.io.FileNotFoundException;
23  import java.io.FileReader;
24  import java.io.IOException;
25  import java.util.ArrayList;
26  import java.util.List;
27  import java.util.Properties;
28  
29  import org.apache.maven.plugin.MojoExecutionException;
30  import org.codehaus.plexus.util.xml.Xpp3Dom;
31  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
32  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
33  
34  /**
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
37   * @version $Id: EclipsePluginTest.java 599668 2007-11-30 01:41:23Z aheritier $
38   */
39  public class EclipsePluginTest
40      extends AbstractEclipsePluginTestCase
41  {
42      protected void setUp()
43          throws Exception
44      {
45          super.setUp();
46      }
47  
48      public void testProject01()
49          throws Exception
50      {
51          testProject( "project-01" );
52      }
53  
54      public void testProject02()
55          throws Exception
56      {
57          testProject( "project-02" );
58      }
59  
60      public void testProject03()
61          throws Exception
62      {
63          testProject( "project-03" );
64      }
65  
66      public void testProject04()
67          throws Exception
68      {
69          testProject( "project-04" );
70      }
71  
72      public void testProject05()
73          throws Exception
74      {
75          testProject( "project-05" );
76      }
77  
78      public void testProject06()
79          throws Exception
80      {
81          testProject( "project-06" );
82      }
83  
84      // @TODO temporarily disabled, since it randomly fails due to a different order for dependencies in classpath and
85      // wtpmodules. This is not a problem, since order could be ignored in this test, but we should rewrite the
86      // file-comparing
87      // step which at the moment just does line by line comparison
88      // public void testProject07()
89      // throws Exception
90      // {
91      // testProject( "project-07" );
92      // }
93  
94      public void testProject08()
95          throws Exception
96      {
97          testProject( "project-08" );
98      }
99  
100     /**
101      * Tests with <code>outputDirectory</code> and <code>outputDir</code>
102      * 
103      * @throws Exception
104      */
105     public void testProject09()
106         throws Exception
107     {
108         testProject( "project-09" );
109     }
110 
111     public void testProject10()
112         throws Exception
113     {
114         testProject( "project-10" );
115     }
116 
117     public void testProject11()
118         throws Exception
119     {
120         testProject( "project-11" );
121     }
122 
123     /**
124      * Ear packaging
125      * 
126      * @throws Exception any exception thrown during test
127      */
128     public void testProject12()
129         throws Exception
130     {
131         testProject( "project-12" );
132     }
133 
134     /**
135      * Dependency range - MECLIPSE-96
136      * 
137      * @throws Exception any exception thrown during test
138      */
139     public void testProject13()
140         throws Exception
141     {
142         testProject( "project-13" );
143     }
144 
145     /**
146      * Additional natures and builders - MECLIPSE-64
147      * 
148      * @throws Exception any exception thrown during test
149      */
150     public void testProject14()
151         throws Exception
152     {
153         testProject( "project-14" );
154     }
155 
156     /**
157      * <code>outputDirectory</code> parameter - MECLIPSE-11
158      * 
159      * @throws Exception any exception thrown during test
160      */
161     public void testProject15()
162         throws Exception
163     {
164         Properties props = new Properties();
165         props.put( "outputDirectory", "bin" );
166         testProject( "project-15", props, "clean", "eclipse" );
167     }
168 
169     // Commented out: failing due to MNG-2025
170     // /**
171     // * UTF8 encoding - MECLIPSE-56
172     // * @throws Exception any exception thrown during test
173     // */
174     // public void testProject16()
175     // throws Exception
176     // {
177     // testProject( "project-16" );
178     // }
179 
180     // Commented out: failing on Continuum, due to MNG-2025 too?
181     // /**
182     // * ISO-8859-15 encoding - MECLIPSE-56
183     // * @throws Exception any exception thrown during test
184     // */
185     // public void testProject17()
186     // throws Exception
187     // {
188     // testProject( "project-17" );
189     // }
190 
191     /**
192      * relative location of system dependencies - MECLIPSE-89
193      * 
194      * @throws Exception any exception thrown during test
195      */
196     public void testProject18()
197         throws Exception
198     {
199         testProject( "project-18" );
200     }
201 
202     /**
203      * Resource targetPath is relative to the project's output directory - MECLIPSE-77
204      * 
205      * @throws Exception any exception thrown during test
206      */
207     public void testProject19()
208         throws Exception
209     {
210         testProject( "project-19" );
211     }
212 
213     /**
214      * WTP 1.5 changes in wtpmodules.
215      * 
216      * @throws Exception any exception thrown during test
217      */
218     public void testProject20()
219         throws Exception
220     {
221         testProject( "project-20" );
222     }
223 
224     /**
225      * PDE support.
226      * 
227      * @throws Exception any exception thrown during test
228      */
229     public void testProject21()
230         throws Exception
231     {
232         testProject( "project-21" );
233     }
234 
235     /**
236      * PDE support using eclipse-plugin packaging.
237      * 
238      * @throws Exception any exception thrown during test
239      */
240     public void testProject22()
241         throws Exception
242     {
243         testProject( "project-22" );
244     }
245 
246     /**
247      * Additional config files using "additionalConfig" property.
248      * 
249      * @throws Exception any exception thrown during test
250      */
251     public void testProject23()
252         throws Exception
253     {
254         testProject( "project-23" );
255     }
256 
257     /**
258      * Test rewriting of OSGI manifest files.
259      * 
260      * @throws Exception any exception thrown during test
261      */
262     public void testProject24()
263         throws Exception
264     {
265         testProject( "project-24" );
266     }
267 
268     /**
269      * Test source exclude/include.
270      * 
271      * @throws Exception any exception thrown during test
272      */
273     public void testProject25()
274         throws Exception
275     {
276         testProject( "project-25" );
277     }
278 
279     /**
280      * Test different compiler settings for test sources.
281      * 
282      * @throws Exception any exception thrown during test
283      */
284     public void testProject26()
285         throws Exception
286     {
287         testProject( "project-26" );
288     }
289 
290     /**
291      * Test additional project facets specified.
292      * 
293      * @throws Exception any exception thrown during test
294      */
295     public void testProject27()
296         throws Exception
297     {
298         testProject( "project-27" );
299     }
300 
301     /**
302      * MECLIPSE-241 : Compiler settings from parent project aren't used in wtp facet.
303      * 
304      * @throws Exception any exception thrown during test
305      */
306     public void testProject28()
307         throws Exception
308     {
309         testProject( "project-28/module-1" );
310     }
311 
312     /**
313      * MECLIPSE-198 : EJB version is not resloved
314      * 
315      * @throws Exception any exception thrown during test
316      */
317     public void testProject29()
318         throws Exception
319     {
320         testProject( "project-29" );
321     }
322 
323     /**
324      * MECLIPSE-108 : .wtpmodules with version 2.4 for javax.servlet:servlet-api:2.3
325      * 
326      * @throws Exception any exception thrown during test
327      */
328     public void testProject30()
329         throws Exception
330     {
331         testProject( "project-30" );
332     }
333 
334     /**
335      * MECLIPSE-185 : plugin doesn't fail when dependencies are missing
336      * 
337      * @throws Exception any exception thrown during test
338      */
339     public void testProject31()
340         throws Exception
341     {
342         try
343         {
344             testProject( "project-31" );
345 
346             // disabling this test for now. See comments in MECLIPSE-185 - Bfox
347             // fail("Expected to receive a MojoExecutionException");
348         }
349         catch ( MojoExecutionException e )
350         {
351             // expected exception here
352         }
353     }
354 
355     /**
356      * MECLIPSE-109 : .component wb-resource source path incorrect for ear packaging
357      * 
358      * @throws Exception any exception thrown during test
359      */
360     public void testProject32()
361         throws Exception
362     {
363         testProject( "project-32" );
364     }
365 
366     public void testProject34()
367         throws Exception
368     {
369         testProject( "project-34" );
370     }
371 
372     public void testProject35()
373         throws Exception
374     {
375         testProject( "project-35" );
376 
377         File basedir = getTestFile( "target/test-classes/projects/project-35" );
378 
379         checkContextRoot( basedir, "multymodule-war", "multymodule-ear", "/somethingVeryDifferent" );
380 
381         FileReader reader =
382             new FileReader( new File( basedir, "multymodule-war/.settings/org.eclipse.wst.common.component" ) );
383         Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
384         Xpp3Dom[] dependentModules = warComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
385         assertEquals( 2, dependentModules.length );
386         for ( int index = 0; index < dependentModules.length; index++ )
387         {
388             assertEquals( "/WEB-INF/lib", dependentModules[index].getAttribute( "deploy-path" ) );
389         }
390 
391         reader = new FileReader( new File( basedir, "multymodule-ear/.settings/org.eclipse.wst.common.component" ) );
392         Xpp3Dom earComponent = Xpp3DomBuilder.build( reader );
393         dependentModules = earComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
394         assertEquals( 2, dependentModules.length );
395         for ( int index = 0; index < dependentModules.length; index++ )
396         {
397             if ( dependentModules[index].getAttribute( "archiveName" ).endsWith( "war" ) )
398             {
399                 assertEquals( "/", dependentModules[index].getAttribute( "deploy-path" ) );
400                 assertTrue( !dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
401             }
402             else
403             {
404                 assertEquals( "lib", dependentModules[index].getAttribute( "deploy-path" ) );
405                 assertTrue( dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
406             }
407         }
408     }
409 
410     public void testProject36()
411         throws Exception
412     {
413         // Install artefacts
414         File basedir = getTestFile( "target/test-classes/projects/project-36" );
415         File pom = new File( basedir, "pom.xml" );
416         List goals = new ArrayList();
417         goals.add( "install" );
418         executeMaven( pom, new Properties(), goals );
419         // Test
420         testProject( "project-36" );
421     }
422 
423     public void testProject37()
424         throws Exception
425     {
426         testProject( "project-37" );
427     }
428 
429     public void testProject38()
430         throws Exception
431     {
432         testProject( "project-38" );
433     }
434 
435     public void testJeeSimple()
436         throws Exception
437     {
438         // Install artefacts
439         File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
440         File pom = new File( basedir, "pom.xml" );
441         List goals = new ArrayList();
442         goals.add( "install" );
443         executeMaven( pom, new Properties(), goals );
444         // Test project
445         testProject( "j2ee-simple" );
446         checkContextRoot( basedir, "servlets/servlet", "ear", "servlet" );
447 
448     }
449 
450     private void checkContextRoot( File basedir, String warModule, String earModule, String expectedContextRoot )
451         throws FileNotFoundException, XmlPullParserException, IOException
452     {
453         FileReader reader =
454             new FileReader( new File( basedir, warModule + "/.settings/org.eclipse.wst.common.component" ) );
455         Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
456         Xpp3Dom[] properties = warComponent.getChild( "wb-module" ).getChildren( "property" );
457         boolean contextRootAvaliable = false;
458         for ( int index = 0; index < properties.length; index++ )
459         {
460             if ( properties[index].getAttribute( "name" ).equals( "context-root" ) )
461             {
462                 assertEquals( "Context root detection in org.eclipse.wst.common.component", expectedContextRoot,
463                               properties[index].getAttribute( "value" ) );
464                 contextRootAvaliable = true;
465             }
466         }
467         assertTrue( "there must be a context root here", contextRootAvaliable );
468 
469         reader = new FileReader( new File( basedir, earModule + "/target/eclipseEar/META-INF/application.xml" ) );
470         Xpp3Dom generatedApplicationXML = Xpp3DomBuilder.build( reader );
471 
472         Xpp3Dom[] modules = generatedApplicationXML.getChildren( "module" );
473         for ( int index = 0; index < modules.length; index++ )
474         {
475             if ( modules[index].getChild( "web" ) != null )
476             {
477                 assertEquals( "Context root detection in target/eclipseEar/META-INF/application.xml",
478                               expectedContextRoot,
479                               modules[index].getChild( "web" ).getChild( "context-root" ).getValue() );
480             }
481         }
482     }
483     /**
484      * MECLIPSE-287 : dependencies with and without classifiers MECLIPSE-151 : test jar source attachments
485      * 
486      * @throws Exception any exception thrown during test
487      */
488     /*
489      * @TODO temporarily disabled, since it randomly fails due to a different order for dependencies in classpath and
490      * wtpmodules. This is not a problem, since order could be ignored in this test, but we should rewrite the
491      * file-comparing step which at the moment just does line by line comparison project 7 is affected by this as well.
492      * public void testProject33() throws Exception { testProject( "project-33" ); }
493      */
494 
495     /*
496      * TODO: Add a test for downloadJavadocs. Currently, eclipse doesn't support having variables in the javadoc path.
497      * This means that the expected .classpath can't match the final result as the result will have the absolute path to
498      * the user's local repo.
499      */
500 }