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.it;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.Properties;
25  
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.eclipse.TempEclipseWorkspace;
28  
29  /**
30   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
31   * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
32   * @version $Id: EclipsePluginIT.java 819238 2009-09-27 00:19:02Z aheritier $
33   */
34  public class EclipsePluginIT
35      extends AbstractEclipsePluginIT
36  {
37      protected void setUp()
38          throws Exception
39      {
40          super.setUp();
41      }
42  
43      /**
44       * Assumes that unit tests (ReadWorkspaceLocationsTest) have been run so that .location files have been created
45       * correctly.
46       */
47      public void testDynamicWorkspaceLookup()
48          throws Exception
49      {
50          File basedir =
51              new File( TempEclipseWorkspace.getFixtureEclipseDynamicWorkspace().workspaceLocation, "project-Z" );
52          testProject( basedir );
53      }
54  
55      public void testProject01()
56          throws Exception
57      {
58          testProject( "project-01" );
59      }
60  
61      public void testProject02()
62          throws Exception
63      {
64          testProject( "project-02" );
65      }
66  
67      public void testProject03()
68          throws Exception
69      {
70          testProject( "project-03" );
71      }
72  
73      public void testProject04()
74          throws Exception
75      {
76          testProject( "project-04" );
77      }
78  
79      public void testProject05()
80          throws Exception
81      {
82          testProject( "project-05" );
83      }
84  
85      public void testProject06()
86          throws Exception
87      {
88          testProject( "project-06" );
89      }
90  
91      /**
92       * @throws Exception
93       */
94      public void testProject07()
95          throws Exception
96      {
97          // Fails because of MECLIPSE-367
98          testProject( "project-07" );
99      }
100 
101     public void testProject08()
102         throws Exception
103     {
104         testProject( "project-08" );
105     }
106 
107     /**
108      * Tests with <code>outputDirectory</code> and <code>outputDir</code>
109      * 
110      * @throws Exception
111      */
112     public void testProject09()
113         throws Exception
114     {
115         testProject( "project-09" );
116     }
117 
118     public void testProject10()
119         throws Exception
120     {
121         testProject( "project-10" );
122     }
123 
124     public void testProject11()
125         throws Exception
126     {
127         testProject( "project-11" );
128     }
129 
130     /**
131      * Ear packaging
132      * 
133      * @throws Exception any exception thrown during test
134      */
135     public void testProject12()
136         throws Exception
137     {
138         testProject( "project-12" );
139     }
140 
141     /**
142      * Dependency range - MECLIPSE-96
143      * 
144      * @throws Exception any exception thrown during test
145      */
146     public void testProject13()
147         throws Exception
148     {
149         testProject( "project-13" );
150     }
151 
152     /**
153      * Additional natures and builders - MECLIPSE-64
154      * 
155      * @throws Exception any exception thrown during test
156      */
157     public void testProject14()
158         throws Exception
159     {
160         testProject( "project-14" );
161     }
162 
163     /**
164      * <code>outputDirectory</code> parameter - MECLIPSE-11
165      * 
166      * @throws Exception any exception thrown during test
167      */
168     public void testProject15()
169         throws Exception
170     {
171         Properties props = new Properties();
172         props.put( "outputDirectory", "bin" );
173         testProject( "project-15", props, "clean", "eclipse" );
174     }
175 
176     /**
177      * UTF8 encoding - MECLIPSE-56
178      * 
179      * @throws Exception any exception thrown during test
180      */
181     public void testProject16()
182         throws Exception
183     {
184         // failing with maven < 2.0.8 due to MNG-2025
185         testProject( "project-16" );
186     }
187 
188     /**
189      * ISO-8859-15 encoding - MECLIPSE-56
190      * 
191      * @throws Exception any exception thrown during test
192      */
193     public void testProject17()
194         throws Exception
195     {
196         // failing with maven < 2.0.8 due to MNG-2025
197         testProject( "project-17" );
198     }
199 
200     /**
201      * relative location of system dependencies - MECLIPSE-89
202      * 
203      * @throws Exception any exception thrown during test
204      */
205     public void testProject18()
206         throws Exception
207     {
208         testProject( "project-18" );
209     }
210 
211     /**
212      * Resource targetPath is relative to the project's output directory - MECLIPSE-77
213      * 
214      * @throws Exception any exception thrown during test
215      */
216     public void testProject19()
217         throws Exception
218     {
219         testProject( "project-19" );
220     }
221 
222     /**
223      * WTP 1.5 changes in wtpmodules.
224      * 
225      * @throws Exception any exception thrown during test
226      */
227     public void testProject20()
228         throws Exception
229     {
230         testProject( "project-20" );
231     }
232 
233     /**
234      * PDE support.
235      * 
236      * @throws Exception any exception thrown during test
237      */
238     public void testProject21()
239         throws Exception
240     {
241         testProject( "project-21" );
242     }
243 
244     /**
245      * PDE support using eclipse-plugin packaging.
246      * 
247      * @throws Exception any exception thrown during test
248      */
249     public void testProject22()
250         throws Exception
251     {
252         testProject( "project-22" );
253     }
254 
255     /**
256      * Additional config files using "additionalConfig" property.
257      * 
258      * @throws Exception any exception thrown during test
259      */
260     public void testProject23()
261         throws Exception
262     {
263         testProject( "project-23" );
264     }
265 
266     /**
267      * Test rewriting of OSGI manifest files.
268      * 
269      * @throws Exception any exception thrown during test
270      */
271     public void testProject24()
272         throws Exception
273     {
274         testProject( "project-24" );
275     }
276 
277     /**
278      * Test source exclude/include.
279      * 
280      * @throws Exception any exception thrown during test
281      */
282     public void testProject25()
283         throws Exception
284     {
285         testProject( "project-25" );
286     }
287 
288     /**
289      * Test different compiler settings for test sources.
290      * 
291      * @throws Exception any exception thrown during test
292      */
293     public void testProject26()
294         throws Exception
295     {
296         testProject( "project-26" );
297     }
298 
299     /**
300      * Test additional project facets specified.
301      * 
302      * @throws Exception any exception thrown during test
303      */
304     public void testProject27()
305         throws Exception
306     {
307         testProject( "project-27" );
308     }
309 
310     /**
311      * MECLIPSE-241 : Compiler settings from parent project aren't used in wtp facet.
312      * 
313      * @throws Exception any exception thrown during test
314      */
315     public void testProject28()
316         throws Exception
317     {
318         testProject( "project-28/module-1" );
319     }
320 
321     /**
322      * MECLIPSE-198 : EJB version is not resloved
323      * 
324      * @throws Exception any exception thrown during test
325      */
326     public void testProject29()
327         throws Exception
328     {
329         testProject( "project-29" );
330     }
331 
332     /**
333      * MECLIPSE-108 : .wtpmodules with version 2.4 for javax.servlet:servlet-api:2.3
334      * 
335      * @throws Exception any exception thrown during test
336      */
337     public void testProject30()
338         throws Exception
339     {
340         testProject( "project-30" );
341     }
342 
343     /**
344      * MECLIPSE-185 : plugin doesn't fail when dependencies are missing
345      * 
346      * @throws Exception any exception thrown during test
347      */
348     public void testProject31()
349         throws Exception
350     {
351         try
352         {
353             testProject( "project-31" );
354 
355             // TODO: disabling this test for now. See comments in MECLIPSE-185 - Bfox
356             // fail("Expected to receive a MojoExecutionException");
357         }
358         catch ( MojoExecutionException e )
359         {
360             // expected exception here
361         }
362     }
363 
364     /**
365      * MECLIPSE-109 : .component wb-resource source path incorrect for ear packaging
366      * 
367      * @throws Exception any exception thrown during test
368      */
369     public void testProject32()
370         throws Exception
371     {
372         testProject( "project-32" );
373     }
374 
375     /**
376      * MECLIPSE-287 : dependencies with and without classifiers. MECLIPSE-151 : test jar source attachments.
377      * MECLIPSE-367 : Dependency to artifact with classifier tests not distinguished from the regular artifact
378      * 
379      * @throws Exception any exception thrown during test
380      */
381     public void testProject33()
382         throws Exception
383     {
384         testProject( "project-33" );
385     }
386 
387     public void testProject34()
388         throws Exception
389     {
390         testProject( "project-34" );
391     }
392 
393     public void testProject35()
394         throws Exception
395     {
396         testProject( "project-35" );
397     }
398 
399     public void testProject36()
400         throws Exception
401     {
402         // Install artefacts
403         File basedir = getTestFile( "target/test-classes/projects/project-36" );
404         File pom = new File( basedir, "pom.xml" );
405         List goals = new ArrayList();
406         goals.add( "install" );
407         executeMaven( pom, new Properties(), goals );
408         // Test
409         testProject( "project-36" );
410     }
411 
412     public void testProject37()
413         throws Exception
414     {
415         testProject( "project-37" );
416     }
417 
418     /**
419      * MECLIPSE-56 : problem with encoding of non-ascii characters in pom.xml
420      */
421     public void testMECLIPSE_56_encoding()
422         throws Exception
423     {
424         testProject( "MECLIPSE-56_encoding" );
425     }
426 
427     public void testProject38()
428         throws Exception
429     {
430         testProject( "project-38" );
431     }
432 
433     public void testProject39_a()
434         throws Exception
435     {
436         checkJRESettingsWithEclipseWorkspace( "project-39-a", TempEclipseWorkspace.getFixtureEclipseWithDefault13(),
437                                               null );
438     }
439 
440     public void testProject39_b()
441         throws Exception
442     {
443         checkJRESettingsWithEclipseWorkspace( "project-39-b", TempEclipseWorkspace.getFixtureEclipseWithDefault15(),
444                                               null );
445     }
446 
447     public void testProject39_c()
448         throws Exception
449     {
450         checkJRESettingsWithEclipseWorkspace( "project-39-c",
451                                               TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14(), null );
452     }
453 
454     public void testProject40_a()
455         throws Exception
456     {
457         String jre131 = new java.io.File( "target/test-classes/eclipse/dummyJDK/1.3.1/bin/javac" ).getCanonicalPath();
458         checkJRESettingsWithEclipseWorkspace( "project-40-a", TempEclipseWorkspace.getFixtureEclipseWithDefault13(),
459                                               jre131 );
460     }
461 
462     public void testProject40_b()
463         throws Exception
464     {
465         String jre131 = new java.io.File( "target/test-classes/eclipse/dummyJDK/1.3.1/bin/javac" ).getCanonicalPath();
466         checkJRESettingsWithEclipseWorkspace( "project-40-b", TempEclipseWorkspace.getFixtureEclipseWithDefault15(),
467                                               jre131 );
468     }
469 
470     public void testProject40_c()
471         throws Exception
472     {
473         String jre131 = new java.io.File( "target/test-classes/eclipse/dummyJDK/1.3.1/bin/javac" ).getCanonicalPath();
474         checkJRESettingsWithEclipseWorkspace( "project-40-c",
475                                               TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14(),
476                                               jre131 );
477     }
478 
479     public void testProject41()
480         throws Exception
481     {
482         TempEclipseWorkspace rad7 = TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14();
483         Properties properties = new Properties();
484         properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
485         testProject( "project-41", properties, "clean", "eclipse" );
486 
487     }
488 
489     public void testProject42()
490         throws Exception
491     {
492         TempEclipseWorkspace rad7 = TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14();
493         Properties properties = new Properties();
494         properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
495         testProject( "project-42", properties, "clean", "eclipse" );
496 
497     }
498 
499     /**
500      * [MECLIPSE-79]
501      * 
502      * @since 2.5
503      * @throws Exception
504      */
505     public void testProject43()
506         throws Exception
507     {
508         testProject( "project-43" );
509     }
510 
511     /**
512      * [MECLIPSE-219]
513      * 
514      * @since 2.5
515      * @throws Exception
516      */
517     public void testProject44()
518         throws Exception
519     {
520         testProject( "project-44" );
521     }
522 
523     /**
524      * [MECLIPSE-379] When downloading sources and javadocs dependency classifier is not respected.
525      * 
526      * @since 2.5
527      * @throws Exception
528      */
529     public void testProject45()
530         throws Exception
531     {
532         testProject( "project-45" );
533     }
534 
535     /**
536      * Test not available marker file is created for sources/javadocs. biz.aQute:bndlib:0.0.145 does not have sources or
537      * javadocs.
538      * 
539      * @throws Exception
540      */
541     public void testProject46()
542         throws Exception
543     {
544         testProject( "project-46" );
545         assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145", null, "sources" );
546         assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145", null, "javadoc" );
547     }
548 
549     /**
550      * Test not available marker file is created for sources/javadocs. commons-lang:commons-lang:1.0 does not have
551      * sources but does have javadocs.
552      * 
553      * @throws Exception
554      */
555     public void testProject47()
556         throws Exception
557     {
558         testProject( "project-47" );
559         assertNotAvailableMarkerFileExists( "commons-lang", "commons-lang", "1.0", null, "sources" );
560         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "1.0", null, "javadoc" );
561     }
562 
563     /**
564      * Test not available marker file is created for sources/javadocs. does-not-exist:does-not-exist:666 doesn't exist
565      * so no markers should be created.
566      * 
567      * @throws Exception
568      */
569     public void testProject48()
570         throws Exception
571     {
572         testProject( "project-48" );
573         assertNotAvailableMarkerFileDoesNotExist( "does-not-exist", "does-not-exist", "666", null, "sources" );
574         assertNotAvailableMarkerFileDoesNotExist( "does-not-exist", "does-not-exist", "666", null, "javadoc" );
575     }
576 
577     /**
578      * Test forceRecheck
579      * 
580      * @throws Exception
581      */
582     public void testProject49()
583         throws Exception
584     {
585         File notAvailableMarkerFile =
586             getNotAvailableMarkerFile( "commons-lang", "commons-lang", "2.4", null, "sources" );
587         notAvailableMarkerFile.getParentFile().mkdirs();
588         notAvailableMarkerFile.createNewFile();
589         getNotAvailableMarkerFile( "commons-lang", "commons-lang", "2.4", null, "javadoc" ).createNewFile();
590 
591         testProject( "project-49" );
592         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "2.4", null, "sources" );
593         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "2.4", null, "javadoc" );
594     }
595 
596     /**
597      * [MECLIPSE-415] settings are stored in wrong directory if project is not in the workspace.
598      * 
599      * @throws Exception
600      */
601     public void testProject50MECLIPSE415()
602         throws Exception
603     {
604         testProject( "project-50-MECLIPSE-415" );
605     }
606 
607     /**
608      * [MECLIPSE-415] settings are stored in wrong directory if project is not in the workspace.
609      * 
610      * @throws Exception
611      */
612     public void testProject51MECLIPSE415()
613         throws Exception
614     {
615         testProject( "project-51-MECLIPSE-415" );
616     }
617 
618     /**
619      * [MECLIPSE-104] Add the ability to specify source exclusions
620      * 
621      * @throws Exception
622      */
623     public void testProject52MECLIPSE104()
624         throws Exception
625     {
626         testProject( "project-52-MECLIPSE-104" );
627     }
628 
629     /**
630      * [MECLIPSE-551] Source directory and resource directory are the same
631      * 
632      * @throws Exception
633      */
634     public void testProject53MECLIPSE551()
635         throws Exception
636     {
637         testProject( "project-53-MECLIPSE-551" );
638     }
639 
640     /**
641      * [MECLIPSE-178] symbolic links need to able to be specified in the pom
642      * 
643      * @throws Exception
644      */
645     public void testProject54MECLIPSE178()
646         throws Exception
647     {
648         testProject( "project-54-MECLIPSE-178" );
649     }
650 
651     /**
652      * [MECLIPSE-178] symbolic links need to able to be specified in the pom Test the case where a link is already
653      * existing in the .project
654      * 
655      * @throws Exception
656      */
657     public void testProject55MECLIPSE178()
658         throws Exception
659     {
660         testProject( "project-55-MECLIPSE-178" );
661     }
662 
663     /**
664      * [MECLIPSE-603] checks exclusions on direct and transitive dependencies
665      * 
666      * @throws Exception
667      */
668     public void testProject56()
669         throws Exception
670     {
671         testProject( "project-56-MECLIPSE-603" );
672     }
673 
674     /**
675      * [MECLIPSE-368] Dependency configuration in DependencyManagement with exclusions is ignored
676      * 
677      * @throws Exception
678      */
679     public void testProject57()
680         throws Exception
681     {
682         testProject( "project-57-MECLIPSE-368" );
683     }
684 
685     public void testJeeSimple()
686         throws Exception
687     {
688         // Install artefacts
689         File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
690         File pom = new File( basedir, "pom.xml" );
691         List goals = new ArrayList();
692         goals.add( "install" );
693         executeMaven( pom, new Properties(), goals );
694         // Test project
695         testProject( "j2ee-simple" );
696     }
697 
698     private void checkJRESettingsWithEclipseWorkspace( String project, TempEclipseWorkspace workspace, String jreExec )
699         throws Exception
700     {
701         Properties properties = new Properties();
702         properties.setProperty( "eclipse.workspace", workspace.workspaceLocation.getCanonicalPath() );
703         if ( jreExec != null )
704         {
705             properties.setProperty( "maven.compiler.executable", jreExec );
706         }
707         testProject( project, properties, "clean", "eclipse" );
708     }
709 
710 }