< prev index next >

test/langtools/jdk/javadoc/tool/OptionSyntaxTest.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2016, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8166144
  27  * @summary support new-style options
  28  * @modules jdk.compiler/com.sun.tools.javac.api
  29  * @modules jdk.compiler/com.sun.tools.javac.main
  30  * @modules jdk.javadoc/jdk.javadoc.internal.api
  31  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  32  * @library /tools/lib
  33  * @build toolbox.JavacTask toolbox.JavadocTask toolbox.ModuleBuilder toolbox.TestRunner toolbox.ToolBox

  34  * @run main OptionSyntaxTest
  35  */
  36 import java.io.IOException;
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.HashSet;
  42 import java.util.List;
  43 import java.util.Locale;
  44 import java.util.Set;
  45 
  46 import javax.lang.model.SourceVersion;
  47 
  48 import jdk.javadoc.doclet.Doclet;
  49 import jdk.javadoc.doclet.DocletEnvironment;
  50 import jdk.javadoc.doclet.Reporter;
  51 
  52 import toolbox.JavadocTask;
  53 import toolbox.ModuleBuilder;
  54 import toolbox.Task;
  55 import toolbox.TestRunner;
  56 import toolbox.ToolBox;
  57 
  58 
  59 public class OptionSyntaxTest extends TestRunner {
  60     public static class TestDoclet implements Doclet {
  61         @Override
  62         public boolean run(DocletEnvironment root) {


  77         @Override
  78         public SourceVersion getSupportedSourceVersion() {
  79             return SourceVersion.latest();
  80         }
  81 
  82         @Override
  83         public void init(Locale locale, Reporter reporter) {
  84         }
  85 
  86         private final Set<Doclet.Option> options = new HashSet<>(Arrays.asList(
  87                 new DOption("-old", 0),
  88                 new DOption("-oldWithArg", 1),
  89                 new DOption("-oldWithArgs", 2),
  90                 new DOption("--new", 0),
  91                 new DOption("--newWithArg", 1),
  92                 new DOption("--newWithArgs", 2)
  93         ));
  94 
  95     }
  96 
  97     static class DOption implements Doclet.Option {
  98         private final List<String> names = new ArrayList<>();
  99         private final int argCount;
 100 
 101         DOption(String name, int argCount) {
 102             this.names.add(name);
 103             this.argCount = argCount;
 104         }
 105 
 106         @Override
 107         public int getArgumentCount() {
 108             return argCount;
 109         }
 110 
 111         @Override
 112         public String getDescription() {
 113             return "description[" + names.get(0) + "]";
 114         }
 115 
 116         @Override
 117         public Kind getKind() {
 118             return Doclet.Option.Kind.STANDARD;
 119         }
 120 
 121         @Override
 122         public List<String> getNames() {
 123             return names;
 124         }
 125 
 126         @Override
 127         public String getParameters() {
 128             return argCount > 0 ? "parameters[" + names.get(0) + "," + argCount + "]" : null;
 129         }
 130 
 131         @Override
 132         public boolean process(String option, List<String> arguments) {
 133             List<String> args = new ArrayList<>();
 134             for (int i = 0; i < argCount && i < arguments.size(); i++) {
 135                 args.add(arguments.get(i));
 136             }
 137             System.out.println("process " + option + " " + args);
 138             return args.stream().filter(s -> s.startsWith("arg")).count() == argCount;
 139         }
 140     }
 141 
 142     public static void main(String... args) throws Exception {
 143         OptionSyntaxTest t = new OptionSyntaxTest();
 144         t.runTests();
 145     }
 146 
 147     private final ToolBox tb = new ToolBox();
 148     private final Path src = Paths.get("src");
 149     private final Path modules = Paths.get("modules");
 150 
 151     OptionSyntaxTest() throws IOException {
 152         super(System.err);
 153         initModules();
 154     }
 155 
 156     void initModules() throws IOException {
 157         new ModuleBuilder(tb, "m1")
 158                 .exports("p1")
 159                 .classes("package p1; public class C1 { }")
 160                 .write(src);


   1 /*
   2  * Copyright (c) 2002, 2019, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8166144
  27  * @summary support new-style options
  28  * @modules jdk.compiler/com.sun.tools.javac.api
  29  * @modules jdk.compiler/com.sun.tools.javac.main
  30  * @modules jdk.javadoc/jdk.javadoc.internal.api
  31  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  32  * @library /tools/lib
  33  * @build toolbox.JavacTask toolbox.JavadocTask toolbox.ModuleBuilder toolbox.TestRunner toolbox.ToolBox
  34  * @build DOption
  35  * @run main OptionSyntaxTest
  36  */
  37 import java.io.IOException;
  38 import java.nio.file.Path;
  39 import java.nio.file.Paths;

  40 import java.util.Arrays;
  41 import java.util.HashSet;

  42 import java.util.Locale;
  43 import java.util.Set;
  44 
  45 import javax.lang.model.SourceVersion;
  46 
  47 import jdk.javadoc.doclet.Doclet;
  48 import jdk.javadoc.doclet.DocletEnvironment;
  49 import jdk.javadoc.doclet.Reporter;
  50 
  51 import toolbox.JavadocTask;
  52 import toolbox.ModuleBuilder;
  53 import toolbox.Task;
  54 import toolbox.TestRunner;
  55 import toolbox.ToolBox;
  56 
  57 
  58 public class OptionSyntaxTest extends TestRunner {
  59     public static class TestDoclet implements Doclet {
  60         @Override
  61         public boolean run(DocletEnvironment root) {


  76         @Override
  77         public SourceVersion getSupportedSourceVersion() {
  78             return SourceVersion.latest();
  79         }
  80 
  81         @Override
  82         public void init(Locale locale, Reporter reporter) {
  83         }
  84 
  85         private final Set<Doclet.Option> options = new HashSet<>(Arrays.asList(
  86                 new DOption("-old", 0),
  87                 new DOption("-oldWithArg", 1),
  88                 new DOption("-oldWithArgs", 2),
  89                 new DOption("--new", 0),
  90                 new DOption("--newWithArg", 1),
  91                 new DOption("--newWithArgs", 2)
  92         ));
  93 
  94     }
  95 












































  96 
  97     public static void main(String... args) throws Exception {
  98         OptionSyntaxTest t = new OptionSyntaxTest();
  99         t.runTests();
 100     }
 101 
 102     private final ToolBox tb = new ToolBox();
 103     private final Path src = Paths.get("src");
 104     private final Path modules = Paths.get("modules");
 105 
 106     OptionSyntaxTest() throws IOException {
 107         super(System.err);
 108         initModules();
 109     }
 110 
 111     void initModules() throws IOException {
 112         new ModuleBuilder(tb, "m1")
 113                 .exports("p1")
 114                 .classes("package p1; public class C1 { }")
 115                 .write(src);


< prev index next >