KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > pluggy > Main


1 package org.apache.maven.tools.plugin.pluggy;
2
3 /*
4  * Copyright 2001-2004 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 org.apache.maven.model.Model;
20 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
21 import org.apache.maven.plugin.descriptor.PluginDescriptor;
22 import org.apache.maven.project.MavenProject;
23 import org.apache.maven.tools.plugin.extractor.java.JavaMojoDescriptorExtractor;
24 import org.apache.maven.tools.plugin.generator.Generator;
25 import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
26 import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
27 import org.apache.maven.tools.plugin.scanner.DefaultMojoScanner;
28 import org.apache.maven.tools.plugin.scanner.MojoScanner;
29 import org.apache.maven.tools.plugin.util.PluginUtils;
30
31 import java.io.File JavaDoc;
32 import java.io.FileReader JavaDoc;
33 import java.util.Collections JavaDoc;
34
35 /**
36  * @author <a HREF="mailto:jason@maven.org">Jason van Zyl</a>
37  * @version $Id: Main.java 355404 2005-12-09 07:58:04Z brett $
38  */

39 public class Main
40 {
41     public static void main( String JavaDoc[] args )
42         throws Exception JavaDoc
43     {
44         if ( args.length != 5 )
45         {
46             System.err.println( "Usage: pluggy <mode> <source directory> <output directory> <pom>" );
47
48             System.exit( 1 );
49         }
50
51         // Make sense of the args.
52
String JavaDoc mode = args[0];
53
54         String JavaDoc sourceDirectory = args[1];
55
56         String JavaDoc outputDirectory = args[2];
57
58         String JavaDoc pom = args[3];
59
60         // Massage the local-repo path into an ArtifactRepository.
61

62
63         MavenXpp3Reader modelReader = new MavenXpp3Reader();
64         FileReader JavaDoc reader = new FileReader JavaDoc( pom );
65
66         Model model = modelReader.read( reader, true );
67
68         // Not doing inheritence, except for groupId and version
69
if ( model.getGroupId() == null )
70         {
71             model.setGroupId( model.getParent().getGroupId() );
72         }
73         if ( model.getVersion() == null )
74         {
75             model.setVersion( model.getParent().getVersion() );
76         }
77
78         MavenProject project = new MavenProject( model );
79         project.setFile( new File JavaDoc( pom ) );
80         project.addCompileSourceRoot( sourceDirectory );
81
82         // Lookup the mojo scanner instance, and use it to scan for mojo's, and
83
// extract their descriptors.
84
MojoScanner scanner = new DefaultMojoScanner(
85             Collections.singletonMap( "java", new JavaMojoDescriptorExtractor() ) );
86
87         PluginDescriptor pluginDescriptor = new PluginDescriptor();
88
89         pluginDescriptor.setGroupId( project.getGroupId() );
90
91         pluginDescriptor.setArtifactId( project.getArtifactId() );
92
93         pluginDescriptor.setVersion( project.getVersion() );
94
95         // TODO: should read this from the pom...
96
pluginDescriptor.setGoalPrefix( PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ) );
97
98         pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getDependencies() ) );
99
100         scanner.populatePluginDescriptor( project, pluginDescriptor );
101         
102         // Create the generator.
103
Generator generator = null;
104
105         if ( mode.equals( "descriptor" ) )
106         {
107             generator = new PluginDescriptorGenerator();
108         }
109         else if ( mode.equals( "xdoc" ) )
110         {
111             generator = new PluginXdocGenerator();
112         }
113
114         // Use the generator to process the discovered descriptors and produce
115
// something with them.
116
generator.execute( new File JavaDoc( outputDirectory ), pluginDescriptor );
117     }
118 }
119
Popular Tags