View Javadoc

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