View Javadoc
1   package org.codehaus.plexus.metadata;
2   
3   import java.io.File;
4   import java.util.Arrays;
5   import java.util.Collections;
6   
7   import org.apache.commons.cli.CommandLine;
8   import org.apache.commons.cli.OptionBuilder;
9   import org.apache.commons.cli.Options;
10  import org.codehaus.plexus.PlexusContainer;
11  import org.codehaus.plexus.tools.cli.AbstractCli;
12  
13  public class PlexusMetadataGeneratorCli
14      extends AbstractCli
15  {
16      public static final char SOURCE_DIRECTORY = 's';
17      public static final char SOURCE_ENCODING = 'e';
18      public static final char CLASSES_DIRECTORY = 'c';
19      public static final char OUTPUT_FILE = 'o';
20      public static final char DESCRIPTORS_DIRECTORY = 'm';
21  
22      public static void main( String[] args )
23          throws Exception
24      {
25          new PlexusMetadataGeneratorCli().execute( args );
26      }
27  
28      @Override
29      public String getPomPropertiesPath()
30      {
31          return "META-INF/maven/org.codehaus.plexus/plexus-metadata-generator/pom.properties";
32      }
33  
34      @Override
35      @SuppressWarnings("static-access")
36      public Options buildCliOptions( Options options )
37      {
38          options.addOption( OptionBuilder.withLongOpt( "source" ).hasArg().withDescription( "Source directory." ).create( SOURCE_DIRECTORY ) );
39          options.addOption( OptionBuilder.withLongOpt( "encoding" ).hasArg().withDescription( "Source file encoding." ).create( SOURCE_ENCODING ) );
40          options.addOption( OptionBuilder.withLongOpt( "classes" ).hasArg().withDescription( "Classes directory." ).create( CLASSES_DIRECTORY ) );
41          options.addOption( OptionBuilder.withLongOpt( "output" ).hasArg().withDescription( "Output directory." ).create( OUTPUT_FILE ) );
42          options.addOption( OptionBuilder.withLongOpt( "descriptors" ).hasArg().withDescription( "Descriptors directory." ).create( DESCRIPTORS_DIRECTORY ) );
43          return options;
44      }    
45  
46      public void invokePlexusComponent( CommandLine cli, PlexusContainer plexus )
47          throws Exception
48      {
49          MetadataGenerator metadataGenerator = plexus.lookup( MetadataGenerator.class );
50          
51          MetadataGenerationRequest request = new MetadataGenerationRequest();        
52          request.classesDirectory = new File( cli.getOptionValue( CLASSES_DIRECTORY ) );
53          request.classpath = Collections.emptyList();
54          request.sourceDirectories = Arrays.asList( new String[]{ new File( cli.getOptionValue( SOURCE_DIRECTORY ) ).getAbsolutePath() } );
55          request.sourceEncoding = cli.getOptionValue( SOURCE_ENCODING );
56          request.useContextClassLoader = true;
57          request.outputFile = new File( cli.getOptionValue( OUTPUT_FILE ) );
58          request.componentDescriptorDirectory = new File( cli.getOptionValue( DESCRIPTORS_DIRECTORY ) );
59          
60          metadataGenerator.generateDescriptor( request );
61      }
62  }