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.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.apache.maven.plugin.eclipse.TempEclipseWorkspace;
31  import org.codehaus.plexus.util.xml.Xpp3Dom;
32  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
33  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
34  
35  
36  
37  
38  
39  
40  public class EclipsePluginIT
41      extends AbstractEclipsePluginIT
42  {
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47      }
48  
49      
50  
51  
52  
53      public void testDynamicWorkspaceLookup()
54          throws Exception
55      {
56          File basedir = new File(TempEclipseWorkspace.getFixtureEclipseDynamicWorkspace().workspaceLocation, "project-Z");
57          testProject( basedir );
58      }
59  
60      public void testProject01()
61          throws Exception
62      {
63          testProject( "project-01" );
64      }
65  
66      public void testProject02()
67          throws Exception
68      {
69          testProject( "project-02" );
70      }
71  
72      public void testProject03()
73          throws Exception
74      {
75          testProject( "project-03" );
76      }
77  
78      public void testProject04()
79          throws Exception
80      {
81          testProject( "project-04" );
82      }
83  
84      public void testProject05()
85          throws Exception
86      {
87          testProject( "project-05" );
88      }
89  
90      public void testProject06()
91          throws Exception
92      {
93          testProject( "project-06" );
94      }
95  
96      
97  
98  
99      public void testProject07()
100         throws Exception
101     {
102         
103         testProject( "project-07" );
104     }
105 
106     public void testProject08()
107         throws Exception
108     {
109         testProject( "project-08" );
110     }
111 
112     
113 
114 
115 
116 
117     public void testProject09()
118         throws Exception
119     {
120         testProject( "project-09" );
121     }
122 
123     public void testProject10()
124         throws Exception
125     {
126         testProject( "project-10" );
127     }
128 
129     public void testProject11()
130         throws Exception
131     {
132         testProject( "project-11" );
133     }
134 
135     
136 
137 
138 
139 
140     public void testProject12()
141         throws Exception
142     {
143         testProject( "project-12" );
144     }
145 
146     
147 
148 
149 
150 
151     public void testProject13()
152         throws Exception
153     {
154         testProject( "project-13" );
155     }
156 
157     
158 
159 
160 
161 
162     public void testProject14()
163         throws Exception
164     {
165         testProject( "project-14" );
166     }
167 
168     
169 
170 
171 
172 
173     public void testProject15()
174         throws Exception
175     {
176         Properties props = new Properties();
177         props.put( "outputDirectory", "bin" );
178         testProject( "project-15", props, "clean", "eclipse" );
179     }
180 
181     
182 
183 
184 
185 
186     public void testProject16()
187         throws Exception
188     {
189         
190         testProject( "project-16" );
191     }
192 
193     
194 
195 
196 
197 
198     public void testProject17()
199         throws Exception
200     {
201         
202         testProject( "project-17" );
203     }
204 
205     
206 
207 
208 
209 
210     public void testProject18()
211         throws Exception
212     {
213         testProject( "project-18" );
214     }
215 
216     
217 
218 
219 
220 
221     public void testProject19()
222         throws Exception
223     {
224         testProject( "project-19" );
225     }
226 
227     
228 
229 
230 
231 
232     public void testProject20()
233         throws Exception
234     {
235         testProject( "project-20" );
236     }
237 
238     
239 
240 
241 
242 
243     public void testProject21()
244         throws Exception
245     {
246         testProject( "project-21" );
247     }
248 
249     
250 
251 
252 
253 
254     public void testProject22()
255         throws Exception
256     {
257         testProject( "project-22" );
258     }
259 
260     
261 
262 
263 
264 
265     public void testProject23()
266         throws Exception
267     {
268         testProject( "project-23" );
269     }
270 
271     
272 
273 
274 
275 
276     public void testProject24()
277         throws Exception
278     {
279         testProject( "project-24" );
280     }
281 
282     
283 
284 
285 
286 
287     public void testProject25()
288         throws Exception
289     {
290         testProject( "project-25" );
291     }
292 
293     
294 
295 
296 
297 
298     public void testProject26()
299         throws Exception
300     {
301         testProject( "project-26" );
302     }
303 
304     
305 
306 
307 
308 
309     public void testProject27()
310         throws Exception
311     {
312         testProject( "project-27" );
313     }
314 
315     
316 
317 
318 
319 
320     public void testProject28()
321         throws Exception
322     {
323         testProject( "project-28/module-1" );
324     }
325 
326     
327 
328 
329 
330 
331     public void testProject29()
332         throws Exception
333     {
334         testProject( "project-29" );
335     }
336 
337     
338 
339 
340 
341 
342     public void testProject30()
343         throws Exception
344     {
345         testProject( "project-30" );
346     }
347 
348     
349 
350 
351 
352 
353     public void testProject31()
354         throws Exception
355     {
356         try
357         {
358             testProject( "project-31" );
359 
360             
361             
362         }
363         catch ( MojoExecutionException e )
364         {
365             
366         }
367     }
368 
369     
370 
371 
372 
373 
374     public void testProject32()
375         throws Exception
376     {
377         testProject( "project-32" );
378     }
379 
380     
381 
382 
383 
384 
385 
386     public void testProject33()
387         throws Exception
388     {
389         testProject( "project-33" );
390     }
391 
392     public void testProject34()
393         throws Exception
394     {
395         testProject( "project-34" );
396     }
397 
398     public void testProject35()
399         throws Exception
400     {
401         testProject( "project-35" );
402 
403         File basedir = getTestFile( "target/test-classes/projects/project-35" );
404 
405         checkContextRoot( basedir, "multymodule-war", "multymodule-ear", "/somethingVeryDifferent" );
406 
407         FileReader reader =
408             new FileReader( new File( basedir, "multymodule-war/.settings/org.eclipse.wst.common.component" ) );
409         Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
410         Xpp3Dom[] dependentModules = warComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
411         assertEquals( 2, dependentModules.length );
412         for ( int index = 0; index < dependentModules.length; index++ )
413         {
414             assertEquals( "/WEB-INF/lib", dependentModules[index].getAttribute( "deploy-path" ) );
415         }
416 
417         reader = new FileReader( new File( basedir, "multymodule-ear/.settings/org.eclipse.wst.common.component" ) );
418         Xpp3Dom earComponent = Xpp3DomBuilder.build( reader );
419         dependentModules = earComponent.getChild( "wb-module" ).getChildren( "dependent-module" );
420         assertEquals( 2, dependentModules.length );
421         for ( int index = 0; index < dependentModules.length; index++ )
422         {
423             if ( dependentModules[index].getAttribute( "archiveName" ).endsWith( "war" ) )
424             {
425                 assertEquals( "/", dependentModules[index].getAttribute( "deploy-path" ) );
426                 assertTrue( !dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
427             }
428             else
429             {
430                 assertEquals( "lib", dependentModules[index].getAttribute( "deploy-path" ) );
431                 assertTrue( dependentModules[index].getAttribute( "archiveName" ).startsWith( ".." ) );
432             }
433         }
434     }
435 
436     public void testProject36()
437         throws Exception
438     {
439         
440         File basedir = getTestFile( "target/test-classes/projects/project-36" );
441         File pom = new File( basedir, "pom.xml" );
442         List goals = new ArrayList();
443         goals.add( "install" );
444         executeMaven( pom, new Properties(), goals );
445         
446         testProject( "project-36" );
447     }
448 
449     public void testProject37()
450         throws Exception
451     {
452         testProject( "project-37" );
453     }
454 
455     
456 
457 
458     public void testMECLIPSE_56_encoding()
459         throws Exception
460     {
461         testProject( "MECLIPSE-56_encoding" );
462     }
463 
464     public void testProject38()
465         throws Exception
466     {
467         testProject( "project-38" );
468     }
469 
470     public void testProject39()
471         throws Exception
472     {
473         checkJRESettingsWithEclipseWorkspace( "project-39", TempEclipseWorkspace.getFixtureEclipseWithDefault13(),
474                                               "", null );
475         checkJRESettingsWithEclipseWorkspace( "project-39", TempEclipseWorkspace.getFixtureEclipseWithDefault15(),
476                                               "J2SE-1.3", null );
477         checkJRESettingsWithEclipseWorkspace( "project-39", TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14(),
478                                               "J2SE-1.3", null );
479     }
480 
481     public void testProject40()
482         throws Exception
483     {
484         String jre131 = new java.io.File( "target/test-classes/eclipse/dummyJDK/1.3.1/bin/javac" ).getCanonicalPath();
485         checkJRESettingsWithEclipseWorkspace( "project-40", TempEclipseWorkspace.getFixtureEclipseWithDefault13(),
486                                               "JVM 1.3.1", jre131 );
487         checkJRESettingsWithEclipseWorkspace( "project-40", TempEclipseWorkspace.getFixtureEclipseWithDefault15(),
488                                               "JVM 1.3.1", jre131 );
489         checkJRESettingsWithEclipseWorkspace( "project-40", TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14(), "",
490                                               jre131 );
491     }
492 
493     public void testProject41()
494         throws Exception
495     {
496         TempEclipseWorkspace rad7 = TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14();
497         Properties properties = new Properties();
498         properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
499         testProject( "project-41", properties, "clean", "eclipse" );
500 
501     }
502 
503     public void testProject42()
504         throws Exception
505     {
506         TempEclipseWorkspace rad7 = TempEclipseWorkspace.getFixtureEclipseWorkspaceWithRad7Default14();
507         Properties properties = new Properties();
508         properties.setProperty( "eclipse.workspace", rad7.workspaceLocation.getCanonicalPath() );
509         testProject( "project-42", properties, "clean", "eclipse" );
510 
511     }
512 
513     
514 
515 
516 
517 
518 
519     public void testProject43()
520         throws Exception
521     {
522         testProject( "project-43" );
523     }
524 
525     
526 
527 
528 
529 
530 
531     public void testProject44()
532         throws Exception
533     {
534         testProject( "project-44" );
535     }
536 
537     
538 
539 
540 
541 
542 
543     public void testProject45()
544         throws Exception
545     {
546         testProject( "project-45" );
547     }
548     
549     
550 
551 
552 
553 
554 
555     public void testProject46()
556         throws Exception
557     {
558         testProject( "project-46" );
559         assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145", null, "sources" );
560         assertNotAvailableMarkerFileExists( "biz.aQute", "bndlib", "0.0.145", null, "javadoc" );
561     }
562     
563     
564 
565 
566 
567 
568 
569     public void testProject47()
570         throws Exception
571     {
572         testProject( "project-47" );
573         assertNotAvailableMarkerFileExists( "commons-lang", "commons-lang", "1.0", null, "sources" );
574         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "1.0", null, "javadoc" );
575     }
576     
577     
578 
579 
580 
581 
582 
583     public void testProject48()
584         throws Exception
585     {
586         testProject( "project-48" );
587         assertNotAvailableMarkerFileDoesNotExist( "does-not-exist", "does-not-exist", "666", null, "sources" );
588         assertNotAvailableMarkerFileDoesNotExist( "does-not-exist", "does-not-exist", "666", null, "javadoc" );
589     }    
590 
591     
592 
593 
594 
595 
596     public void testProject49()
597         throws Exception
598     {
599         File notAvailableMarkerFile =
600             getNotAvailableMarkerFile( "commons-lang", "commons-lang", "2.4", null, "sources" );
601         notAvailableMarkerFile.getParentFile().mkdirs();
602         notAvailableMarkerFile.createNewFile();
603         getNotAvailableMarkerFile( "commons-lang", "commons-lang", "2.4", null, "javadoc" ).createNewFile();
604 
605         testProject( "project-49" );
606         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "2.4", null, "sources" );
607         assertNotAvailableMarkerFileDoesNotExist( "commons-lang", "commons-lang", "2.4", null, "javadoc" );
608     }   
609 
610 
611     
612 
613 
614 
615 
616     public void testProject50MECLIPSE415()
617         throws Exception
618     {
619         testProject( "project-50-MECLIPSE-415" );
620     }    
621 
622     
623 
624 
625 
626 
627     public void testProject51MECLIPSE415()
628         throws Exception
629     {
630         testProject( "project-51-MECLIPSE-415" );
631     }    
632     
633     public void testJeeSimple()
634         throws Exception
635     {
636         
637         File basedir = getTestFile( "target/test-classes/projects/j2ee-simple" );
638         File pom = new File( basedir, "pom.xml" );
639         List goals = new ArrayList();
640         goals.add( "install" );
641         executeMaven( pom, new Properties(), goals );
642         
643         testProject( "j2ee-simple" );
644         checkContextRoot( basedir, "servlets/servlet", "ear", "servlet" );
645 
646     }
647 
648     private void checkContextRoot( File basedir, String warModule, String earModule, String expectedContextRoot )
649         throws FileNotFoundException, XmlPullParserException, IOException
650     {
651         FileReader reader =
652             new FileReader( new File( basedir, warModule + "/.settings/org.eclipse.wst.common.component" ) );
653         Xpp3Dom warComponent = Xpp3DomBuilder.build( reader );
654         Xpp3Dom[] properties = warComponent.getChild( "wb-module" ).getChildren( "property" );
655         boolean contextRootAvaliable = false;
656         for ( int index = 0; index < properties.length; index++ )
657         {
658             if ( properties[index].getAttribute( "name" ).equals( "context-root" ) )
659             {
660                 assertEquals( "Context root detection in org.eclipse.wst.common.component", expectedContextRoot,
661                               properties[index].getAttribute( "value" ) );
662                 contextRootAvaliable = true;
663             }
664         }
665         assertTrue( "there must be a context root here", contextRootAvaliable );
666 
667         reader = new FileReader( new File( basedir, earModule + "/target/eclipseEar/META-INF/application.xml" ) );
668         Xpp3Dom generatedApplicationXML = Xpp3DomBuilder.build( reader );
669 
670         Xpp3Dom[] modules = generatedApplicationXML.getChildren( "module" );
671         for ( int index = 0; index < modules.length; index++ )
672         {
673             if ( modules[index].getChild( "web" ) != null )
674             {
675                 assertEquals( "Context root detection in target/eclipseEar/META-INF/application.xml",
676                               expectedContextRoot,
677                               modules[index].getChild( "web" ).getChild( "context-root" ).getValue() );
678             }
679         }
680     }
681 
682     private void checkJRESettingsWithEclipseWorkspace( String project, TempEclipseWorkspace workspace,
683                                                        String expectedJRE, String jreExec )
684         throws Exception
685     {
686         Properties properties = new Properties();
687         properties.setProperty( "eclipse.workspace", workspace.workspaceLocation.getCanonicalPath() );
688         if ( jreExec != null )
689         {
690             properties.setProperty( "maven.compiler.executable", jreExec );
691         }
692         testProject( project, properties, "clean", "eclipse" );
693 
694         Xpp3Dom classpath =
695             Xpp3DomBuilder.build( new FileReader( getTestFile( "target/test-classes/projects/" + project
696                 + "/.classpath" ) ) );
697 
698         boolean foundDirectCompileAsProject = false;
699         String foundJRE = "";
700 
701         Xpp3Dom[] classpathentries = classpath.getChildren( "classpathentry" );
702         for ( int index = 0; index < classpathentries.length; index++ )
703         {
704             if ( "/direct-compile".equals( classpathentries[index].getAttribute( "path" ) ) )
705             {
706                 foundDirectCompileAsProject = true;
707             }
708             String path = classpathentries[index].getAttribute( "path" );
709             if ( "con".equals( classpathentries[index].getAttribute( "kind" ) ) && path.lastIndexOf( '/' ) > 0 )
710             {
711                 foundJRE = path.substring( path.lastIndexOf( '/' ) + 1 );
712             }
713         }
714         assertTrue( foundDirectCompileAsProject );
715         assertEquals( expectedJRE, foundJRE );
716     }
717 
718 }