src/share/jaxws_classes/com/sun/tools/internal/ws/wscompile/Options.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.wscompile;
  27 
  28 import com.sun.tools.internal.ws.resources.WscompileMessages;
  29 import com.sun.tools.internal.ws.Invoker;
  30 
  31 import javax.annotation.processing.Filer;
  32 import java.io.File;
  33 import java.io.IOException;
  34 import java.net.MalformedURLException;
  35 import java.net.URL;
  36 import java.net.URLClassLoader;
  37 import java.nio.charset.Charset;
  38 import java.nio.charset.IllegalCharsetNameException;

  39 import java.util.ArrayList;
  40 import java.util.List;
  41 import java.util.StringTokenizer;
  42 
  43 /**
  44  * Provide common jaxws tool options.
  45  *
  46  * @author Vivek Pandey
  47  */
  48 public class Options {
  49     /**
  50      * -verbose
  51      */
  52     public boolean verbose;
  53 
  54     /**
  55      * - quite
  56      */
  57     public boolean quiet;
  58 


  75     public File sourceDir;
  76 
  77     /**
  78      * The filer that can use used to write out the generated files
  79      */
  80     public Filer filer;
  81 
  82     /**
  83      * -encoding
  84      */
  85     public String encoding;
  86 
  87     public String classpath = System.getProperty("java.class.path");
  88 
  89 
  90     /**
  91      * -Xnocompile
  92      */
  93     public boolean nocompile;
  94 






  95     public enum Target {
  96         V2_0, V2_1, V2_2;
  97 
  98         /**
  99          * Returns true if this version is equal or later than the given one.
 100          */
 101         public boolean isLaterThan(Target t) {
 102             return this.ordinal() >= t.ordinal();
 103         }
 104 
 105         /**
 106          * Parses "2.0" and "2.1" into the {@link Target} object.
 107          *
 108          * @return null for parsing failure.
 109          */
 110         public static Target parse(String token) {
 111             if (token.equals("2.0"))
 112                 return Target.V2_0;
 113             else if (token.equals("2.1"))
 114                 return Target.V2_1;


 163      */
 164     public static final int STRICT = 1;
 165 
 166     /**
 167      * loosely follow the compatibility rules and allow the use of vendor
 168      * binding extensions
 169      */
 170     public static final int EXTENSION = 2;
 171 
 172     /**
 173      * this switch determines how carefully the compiler will follow
 174      * the compatibility rules in the spec. Either <code>STRICT</code>
 175      * or <code>EXTENSION</code>.
 176      */
 177     public int compatibilityMode = STRICT;
 178 
 179     public boolean isExtensionMode() {
 180         return compatibilityMode == EXTENSION;
 181     }
 182 
 183     /**
 184      * Target direcoty when producing files.
 185      */
 186     public File targetDir = new File(".");
 187 
 188 
 189 
 190     public boolean debug = false;
 191 
 192     /**
 193      * -Xdebug - gives complete stack trace
 194      */
 195     public boolean debugMode = false;
 196 
 197 
 198     private final List<File> generatedFiles = new ArrayList<File>();
 199     private ClassLoader classLoader;
 200 
 201 
 202     /**
 203      * Remember info on  generated source file generated so that it
 204      * can be removed later, if appropriate.
 205      */
 206     public void addGeneratedFile(File file) {
 207         generatedFiles.add(file);
 208     }
 209 
 210     /**
 211      * Remove generated files
 212      */
 213     public void removeGeneratedFiles(){
 214         for(File file : generatedFiles){
 215             if (file.getName().endsWith(".java")) {
 216                 file.delete();



 217             }
 218         }
 219         generatedFiles.clear();
 220     }
 221 
 222     /**
 223      * Return all the generated files and its types.
 224      */
 225     public Iterable<File> getGeneratedFiles() {
 226         return generatedFiles;
 227     }
 228 
 229     /**
 230      * Delete all the generated source files made during the execution
 231      * of this environment (those that have been registered with the
 232      * "addGeneratedFile" method).
 233      */
 234     public void deleteGeneratedFiles() {
 235         synchronized (generatedFiles) {
 236             for (File file : generatedFiles) {
 237                 if (file.getName().endsWith(".java")) {
 238                     file.delete();



 239                 }
 240             }
 241             generatedFiles.clear();
 242         }
 243     }
 244 
 245     /**
 246      * Parses arguments and fill fields of this object.
 247      *
 248      * @exception BadCommandLineException
 249      *      thrown when there's a problem in the command-line arguments
 250      */
 251     public void parseArguments( String[] args ) throws BadCommandLineException {
 252 
 253         for (int i = 0; i < args.length; i++) {
 254             if(args[i].length()==0)
 255                 throw new BadCommandLineException();
 256             if (args[i].charAt(0) == '-') {
 257                 int j = parseArguments(args,i);
 258                 if(j==0)


 331             return 1;
 332         } else if (args[i].startsWith("-help")) {
 333             WeAreDone done = new WeAreDone();
 334             done.initOptions(this);
 335             throw done;
 336         } else if (args[i].equals("-Xnocompile")) {
 337             // -nocompile implies -keep. this is undocumented switch.
 338             nocompile = true;
 339             keep = true;
 340             return 1;
 341         } else if (args[i].equals("-encoding")) {
 342             encoding = requireArgument("-encoding", args, ++i);
 343             try {
 344                 if (!Charset.isSupported(encoding)) {
 345                     throw new BadCommandLineException(WscompileMessages.WSCOMPILE_UNSUPPORTED_ENCODING(encoding));
 346                 }
 347             } catch (IllegalCharsetNameException icne) {
 348                 throw new BadCommandLineException(WscompileMessages.WSCOMPILE_UNSUPPORTED_ENCODING(encoding));
 349             }
 350             return 2;



 351         }
 352         return 0;
 353     }
 354 
 355     /**
 356      * Obtains an operand and reports an error if it's not there.
 357      */
 358     public String requireArgument(String optionName, String[] args, int i) throws BadCommandLineException {
 359         //if (i == args.length || args[i].startsWith("-")) {
 360         if (args[i].startsWith("-")) {
 361             throw new BadCommandLineException(WscompileMessages.WSCOMPILE_MISSING_OPTION_ARGUMENT(optionName));
 362         }
 363         return args[i];
 364     }
 365 
 366 
 367 
 368     /**
 369      * Used to signal that we've finished processing.
 370      */


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.wscompile;
  27 
  28 import com.sun.tools.internal.ws.resources.WscompileMessages;
  29 import com.sun.tools.internal.ws.Invoker;
  30 
  31 import javax.annotation.processing.Filer;
  32 import java.io.File;
  33 import java.io.IOException;
  34 import java.net.MalformedURLException;
  35 import java.net.URL;
  36 import java.net.URLClassLoader;
  37 import java.nio.charset.Charset;
  38 import java.nio.charset.IllegalCharsetNameException;
  39 import java.text.MessageFormat;
  40 import java.util.ArrayList;
  41 import java.util.List;
  42 import java.util.StringTokenizer;
  43 
  44 /**
  45  * Provide common jaxws tool options.
  46  *
  47  * @author Vivek Pandey
  48  */
  49 public class Options {
  50     /**
  51      * -verbose
  52      */
  53     public boolean verbose;
  54 
  55     /**
  56      * - quite
  57      */
  58     public boolean quiet;
  59 


  76     public File sourceDir;
  77 
  78     /**
  79      * The filer that can use used to write out the generated files
  80      */
  81     public Filer filer;
  82 
  83     /**
  84      * -encoding
  85      */
  86     public String encoding;
  87 
  88     public String classpath = System.getProperty("java.class.path");
  89 
  90 
  91     /**
  92      * -Xnocompile
  93      */
  94     public boolean nocompile;
  95 
  96     /**
  97      * Disable secure xml processing.
  98      * -XdisableSecureXmlProcessing
  99      */
 100     public boolean disableSecureXmlProcessing = false;
 101 
 102     public enum Target {
 103         V2_0, V2_1, V2_2;
 104 
 105         /**
 106          * Returns true if this version is equal or later than the given one.
 107          */
 108         public boolean isLaterThan(Target t) {
 109             return this.ordinal() >= t.ordinal();
 110         }
 111 
 112         /**
 113          * Parses "2.0" and "2.1" into the {@link Target} object.
 114          *
 115          * @return null for parsing failure.
 116          */
 117         public static Target parse(String token) {
 118             if (token.equals("2.0"))
 119                 return Target.V2_0;
 120             else if (token.equals("2.1"))
 121                 return Target.V2_1;


 170      */
 171     public static final int STRICT = 1;
 172 
 173     /**
 174      * loosely follow the compatibility rules and allow the use of vendor
 175      * binding extensions
 176      */
 177     public static final int EXTENSION = 2;
 178 
 179     /**
 180      * this switch determines how carefully the compiler will follow
 181      * the compatibility rules in the spec. Either <code>STRICT</code>
 182      * or <code>EXTENSION</code>.
 183      */
 184     public int compatibilityMode = STRICT;
 185 
 186     public boolean isExtensionMode() {
 187         return compatibilityMode == EXTENSION;
 188     }
 189 







 190     public boolean debug = false;
 191 
 192     /**
 193      * -Xdebug - gives complete stack trace
 194      */
 195     public boolean debugMode = false;
 196 
 197 
 198     private final List<File> generatedFiles = new ArrayList<File>();
 199     private ClassLoader classLoader;
 200 
 201 
 202     /**
 203      * Remember info on  generated source file generated so that it
 204      * can be removed later, if appropriate.
 205      */
 206     public void addGeneratedFile(File file) {
 207         generatedFiles.add(file);
 208     }
 209 
 210     /**
 211      * Remove generated files
 212      */
 213     public void removeGeneratedFiles(){
 214         for(File file : generatedFiles){
 215             if (file.getName().endsWith(".java")) {
 216                 boolean deleted = file.delete();
 217                 if (verbose && !deleted) {
 218                     System.out.println(MessageFormat.format("{0} could not be deleted.", file));
 219                 }
 220             }
 221         }
 222         generatedFiles.clear();
 223     }
 224 
 225     /**
 226      * Return all the generated files and its types.
 227      */
 228     public Iterable<File> getGeneratedFiles() {
 229         return generatedFiles;
 230     }
 231 
 232     /**
 233      * Delete all the generated source files made during the execution
 234      * of this environment (those that have been registered with the
 235      * "addGeneratedFile" method).
 236      */
 237     public void deleteGeneratedFiles() {
 238         synchronized (generatedFiles) {
 239             for (File file : generatedFiles) {
 240                 if (file.getName().endsWith(".java")) {
 241                     boolean deleted = file.delete();
 242                     if (verbose && !deleted) {
 243                         System.out.println(MessageFormat.format("{0} could not be deleted.", file));
 244                     }
 245                 }
 246             }
 247             generatedFiles.clear();
 248         }
 249     }
 250 
 251     /**
 252      * Parses arguments and fill fields of this object.
 253      *
 254      * @exception BadCommandLineException
 255      *      thrown when there's a problem in the command-line arguments
 256      */
 257     public void parseArguments( String[] args ) throws BadCommandLineException {
 258 
 259         for (int i = 0; i < args.length; i++) {
 260             if(args[i].length()==0)
 261                 throw new BadCommandLineException();
 262             if (args[i].charAt(0) == '-') {
 263                 int j = parseArguments(args,i);
 264                 if(j==0)


 337             return 1;
 338         } else if (args[i].startsWith("-help")) {
 339             WeAreDone done = new WeAreDone();
 340             done.initOptions(this);
 341             throw done;
 342         } else if (args[i].equals("-Xnocompile")) {
 343             // -nocompile implies -keep. this is undocumented switch.
 344             nocompile = true;
 345             keep = true;
 346             return 1;
 347         } else if (args[i].equals("-encoding")) {
 348             encoding = requireArgument("-encoding", args, ++i);
 349             try {
 350                 if (!Charset.isSupported(encoding)) {
 351                     throw new BadCommandLineException(WscompileMessages.WSCOMPILE_UNSUPPORTED_ENCODING(encoding));
 352                 }
 353             } catch (IllegalCharsetNameException icne) {
 354                 throw new BadCommandLineException(WscompileMessages.WSCOMPILE_UNSUPPORTED_ENCODING(encoding));
 355             }
 356             return 2;
 357         } else if (args[i].equals("-XdisableSecureXmlProcessing")) {
 358             disableSecureXmlProcessing= true;
 359             return 1;
 360         }
 361         return 0;
 362     }
 363 
 364     /**
 365      * Obtains an operand and reports an error if it's not there.
 366      */
 367     public String requireArgument(String optionName, String[] args, int i) throws BadCommandLineException {
 368         //if (i == args.length || args[i].startsWith("-")) {
 369         if (args[i].startsWith("-")) {
 370             throw new BadCommandLineException(WscompileMessages.WSCOMPILE_MISSING_OPTION_ARGUMENT(optionName));
 371         }
 372         return args[i];
 373     }
 374 
 375 
 376 
 377     /**
 378      * Used to signal that we've finished processing.
 379      */