changeset 31936:02f1cfc234a0

8086737: Add support for -release to Javadoc Reviewed-by: jjg, ksrini
author jlahoda
date Fri, 24 Jul 2015 13:08:36 +0200
parents f55df5cfe11c
children ad43a6639c4a
files langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/PlatformUtils.java langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ToolOption.java langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties langtools/test/tools/javadoc/ReleaseOption.java langtools/test/tools/javadoc/ReleaseOptionSource.java
diffstat 7 files changed, 213 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Wed Jul 05 20:43:22 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Fri Jul 24 13:08:36 2015 +0200
@@ -33,11 +33,8 @@
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
-import java.util.Optional;
-import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
 
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileObject;
@@ -53,8 +50,7 @@
 import com.sun.tools.javac.jvm.Target;
 import com.sun.tools.javac.main.OptionHelper.GrumpyHelper;
 import com.sun.tools.javac.platform.PlatformDescription;
-import com.sun.tools.javac.platform.PlatformProvider;
-import com.sun.tools.javac.platform.PlatformProvider.PlatformNotSupported;
+import com.sun.tools.javac.platform.PlatformUtils;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.List;
 import com.sun.tools.javac.util.ListBuffer;
@@ -297,7 +293,7 @@
                 Option.TARGET);
 
         if (platformString != null) {
-            PlatformDescription platformDescription = lookupDescription(platformString);
+            PlatformDescription platformDescription = PlatformUtils.lookupPlatformDescription(platformString);
 
             if (platformDescription == null) {
                 error("err.unsupported.release.version", platformString);
@@ -502,31 +498,6 @@
         return !errors;
     }
 
-    private PlatformDescription lookupDescription(String platformString) {
-        int separator = platformString.indexOf(":");
-        String platformProviderName =
-                separator != (-1) ? platformString.substring(0, separator) : platformString;
-        String platformOptions =
-                separator != (-1) ? platformString.substring(separator + 1) : "";
-        Iterable<PlatformProvider> providers =
-                ServiceLoader.load(PlatformProvider.class, Arguments.class.getClassLoader());
-
-        return StreamSupport.stream(providers.spliterator(), false)
-                            .filter(provider -> StreamSupport.stream(provider.getSupportedPlatformNames()
-                                                                             .spliterator(),
-                                                                     false)
-                                                             .anyMatch(platformProviderName::equals))
-                            .findFirst()
-                            .flatMap(provider -> {
-                                try {
-                                    return Optional.of(provider.getPlatform(platformProviderName, platformOptions));
-                                } catch (PlatformNotSupported pns) {
-                                    return Optional.empty();
-                                }
-                            })
-                            .orElse(null);
-    }
-
     /**
      * Returns true if there are no files or classes specified for use.
      * @return true if there are no files or classes specified for use
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/PlatformUtils.java	Fri Jul 24 13:08:36 2015 +0200
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.tools.javac.platform;
+
+import com.sun.tools.javac.main.Arguments;
+import com.sun.tools.javac.platform.PlatformProvider.PlatformNotSupported;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.stream.StreamSupport;
+
+/** Internal utilities to work with PlatformDescriptions.
+ *
+ *  <p><b>This is NOT part of any supported API.
+ *  If you write code that depends on this, you do so at your own risk.
+ *  This code and its internal interfaces are subject to change or
+ *  deletion without notice.</b>
+ */
+public class PlatformUtils {
+
+    public static PlatformDescription lookupPlatformDescription(String platformString) {
+        int separator = platformString.indexOf(":");
+        String platformProviderName =
+                separator != (-1) ? platformString.substring(0, separator) : platformString;
+        String platformOptions =
+                separator != (-1) ? platformString.substring(separator + 1) : "";
+        Iterable<PlatformProvider> providers =
+                ServiceLoader.load(PlatformProvider.class, Arguments.class.getClassLoader());
+
+        return StreamSupport.stream(providers.spliterator(), false)
+                            .filter(provider -> StreamSupport.stream(provider.getSupportedPlatformNames()
+                                                                             .spliterator(),
+                                                                     false)
+                                                             .anyMatch(platformProviderName::equals))
+                            .findFirst()
+                            .flatMap(provider -> {
+                                try {
+                                    return Optional.of(provider.getPlatform(platformProviderName, platformOptions));
+                                } catch (PlatformNotSupported pns) {
+                                    return Optional.empty();
+                                }
+                            })
+                            .orElse(null);
+    }
+
+}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java	Wed Jul 05 20:43:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java	Fri Jul 24 13:08:36 2015 +0200
@@ -29,20 +29,24 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Map;
 import java.util.Objects;
 
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.main.CommandLine;
 import com.sun.tools.javac.main.Option;
 import com.sun.tools.javac.file.BaseFileManager;
+import com.sun.tools.javac.platform.PlatformDescription;
+import com.sun.tools.javac.platform.PlatformUtils;
 import com.sun.tools.javac.util.ClientCodeException;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.List;
@@ -352,6 +356,40 @@
             ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
         }
 
