1 package org.apache.maven.tools.plugin.pluggy; 2 3 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 ; 32 import java.io.FileReader ; 33 import java.util.Collections ; 34 35 39 public class Main 40 { 41 public static void main( String [] args ) 42 throws Exception 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 String mode = args[0]; 53 54 String sourceDirectory = args[1]; 55 56 String outputDirectory = args[2]; 57 58 String pom = args[3]; 59 60 62 63 MavenXpp3Reader modelReader = new MavenXpp3Reader(); 64 FileReader reader = new FileReader ( pom ); 65 66 Model model = modelReader.read( reader, true ); 67 68 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 ( pom ) ); 80 project.addCompileSourceRoot( sourceDirectory ); 81 82 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 pluginDescriptor.setGoalPrefix( PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ) ); 97 98 pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getDependencies() ) ); 99 100 scanner.populatePluginDescriptor( project, pluginDescriptor ); 101 102 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 generator.execute( new File ( outputDirectory ), pluginDescriptor ); 117 } 118 } 119 | Popular Tags |