langtools/test/jdk/javadoc/tool/sourceOption/SourceOption.java
changeset 40310 a979695d72a1
parent 35426 374342e56a56
child 40508 74ef30d16fb9
equal deleted inserted replaced
40309:4c9d829b21ea 40310:a979695d72a1
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug     6507179
    26  * @bug     6507179
    27  * @summary Ensure that "-source" option isn't ignored.
    27  * @summary Ensure that "-source" option isn't ignored.
    28  * @author  Scott Seligman
    28  * @author  Scott Seligman
    29  * @ignore API modifications
    29  * @modules jdk.javadoc/jdk.javadoc.internal.tool
    30  * @modules jdk.javadoc
       
    31  * @run main/fail SourceOption 7
    30  * @run main/fail SourceOption 7
    32  * @run main      SourceOption 9
    31  * @run main      SourceOption 9
    33  * @run main      SourceOption
    32  * @run main      SourceOption
    34  */
    33  */
    35 
    34 
    53  *  fixVersion: JDK11
    52  *  fixVersion: JDK11
    54  *      replace ./p/LambdaConstructTest.java with a missing from
    53  *      replace ./p/LambdaConstructTest.java with a missing from
    55  *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
    54  *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
    56  */
    55  */
    57 
    56 
       
    57 import java.util.ArrayList;
    58 import java.util.Collections;
    58 import java.util.Collections;
       
    59 import java.util.List;
       
    60 import java.util.Locale;
    59 import java.util.Set;
    61 import java.util.Set;
    60 
    62 
    61 import javax.lang.model.SourceVersion;
    63 import javax.lang.model.SourceVersion;
       
    64 import javax.tools.Diagnostic.Kind;
    62 
    65 
    63 import jdk.javadoc.doclet.Doclet;
    66 import jdk.javadoc.doclet.Doclet;
    64 import jdk.javadoc.doclet.Doclet.Option;
    67 import jdk.javadoc.doclet.Doclet.Option;
    65 import jdk.javadoc.doclet.DocletEnvironment;
    68 import jdk.javadoc.doclet.DocletEnvironment;
       
    69 import jdk.javadoc.doclet.Reporter;
    66 
    70 
    67 public class SourceOption implements Doclet {
    71 public class SourceOption implements Doclet {
    68 
    72 
    69     public static void main(String[] args) {
    73     public static void main(String[] args) {
    70         String[] params;
    74         List<String> params = new ArrayList<>();
       
    75         params.add("-sourcepath");
       
    76         params.add(System.getProperty("test.src"));
       
    77         params.add("-docletpath");
       
    78         params.add(System.getProperty("test.classes"));
       
    79         params.add("-doclet");
       
    80         params.add("SourceOption");
    71         if ((args == null) || (args.length==0)) {
    81         if ((args == null) || (args.length==0)) {
    72             params = new String[]{"p"};
       
    73             System.out.println("NOTE : -source not provided, default taken");
    82             System.out.println("NOTE : -source not provided, default taken");
    74         } else {
    83         } else {
    75             params = new String[]{"-source", args[0], "p"};
    84             params.add("-source");
       
    85             params.add(args[0]);
    76             System.out.println("NOTE : -source will be: " + args[0]);
    86             System.out.println("NOTE : -source will be: " + args[0]);
    77         }
    87         }
    78 
    88         params.add("p");
    79         if (com.sun.tools.javadoc.Main.execute(
    89         System.out.println("arguments: " + params);
    80                 "javadoc",
    90         if (jdk.javadoc.internal.tool.Main.execute(params.toArray(new String[params.size()])) != 0)
    81                 "SourceOption",
    91             throw new Error("Javadoc encountered warnings or errors.");
    82                 SourceOption.class.getClassLoader(),
       
    83                 params) != 0)
       
    84         throw new Error("Javadoc encountered warnings or errors.");
       
    85 
       
    86     }
    92     }
    87 
    93 
    88     public boolean run(DocletEnvironment root) {
    94     public boolean run(DocletEnvironment root) {
    89         root.getIncludedClasses();         // force parser into action
    95         root.getIncludedClasses();         // force parser into action
    90         return true;
    96         return true;
   102 
   108 
   103     @Override
   109     @Override
   104     public SourceVersion getSupportedSourceVersion() {
   110     public SourceVersion getSupportedSourceVersion() {
   105         return SourceVersion.latest();
   111         return SourceVersion.latest();
   106     }
   112     }
       
   113 
       
   114     @Override
       
   115     public void init(Locale locale, Reporter reporter) {
       
   116         reporter.print(Kind.NOTE, "init");
       
   117     }
   107 }
   118 }