KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > extractor > java > JavaMojoDescriptorExtractorTest


1 package org.apache.maven.tools.plugin.extractor.java;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * @author jdcasey
30  */

31 public class JavaMojoDescriptorExtractorTest
32     extends TestCase
33 {
34
35     public void testShouldFindTwoMojoDescriptorsInTestSourceDirectory()
36         throws Exception JavaDoc
37     {
38         JavaMojoDescriptorExtractor extractor = new JavaMojoDescriptorExtractor();
39
40         File JavaDoc sourceFile = fileOf( "dir-flag.txt" );
41         System.out.println( "found source file: " + sourceFile );
42
43         File JavaDoc 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 JavaDoc( dir, "pom.xml" ) );
51         project.addCompileSourceRoot( new File JavaDoc( dir, "source" ).getPath() );
52
53         PluginDescriptor pluginDescriptor = new PluginDescriptor();
54         pluginDescriptor.setGoalPrefix( "test" );
55         List JavaDoc results = extractor.execute( project, pluginDescriptor );
56         assertEquals( 2, results.size() );
57     }
58
59     private File JavaDoc fileOf( String JavaDoc classpathResource )
60     {
61         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
62         URL JavaDoc resource = cl.getResource( classpathResource );
63
64         File JavaDoc result = null;
65         if ( resource != null )
66         {
67             result = new File JavaDoc( resource.getPath() );
68         }
69
70         return result;
71     }
72
73 }
Popular Tags