< prev index next >

src/jdk.jartool/share/classes/sun/tools/jar/GNUStyleOptions.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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 sun.tools.jar;
  27 
  28 import java.io.File;
  29 import java.io.PrintStream;
  30 import java.io.PrintWriter;
  31 import java.lang.module.ModuleFinder;
  32 import java.lang.module.ModuleDescriptor.Version;
  33 import java.nio.file.Path;
  34 import java.nio.file.Paths;
  35 import java.util.regex.Pattern;
  36 import java.util.regex.PatternSyntaxException;


  37 import jdk.internal.module.ModuleResolution;
  38 
  39 /**
  40  * Parser for GNU Style Options.
  41  */
  42 class GNUStyleOptions {
  43 
  44     static class BadArgs extends Exception {
  45         static final long serialVersionUID = 0L;
  46 
  47         boolean showUsage;
  48 
  49         BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
  50         BadArgs(String key) { super(Main.getMsg(key)); }
  51 
  52         BadArgs showUsage(boolean b) {
  53             showUsage = b;
  54             return this;
  55         }
  56     }


 138                     jartool.moduleVersion = Version.parse(arg);
 139                 }
 140             },
 141             new Option(true, OptionType.CREATE_UPDATE, "--hash-modules") {
 142                 void process(Main jartool, String opt, String arg) throws BadArgs {
 143                     try {
 144                         jartool.modulesToHash = Pattern.compile(arg);
 145                     } catch (PatternSyntaxException e) {
 146                         throw new BadArgs("err.badpattern", arg).showUsage(true);
 147                     }
 148                 }
 149             },
 150             new Option(true, OptionType.CREATE_UPDATE, "--module-path", "-p") {
 151                 void process(Main jartool, String opt, String arg) {
 152                     String[] dirs = arg.split(File.pathSeparator);
 153                     Path[] paths = new Path[dirs.length];
 154                     int i = 0;
 155                     for (String dir : dirs) {
 156                         paths[i++] = Paths.get(dir);
 157                     }
 158                     jartool.moduleFinder = ModuleFinder.compose(jartool.moduleFinder,
 159                                                                 ModuleFinder.of(paths));
 160                 }
 161             },
 162             new Option(false, OptionType.CREATE_UPDATE, "--do-not-resolve-by-default") {
 163                 void process(Main jartool, String opt, String arg) {
 164                     ModuleResolution mres = jartool.moduleResolution;
 165                     jartool.moduleResolution = mres.withDoNotResolveByDefault();
 166                 }
 167                 boolean isExtra() { return true; }
 168             },
 169             new Option(true, OptionType.CREATE_UPDATE, "--warn-if-resolved") {
 170                 void process(Main jartool, String opt, String arg) throws BadArgs {
 171                     ModuleResolution mres = ModuleResolution.empty();
 172                     if (jartool.moduleResolution.doNotResolveByDefault()) {
 173                         mres.withDoNotResolveByDefault();
 174                     }
 175                     if (arg.equals("deprecated")) {
 176                         jartool.moduleResolution = mres.withDeprecated();
 177                     } else if (arg.equals("deprecated-for-removal")) {
 178                         jartool.moduleResolution = mres.withDeprecatedForRemoval();
 179                     } else if (arg.equals("incubating")) {


   1 /*
   2  * Copyright (c) 2015, 2017, 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 sun.tools.jar;
  27 
  28 import java.io.File;
  29 import java.io.PrintStream;
  30 import java.io.PrintWriter;
  31 import java.lang.module.ModuleFinder;
  32 import java.lang.module.ModuleDescriptor.Version;
  33 import java.nio.file.Path;
  34 import java.nio.file.Paths;
  35 import java.util.regex.Pattern;
  36 import java.util.regex.PatternSyntaxException;
  37 
  38 import jdk.internal.module.ModulePath;
  39 import jdk.internal.module.ModuleResolution;
  40 
  41 /**
  42  * Parser for GNU Style Options.
  43  */
  44 class GNUStyleOptions {
  45 
  46     static class BadArgs extends Exception {
  47         static final long serialVersionUID = 0L;
  48 
  49         boolean showUsage;
  50 
  51         BadArgs(String key, String arg) { super(Main.formatMsg(key, arg)); }
  52         BadArgs(String key) { super(Main.getMsg(key)); }
  53 
  54         BadArgs showUsage(boolean b) {
  55             showUsage = b;
  56             return this;
  57         }
  58     }


 140                     jartool.moduleVersion = Version.parse(arg);
 141                 }
 142             },
 143             new Option(true, OptionType.CREATE_UPDATE, "--hash-modules") {
 144                 void process(Main jartool, String opt, String arg) throws BadArgs {
 145                     try {
 146                         jartool.modulesToHash = Pattern.compile(arg);
 147                     } catch (PatternSyntaxException e) {
 148                         throw new BadArgs("err.badpattern", arg).showUsage(true);
 149                     }
 150                 }
 151             },
 152             new Option(true, OptionType.CREATE_UPDATE, "--module-path", "-p") {
 153                 void process(Main jartool, String opt, String arg) {
 154                     String[] dirs = arg.split(File.pathSeparator);
 155                     Path[] paths = new Path[dirs.length];
 156                     int i = 0;
 157                     for (String dir : dirs) {
 158                         paths[i++] = Paths.get(dir);
 159                     }
 160                     jartool.moduleFinder =
 161                         new ModulePath(Runtime.version(), true, paths);
 162                 }
 163             },
 164             new Option(false, OptionType.CREATE_UPDATE, "--do-not-resolve-by-default") {
 165                 void process(Main jartool, String opt, String arg) {
 166                     ModuleResolution mres = jartool.moduleResolution;
 167                     jartool.moduleResolution = mres.withDoNotResolveByDefault();
 168                 }
 169                 boolean isExtra() { return true; }
 170             },
 171             new Option(true, OptionType.CREATE_UPDATE, "--warn-if-resolved") {
 172                 void process(Main jartool, String opt, String arg) throws BadArgs {
 173                     ModuleResolution mres = ModuleResolution.empty();
 174                     if (jartool.moduleResolution.doNotResolveByDefault()) {
 175                         mres.withDoNotResolveByDefault();
 176                     }
 177                     if (arg.equals("deprecated")) {
 178                         jartool.moduleResolution = mres.withDeprecated();
 179                     } else if (arg.equals("deprecated-for-removal")) {
 180                         jartool.moduleResolution = mres.withDeprecatedForRemoval();
 181                     } else if (arg.equals("incubating")) {


< prev index next >