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