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 java.io.File;
26  import java.util.Properties;
27  
28  import org.codehaus.plexus.DefaultPlexusContainer;
29  import org.codehaus.plexus.util.StringUtils;
30  import org.codehaus.plexus.util.xml.XmlStreamReader;
31  
32  /**
33   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
34   */
35  public class ModelloCli {
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) throws Exception {
43          Modello modello = new DefaultPlexusContainer().lookup(Modello.class);
44  
45          parseArgumentsFromCommandLine(args);
46  
47          modello.generate(new XmlStreamReader(modelFile), outputType, parameters);
48      }
49  
50      public static void parseArgumentsFromCommandLine(String[] args) throws Exception {
51          if (args.length < 6) {
52              usage();
53  
54              System.exit(1);
55          }
56  
57          modelFile = new File(args[0]);
58  
59          outputType = args[1];
60  
61          parameters = new Properties();
62  
63          String outputDirectory = args[2];
64  
65          if (StringUtils.isEmpty(outputDirectory)) {
66              System.err.println("Missing required parameter: output directory");
67  
68              usage();
69  
70              System.exit(1);
71          }
72  
73          parameters.setProperty(ModelloParameterConstants.OUTPUT_DIRECTORY, outputDirectory);
74  
75          String modelVersion = args[3];
76  
77          if (StringUtils.isEmpty(modelVersion)) {
78              System.err.println("Missing required parameter: model version");
79  
80              usage();
81  
82              System.exit(1);
83          }
84  
85          parameters.setProperty(ModelloParameterConstants.VERSION, modelVersion);
86  
87          String packageWithVersion = args[4];
88  
89          if (StringUtils.isEmpty(packageWithVersion)) {
90              System.err.println("Missing required parameter: package with version");
91  
92              usage();
93  
94              System.exit(1);
95          }
96  
97          parameters.setProperty(ModelloParameterConstants.PACKAGE_WITH_VERSION, packageWithVersion);
98  
99          String javaSource = args[5];
100 
101         if (StringUtils.isEmpty(javaSource)) {
102             System.err.println("Missing required parameter: Java Source");
103 
104             usage();
105 
106             System.exit(1);
107         }
108 
109         parameters.setProperty(ModelloParameterConstants.OUTPUT_JAVA_SOURCE, javaSource);
110 
111         if (args.length > 6) {
112             parameters.setProperty(ModelloParameterConstants.ENCODING, args[6]);
113         }
114     }
115 
116     // ----------------------------------------------------------------------
117     //
118     // ----------------------------------------------------------------------
119 
120     private static void usage() {
121         System.err.println("Usage: modello <model> <outputType> <output directory> <modelVersion> <packageWithVersion>"
122                 + "<javaSource> [<encoding>]");
123     }
124 }