+        String platformString = compOpts.get("-release");
+
+        if (platformString != null) {
+            if (compOpts.isSet("-source")) {
+                usageError("main.release.bootclasspath.conflict", "-source");
+            }
+            if (fileManagerOpts.containsKey(Option.BOOTCLASSPATH)) {
+                usageError("main.release.bootclasspath.conflict", Option.BOOTCLASSPATH.getText());
+            }
+
+            PlatformDescription platformDescription =
+                    PlatformUtils.lookupPlatformDescription(platformString);
+
+            if (platformDescription == null) {
+                usageError("main.unsupported.release.version", platformString);
+            }
+
+            compOpts.put(Option.SOURCE, platformDescription.getSourceVersion());
+
+            context.put(PlatformDescription.class, platformDescription);
+
+            Collection<Path> platformCP = platformDescription.getPlatformPath();
+
+            if (platformCP != null) {
+                if (fileManager instanceof StandardJavaFileManager) {
+                    StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
+
+                    sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
+                } else {
+                    usageError("main.release.not.standard.file.manager", platformString);
+                }
+            }
+        }
+
         compOpts.notifyListeners();
 
         if (javaNames.isEmpty() && subPackages.isEmpty() && isEmpty(fileObjects)) {
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ToolOption.java	Wed Jul 05 20:43:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ToolOption.java	Fri Jul 24 13:08:36 2015 +0200
@@ -96,6 +96,13 @@
         }
     },
 
+    RELEASE("-release", true) {
+        @Override
+        public void process(Helper helper, String arg) {
+            helper.setCompilerOpt(opt, arg);
+        }
+    },
+
     SOURCE("-source", true) {
         @Override
         public void process(Helper helper, String arg) {
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties	Wed Jul 05 20:43:22 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/resources/javadoc.properties	Fri Jul 24 13:08:36 2015 +0200
@@ -92,6 +92,9 @@
 main.malformed_locale_name=Malformed locale name: {0}
 main.file_not_found=File not found: "{0}"
 main.illegal_package_name=Illegal package name: "{0}"
+main.release.bootclasspath.conflict=option {0} cannot be used together with -release
+main.unsupported.release.version=release version {0} not supported
+main.release.not.standard.file.manager=-release option specified, but the provided JavaFileManager is not a StandardJavaFileManager.
 tag.illegal_char_in_arr_dim=Tag {0}: Syntax Error in array dimension, method parameters: {1}
 tag.illegal_see_tag=Tag {0}: Syntax Error in method parameters: {1}
 tag.missing_comma_space=Tag {0}: Missing comma or space in method parameters: {1}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/ReleaseOption.java	Fri Jul 24 13:08:36 2015 +0200
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import com.sun.tools.javadoc.Main;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+
+/**
+ * @test
+ * @bug 8086737
+ * @summary Test -release option in javadoc
+ * @run main ReleaseOption
+ */
+public class ReleaseOption {
+    public static void main(String... args) {
+        new ReleaseOption().run();
+    }
+
+    void run() {
+        doRunTest(0, out -> out.contains("compiler.err.doesnt.exist: java.util.stream"), "-release", "7");
+        doRunTest(0, out -> !out.contains("compiler.err.doesnt.exist: java.util.stream"), "-release", "8");
+        doRunTest(1, out -> true, "-release", "7", "-source", "7");
+        doRunTest(1, out -> true, "-release", "7", "-bootclasspath", "any");
+    }
+
+    void doRunTest(int expectedResult, Predicate<String> validate, String... args) {
+        System.err.println("running with args: " + Arrays.asList(args));
+        List<String> options = new ArrayList<>();
+        options.addAll(Arrays.asList(args));
+        options.add("-XDrawDiagnostics");
+        options.add(System.getProperty("test.src", ".") + java.io.File.separatorChar + "ReleaseOptionSource.java");
+        StringWriter out = new StringWriter();
+        PrintWriter pw = new PrintWriter(out);
+        int actualResult = Main.execute("javadoc", pw, pw, pw, "com.sun.tools.doclets.formats.html.HtmlDoclet", options.toArray(new String[0]));
+        System.err.println("actual result=" + actualResult);
+        System.err.println("actual output=" + out.toString());
+        if (actualResult != expectedResult)
+            throw new Error();
+        if (!validate.test(out.toString())) {
+            throw new Error("Not an expected error output: " + out.toString());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/ReleaseOptionSource.java	Fri Jul 24 13:08:36 2015 +0200
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.stream.Stream;
+
+public class ReleaseOptionSource {
+    public Stream s;
+}