1 package org.apache.maven.tools.plugin.extractor.java; 2 3 18 19 import junit.framework.TestCase; 20 import org.apache.maven.model.Model; 21 import org.apache.maven.project.MavenProject; 22 import org.apache.maven.plugin.descriptor.PluginDescriptor; 23 24 import java.io.File ; 25 import java.net.URL ; 26 import java.util.List ; 27 28 31 public class JavaMojoDescriptorExtractorTest 32 extends TestCase 33 { 34 35 public void testShouldFindTwoMojoDescriptorsInTestSourceDirectory() 36 throws Exception 37 { 38 JavaMojoDescriptorExtractor extractor = new JavaMojoDescriptorExtractor(); 39 40 File sourceFile = fileOf( "dir-flag.txt" ); 41 System.out.println( "found source file: " + sourceFile ); 42 43 File dir = sourceFile.getParentFile(); 44 45 Model model = new Model(); 46 model.setArtifactId( "maven-unitTesting-plugin" ); 47 48 MavenProject project = new MavenProject( model ); 49 50 project.setFile( new File ( dir, "pom.xml" ) ); 51 project.addCompileSourceRoot( new File ( dir, "source" ).getPath() ); 52 53 PluginDescriptor pluginDescriptor = new PluginDescriptor(); 54 pluginDescriptor.setGoalPrefix( "test" ); 55 List results = extractor.execute( project, pluginDescriptor ); 56 assertEquals( 2, results.size() ); 57 } 58 59 private File fileOf( String classpathResource ) 60 { 61 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 62 URL resource = cl.getResource( classpathResource ); 63 64 File result = null; 65 if ( resource != null ) 66 { 67 result = new File ( resource.getPath() ); 68 } 69 70 return result; 71 } 72 73 } | Popular Tags |