Path: blob/master/test/langtools/jdk/javadoc/tool/sourceOption/SourceOption.java
66646 views
/*1* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 650717926* @summary Ensure that "-source" option isn't ignored.27* @modules jdk.javadoc/jdk.javadoc.internal.tool28* @run main/fail SourceOption 729* @run main SourceOption 930* @run main SourceOption31*/3233/*34* In order to test whether or not the -source option is working35* correctly, this test tries to parse source code that contains36* a feature that is not available in at least one of the currently37* supported previous versions.38*39* Parsing such code should be expected to fail; if the action40* passes, that means the -source option is (incorrectly) ineffective.41*42* Additional actions are performed to ensure that the source43* provided is valid for the current release of the JDK.44*45* As support for older versions of the platform are dropped, the46* source code (currently p/LambdaConstructTest.java) will need to47* be updated with a more recent feature.48*/4950import java.util.ArrayList;51import java.util.Collections;52import java.util.List;53import java.util.Locale;54import java.util.Set;5556import javax.lang.model.SourceVersion;57import javax.lang.model.util.ElementFilter;58import javax.tools.Diagnostic.Kind;5960import jdk.javadoc.doclet.Doclet;61import jdk.javadoc.doclet.Doclet.Option;62import jdk.javadoc.doclet.DocletEnvironment;63import jdk.javadoc.doclet.Reporter;6465public class SourceOption implements Doclet {6667public static void main(String[] args) {68List<String> params = new ArrayList<>();69params.add("-sourcepath");70params.add(System.getProperty("test.src"));71params.add("-docletpath");72params.add(System.getProperty("test.classes"));73params.add("-doclet");74params.add("SourceOption");75if ((args == null) || (args.length==0)) {76System.out.println("NOTE : -source not provided, default taken");77} else {78params.add("-source");79params.add(args[0]);80System.out.println("NOTE : -source will be: " + args[0]);81}82params.add("p");83System.out.println("arguments: " + params);84if (jdk.javadoc.internal.tool.Main.execute(params.toArray(new String[params.size()])) != 0)85throw new Error("Javadoc encountered warnings or errors.");86}8788public boolean run(DocletEnvironment root) {89ElementFilter.typesIn(root.getIncludedElements());90return true;91}9293@Override94public String getName() {95return "Test";96}9798@Override99public Set<Option> getSupportedOptions() {100return Collections.emptySet();101}102103@Override104public SourceVersion getSupportedSourceVersion() {105return SourceVersion.latest();106}107108@Override109public void init(Locale locale, Reporter reporter) {110reporter.print(Kind.NOTE, "init");111}112}113114115