View Javadoc

1   package org.codehaus.modello;
2   
3   /*
4    * Copyright (c) 2004, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  
25  import org.codehaus.plexus.util.ReaderFactory;
26  import org.codehaus.plexus.util.StringUtils;
27  
28  import java.io.File;
29  import java.util.Properties;
30  
31  /**
32   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
33   */
34  public class ModelloCli
35  {
36      private static File modelFile;
37  
38      private static String outputType;
39  
40      private static Properties parameters;
41  
42      public static void main( String[] args )
43          throws Exception
44      {
45          Modello modello = new Modello();
46  
47          parseArgumentsFromCommandLine( args );
48  
49          modello.generate( ReaderFactory.newXmlReader( modelFile ), outputType, parameters );
50      }
51  
52      public static void parseArgumentsFromCommandLine( String[] args )
53          throws Exception
54      {
55          if ( args.length < 6 )
56          {
57              usage();
58  
59              System.exit( 1 );
60          }
61  
62          modelFile = new File( args[0] );
63  
64          outputType = args[1];
65  
66          parameters = new Properties();
67  
68          String outputDirectory = args[2];
69  
70          if ( StringUtils.isEmpty( outputDirectory ) )
71          {
72              System.err.println( "Missing required parameter: output directory" );
73  
74              usage();
75  
76              System.exit( 1 );
77          }
78  
79          parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, outputDirectory );
80  
81          String modelVersion = args[ 3 ];
82  
83          if ( StringUtils.isEmpty( modelVersion ) )
84          {
85              System.err.println( "Missing required parameter: model version" );
86  
87              usage();
88  
89              System.exit( 1 );
90          }
91  
92          parameters.setProperty( ModelloParameterConstants.VERSION, modelVersion );
93  
94          String packageWithVersion = args[ 4 ];
95  
96          if ( StringUtils.isEmpty( packageWithVersion ) )
97          {
98              System.err.println( "Missing required parameter: package with version" );
99  
100             usage();
101 
102             System.exit( 1 );
103         }
104 
105         parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, packageWithVersion );
106 
107         String useJava5 = args[ 5 ];
108 
109         if ( StringUtils.isEmpty( useJava5 ) )
110         {
111             System.err.println( "Missing required parameter: use Java 5" );
112 
113             usage();
114 
115             System.exit( 1 );
116         }
117 
118         parameters.setProperty( ModelloParameterConstants.USE_JAVA5, useJava5 );
119 
120         if ( args.length > 6 )
121         {
122             parameters.setProperty( ModelloParameterConstants.ENCODING, args[6] );
123         }
124     }
125 
126     // ----------------------------------------------------------------------
127     //
128     // ----------------------------------------------------------------------
129 
130     private static void usage()
131     {
132         System.err.println( "Usage: modello <model> <outputType> <output directory> <modelVersion> <packageWithVersion>"
133                             + "<useJava5> [<encoding>]" );
134     }
135 }