test/jdk/javadoc/tool/sourceOption/SourceOption.java

Print this page




   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     6507179
  27  * @summary Ensure that "-source" option isn't ignored.
  28  * @author  Scott Seligman

  29  * @modules jdk.javadoc
  30  * @run main/fail SourceOption 7
  31  * @run main      SourceOption 9
  32  * @run main      SourceOption
  33  */
  34 
  35 /*
  36  * TEST NOTE
  37  * With JDK9, this test has been transformed into a NEGATIVE test.
  38  *
  39  * Generally speaking, this test should check a feature not in at least
  40  * one of the currently supported previous versions.  In this manner,
  41  * a failure of the -source option to be honored would mean a pass of
  42  * the test, and therefore a failure of the -source option.
  43  *
  44  * For JDK9 and JDK10, both support 1.7, which did not support javac's
  45  * lambda construct.  So we set "-source 1.7" to compile a .java file
  46  * containing the lambda construct.  javac should fail, thus showing
  47  * -source to be working.  Thus the test passes.
  48  *
  49  * The second jtreg @run command checks to make sure that the source
  50  * provided is valid for the current release of the JDK.
  51  *
  52  *  fixVersion: JDK11
  53  *      replace ./p/LambdaConstructTest.java with a missing from
  54  *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
  55  */
  56 
  57 import com.sun.javadoc.*;

  58 
  59 public class SourceOption extends Doclet {
  60 






  61     public static void main(String[] args) {
  62         String[] params;
  63         if ((args == null) || (args.length==0)) {
  64             params = new String[]{"p"};
  65             System.out.println("NOTE : -source not provided, default taken");
  66         } else {
  67             params = new String[]{"-source", args[0], "p"};
  68             System.out.println("NOTE : -source will be: " + args[0]);
  69         }
  70 
  71         if (com.sun.tools.javadoc.Main.execute(
  72                 "javadoc",
  73                 "SourceOption",
  74                 SourceOption.class.getClassLoader(),
  75                 params) != 0)
  76         throw new Error("Javadoc encountered warnings or errors.");
  77 
  78     }
  79 
  80     public static boolean start(RootDoc root) {
  81         root.classes();         // force parser into action
  82         return true;
  83     }















  84 }


   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     6507179
  27  * @summary Ensure that "-source" option isn't ignored.
  28  * @author  Scott Seligman
  29  * @ignore API modifications
  30  * @modules jdk.javadoc
  31  * @run main/fail SourceOption 7
  32  * @run main      SourceOption 9
  33  * @run main      SourceOption
  34  */
  35 
  36 /*
  37  * TEST NOTE
  38  * With JDK9, this test has been transformed into a NEGATIVE test.
  39  *
  40  * Generally speaking, this test should check a feature not in at least
  41  * one of the currently supported previous versions.  In this manner,
  42  * a failure of the -source option to be honored would mean a pass of
  43  * the test, and therefore a failure of the -source option.
  44  *
  45  * For JDK9 and JDK10, both support 1.7, which did not support javac's
  46  * lambda construct.  So we set "-source 1.7" to compile a .java file
  47  * containing the lambda construct.  javac should fail, thus showing
  48  * -source to be working.  Thus the test passes.
  49  *
  50  * The second jtreg @run command checks to make sure that the source
  51  * provided is valid for the current release of the JDK.
  52  *
  53  *  fixVersion: JDK11
  54  *      replace ./p/LambdaConstructTest.java with a missing from
  55  *      JDK8, JDK9, or JDK10.  Set -source below appropriately.
  56  */
  57 
  58 import java.util.Collections;
  59 import java.util.Set;
  60 
  61 import javax.lang.model.SourceVersion;
  62 
  63 import jdk.javadoc.doclet.Doclet;
  64 import jdk.javadoc.doclet.Doclet.Option;
  65 import jdk.javadoc.doclet.DocletEnvironment;
  66 
  67 public class SourceOption implements Doclet {
  68 
  69     public static void main(String[] args) {
  70         String[] params;
  71         if ((args == null) || (args.length==0)) {
  72             params = new String[]{"p"};
  73             System.out.println("NOTE : -source not provided, default taken");
  74         } else {
  75             params = new String[]{"-source", args[0], "p"};
  76             System.out.println("NOTE : -source will be: " + args[0]);
  77         }
  78 
  79         if (com.sun.tools.javadoc.Main.execute(
  80                 "javadoc",
  81                 "SourceOption",
  82                 SourceOption.class.getClassLoader(),
  83                 params) != 0)
  84         throw new Error("Javadoc encountered warnings or errors.");
  85 
  86     }
  87 
  88     public boolean run(DocletEnvironment root) {
  89         root.getIncludedClasses();         // force parser into action
  90         return true;
  91     }
  92 
  93     @Override
  94     public String getName() {
  95         return "Test";
  96     }
  97 
  98     @Override
  99     public Set<Option> getSupportedOptions() {
 100         return Collections.emptySet();
 101     }
 102 
 103     @Override
 104     public SourceVersion getSupportedSourceVersion() {
 105         return SourceVersion.latest();
 106     }
 107 }