View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.enhancer;
18  
19  import java.io.PrintWriter;
20  
21  
22  /***
23   * Set of options used by the JDO enhancer and its test programs.
24   *
25   * @author Martin Zaun
26   */
27  public class EnhancerOptions
28      extends JdoMetaOptions
29  {
30      /***
31       * The quiet option.
32       */
33      public final FlagOption quiet
34          = createFlagOption("quiet", "q",
35                               "           : suppress warnings");
36      /***
37       * The force write option.
38       */
39      public final FlagOption forceWrite
40          = createFlagOption("forcewrite", "f",
41                             "           : overwrite output files");
42  
43      /***
44       * The no write option.
45       */
46      public final FlagOption noWrite
47          = createFlagOption("nowrite", "n",
48                             "           : never write output files");
49  
50      /***
51       * The destination directory option.
52       */
53      public final StringOption destDir
54          = createStringOption("destdir", "d",
55                               "<path>     : directory for any output files");
56  
57      /***
58       * The dump class option.
59       */
60      public final FlagOption dumpClass
61          = createFlagOption("dumpclass", null,
62                             "           : dump out disassembled byte-code");
63  
64      /***
65       * The suppress augmentation option.
66       */
67      public final FlagOption noAugment
68          = createFlagOption("noaugment", null,
69                             "           : do not enhance for persistence-capability");
70  
71      /***
72       * The suppress annotation option.
73       */
74      public final FlagOption noAnnotate
75          = createFlagOption("noannotate", null,
76                             "           : do not enhance for persistence-awareness");
77  
78      /***
79       * Creates an instance.
80       */
81      public EnhancerOptions(PrintWriter out,
82                            PrintWriter err) 
83      {
84          super(out, err);
85      }
86  
87      // ----------------------------------------------------------------------
88  
89      /***
90       * Print a usage message to System.err.
91       */
92      public void printUsageHeader()
93      {
94          printlnErr("Usage: <options>.. <arguments>..");
95          printlnErr(indent
96                     + "-j <path> -s <path> -d <dir>   <classname>..");
97          printlnErr(indent
98                     + "-j <path> -d <dir>             <classfile>..");
99          //^olsen: consider allowing omission of destination directory for
100         // class file arguments
101         //printlnErr(indent
102         //           + "-j <path> [-d <dir>]           <classfile>..");
103         //^olsen: re-enable support for archive files
104         //printlnErr(indent
105         //           + "[-j <path>] [-d <dir>]         <archivefile>..");
106     }
107 
108     /***
109      * Check options and arguments.
110      */
111     public int check()
112     {
113         int res;
114         if ((res = super.check()) != OK) {
115             return res;
116         }
117         
118         // check destination directory option
119         if (destDir.value == null && !classNames.isEmpty()) {
120             printUsageError("No destination directory specified for enhanced classes");
121             return USAGE_ERROR;
122         }
123 
124         //^olsen: consider allowing omission of destination directory for
125         // class file arguments
126         if (destDir.value == null && !classFileNames.isEmpty()) {
127             printUsageError("No destination directory specified for enhanced classes");
128             return USAGE_ERROR;
129         }
130 
131         return OK;
132     }
133 
134     // ----------------------------------------------------------------------
135 
136     /***
137      * Tests the class.
138      */
139     static public void main(String[] args)
140     {
141         final PrintWriter out = new PrintWriter(System.out, true);
142         out.println("--> EnhancerOptions.main()");
143         final EnhancerOptions options = new EnhancerOptions(out, out);
144         out.println("    options.process() ...");
145         int res = options.process(args);
146         out.println("    return value: " + res);
147         out.println("<-- EnhancerOptions.main()");
148     }
149 }