From 727db66e983aac6cccb728a86a20df8ea5753e6e Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 25 Dec 2015 13:22:32 +0100 Subject: [PATCH 1/5] Issue #91: Add new ant-task "ant generate-internal" to produce the list of internal packages like generate-deprecated --- build.xml | 12 +++ .../signatures/jdk-internal-1.6.txt | 14 +++ .../signatures/jdk-internal-1.7.txt | 39 +++++++ .../signatures/jdk-internal-1.8.txt | 56 ++++++++++ .../signatures/jdk-internal-1.9.txt | 59 +++++++++++ .../forbiddenapis/InternalApiGen.java | 100 ++++++++++++++++++ 6 files changed, 280 insertions(+) create mode 100644 src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt create mode 100644 src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt create mode 100644 src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt create mode 100644 src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt create mode 100644 src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java diff --git a/build.xml b/build.xml index 7c7df17f..72a4d2ed 100644 --- a/build.xml +++ b/build.xml @@ -469,6 +469,7 @@ + @@ -480,6 +481,7 @@ + @@ -579,6 +581,7 @@ + @@ -612,6 +615,15 @@ + + + + + + + + + diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt new file mode 100644 index 00000000..ad9333b3 --- /dev/null +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt @@ -0,0 +1,14 @@ +# This file contains API signatures that are marked as internal in Java. +# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: +# $ ant generate-internal + +# This file contains all public, deprecated API signatures in Java version 1.6 (extracted from build 1.6.0_32). + +@defaultMessage non-public internal runtime class in Java 1.6 + +com.sun.imageio.** +com.sun.org.apache.xalan.internal.utils.** +com.sun.org.apache.xerces.internal.utils.** +com.sun.xml.internal.bind.** +com.sun.xml.internal.ws.** +sun.** diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt new file mode 100644 index 00000000..806514cb --- /dev/null +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt @@ -0,0 +1,39 @@ +# This file contains API signatures that are marked as internal in Java. +# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: +# $ ant generate-internal + +# This file contains all public, deprecated API signatures in Java version 1.7 (extracted from build 1.7.0_80). + +@defaultMessage non-public internal runtime class in Java 1.7 + +com.sun.corba.se.** +com.sun.imageio.** +com.sun.istack.internal.** +com.sun.java.accessibility.** +com.sun.jmx.** +com.sun.naming.internal.** +com.sun.org.apache.bcel.internal.** +com.sun.org.apache.regexp.internal.** +com.sun.org.apache.xalan.internal.extensions.** +com.sun.org.apache.xalan.internal.lib.** +com.sun.org.apache.xalan.internal.res.** +com.sun.org.apache.xalan.internal.templates.** +com.sun.org.apache.xalan.internal.utils.** +com.sun.org.apache.xalan.internal.xslt.** +com.sun.org.apache.xalan.internal.xsltc.cmdline.** +com.sun.org.apache.xalan.internal.xsltc.compiler.** +com.sun.org.apache.xalan.internal.xsltc.trax.** +com.sun.org.apache.xalan.internal.xsltc.util.** +com.sun.org.apache.xerces.internal.** +com.sun.org.apache.xml.internal.res.** +com.sun.org.apache.xml.internal.security.** +com.sun.org.apache.xml.internal.serializer.utils.** +com.sun.org.apache.xml.internal.utils.** +com.sun.org.apache.xpath.internal.** +com.sun.org.glassfish.** +com.sun.proxy.** +com.sun.script.** +com.sun.xml.internal.** +oracle.jrockit.jfr.** +org.jcp.xml.dsig.internal.** +sun.** diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt new file mode 100644 index 00000000..ee7e89a5 --- /dev/null +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt @@ -0,0 +1,56 @@ +# This file contains API signatures that are marked as internal in Java. +# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: +# $ ant generate-internal + +# This file contains all public, deprecated API signatures in Java version 1.8 (extracted from build 1.8.0_60). + +@defaultMessage non-public internal runtime class in Java 1.8 + +com.oracle.webservices.internal.** +com.oracle.xmlns.internal.** +com.sun.activation.registries.** +com.sun.browser.** +com.sun.corba.se.** +com.sun.glass.** +com.sun.imageio.** +com.sun.istack.internal.** +com.sun.java.accessibility.** +com.sun.javafx.** +com.sun.jmx.** +com.sun.media.** +com.sun.media.sound.** +com.sun.naming.internal.** +com.sun.openpisces.** +com.sun.org.apache.bcel.internal.** +com.sun.org.apache.regexp.internal.** +com.sun.org.apache.xalan.internal.extensions.** +com.sun.org.apache.xalan.internal.lib.** +com.sun.org.apache.xalan.internal.res.** +com.sun.org.apache.xalan.internal.templates.** +com.sun.org.apache.xalan.internal.utils.** +com.sun.org.apache.xalan.internal.xslt.** +com.sun.org.apache.xalan.internal.xsltc.cmdline.** +com.sun.org.apache.xalan.internal.xsltc.compiler.** +com.sun.org.apache.xalan.internal.xsltc.trax.** +com.sun.org.apache.xalan.internal.xsltc.util.** +com.sun.org.apache.xerces.internal.** +com.sun.org.apache.xml.internal.res.** +com.sun.org.apache.xml.internal.security.** +com.sun.org.apache.xml.internal.serializer.utils.** +com.sun.org.apache.xml.internal.utils.** +com.sun.org.apache.xpath.internal.** +com.sun.org.glassfish.** +com.sun.pisces.** +com.sun.prism.** +com.sun.proxy.** +com.sun.scenario.** +com.sun.t2k.** +com.sun.webkit.** +com.sun.xml.internal.** +jdk.internal.** +jdk.management.resource.internal.** +jdk.nashorn.internal.** +jdk.nashorn.tools.** +oracle.jrockit.jfr.** +org.jcp.xml.dsig.internal.** +sun.** diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt new file mode 100644 index 00000000..e3516795 --- /dev/null +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt @@ -0,0 +1,59 @@ +# This file contains API signatures that are marked as internal in Java. +# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: +# $ ant generate-internal + +# This file contains all public, deprecated API signatures in Java version 1.9 (extracted from build 1.9.0-ea). + +@defaultMessage non-public internal runtime class in Java 1.9 + +com.oracle.webservices.internal.** +com.oracle.xmlns.internal.** +com.sun.activation.registries.** +com.sun.browser.** +com.sun.corba.se.** +com.sun.glass.** +com.sun.imageio.** +com.sun.istack.internal.** +com.sun.java.accessibility.internal.** +com.sun.java.accessibility.util.internal.** +com.sun.javafx.** +com.sun.jmx.** +com.sun.media.** +com.sun.media.sound.** +com.sun.naming.internal.** +com.sun.openpisces.** +com.sun.org.apache.bcel.internal.** +com.sun.org.apache.regexp.internal.** +com.sun.org.apache.xalan.internal.extensions.** +com.sun.org.apache.xalan.internal.lib.** +com.sun.org.apache.xalan.internal.res.** +com.sun.org.apache.xalan.internal.templates.** +com.sun.org.apache.xalan.internal.utils.** +com.sun.org.apache.xalan.internal.xslt.** +com.sun.org.apache.xalan.internal.xsltc.cmdline.** +com.sun.org.apache.xalan.internal.xsltc.compiler.** +com.sun.org.apache.xalan.internal.xsltc.trax.** +com.sun.org.apache.xalan.internal.xsltc.util.** +com.sun.org.apache.xerces.internal.** +com.sun.org.apache.xml.internal.res.** +com.sun.org.apache.xml.internal.security.** +com.sun.org.apache.xml.internal.serializer.utils.** +com.sun.org.apache.xml.internal.utils.** +com.sun.org.apache.xpath.internal.** +com.sun.org.glassfish.** +com.sun.pisces.** +com.sun.prism.** +com.sun.proxy.** +com.sun.scenario.** +com.sun.t2k.** +com.sun.tools.script.** +com.sun.webkit.** +com.sun.xml.internal.** +jdk.internal.** +jdk.management.cmm.internal.** +jdk.nashorn.internal.** +jdk.nashorn.tools.** +jdk.tools.jimage.** +oracle.jrockit.jfr.** +org.jcp.xml.dsig.internal.** +sun.** diff --git a/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java b/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java new file mode 100644 index 00000000..e5e865cb --- /dev/null +++ b/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java @@ -0,0 +1,100 @@ +package de.thetaphi.forbiddenapis; + +/* + * (C) Copyright Uwe Schindler (Generics Policeman) and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.security.Security; +import java.util.Locale; +import java.util.Set; +import java.util.TreeSet; + +/** Generates a signatures file listing all JRE-internal classes for the current runtime. */ +public final class InternalApiGen { + + final static String NL = System.getProperty("line.separator", "\n"); + final String javaVersion, header; + + private final File output; + + InternalApiGen(String javaVersion, String outputFile) { + this(javaVersion, new File(outputFile)); + } + + InternalApiGen(String javaVersion, File output) { + this.javaVersion = javaVersion; + this.output = output; + if (!System.getProperty("java.version").startsWith(javaVersion)) + throw new IllegalArgumentException("Java version mismatch: build " + System.getProperty("java.version") + " != expected " + javaVersion); + this.header = new StringBuilder() + .append("# This file contains API signatures that are marked as internal in Java.").append(NL) + .append("# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis:").append(NL) + .append("# $ ant generate-internal").append(NL) + .append(NL) + .append("# This file contains all public, deprecated API signatures in Java version ").append(javaVersion) + .append(" (extracted from build ").append(System.getProperty("java.version")).append(").").append(NL) + .append(NL) + .append("@defaultMessage non-public internal runtime class in Java ").append(javaVersion).append(NL) + .append(NL) + .toString(); + } + + private void parsePackages(String packagesStr, Set packages) { + if (packagesStr == null || packagesStr.isEmpty()) { + return; + } + for (String pkg : packagesStr.split(",")) { + pkg = pkg.trim(); + if (!pkg.endsWith(".")) { + pkg = pkg.concat("."); + } + packages.add(pkg.concat("**")); + } + } + + @SuppressForbidden + void run() throws IOException { + System.err.println(String.format(Locale.ENGLISH, "Writing internal APIs to signatures file '%s'...", output)); + + final Set packages = new TreeSet(); + parsePackages(Security.getProperty("package.access"), packages); + // TODO: add this, too??: parsePackages(Security.getProperty("package.definition"), packages); + + final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8")); + try { + writer.write(header); + for (final String s : packages) { + writer.write(s); + writer.newLine(); + } + } finally { + writer.close(); + } + + System.err.println("Internal API signatures for Java version " + javaVersion + " written successfully."); + } + + public static void main(String... args) throws Exception { + if (args.length != 2) { + throw new IllegalArgumentException("Need 2 arguments: java version, output file"); + } + new InternalApiGen(args[0], args[1]).run(); + } +} From 7dd7764bb3854b2aa4f8659e1ee5bd5380a4aae4 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 25 Dec 2015 13:37:47 +0100 Subject: [PATCH 2/5] Issue #91: Fix comment in jdk-internal bundled signatures --- .../de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt | 2 +- .../de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt | 2 +- .../de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt | 2 +- .../de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt | 2 +- src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt index ad9333b3..5e202018 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.6.txt @@ -2,7 +2,7 @@ # It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: # $ ant generate-internal -# This file contains all public, deprecated API signatures in Java version 1.6 (extracted from build 1.6.0_32). +# This file contains all internal packages listed in Security.getProperty("package.access") of Java version 1.6 (extracted from build 1.6.0_32). @defaultMessage non-public internal runtime class in Java 1.6 diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt index 806514cb..d161b8f0 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.7.txt @@ -2,7 +2,7 @@ # It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: # $ ant generate-internal -# This file contains all public, deprecated API signatures in Java version 1.7 (extracted from build 1.7.0_80). +# This file contains all internal packages listed in Security.getProperty("package.access") of Java version 1.7 (extracted from build 1.7.0_80). @defaultMessage non-public internal runtime class in Java 1.7 diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt index ee7e89a5..c1066923 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.8.txt @@ -2,7 +2,7 @@ # It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: # $ ant generate-internal -# This file contains all public, deprecated API signatures in Java version 1.8 (extracted from build 1.8.0_60). +# This file contains all internal packages listed in Security.getProperty("package.access") of Java version 1.8 (extracted from build 1.8.0_60). @defaultMessage non-public internal runtime class in Java 1.8 diff --git a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt index e3516795..2848af3e 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt +++ b/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-internal-1.9.txt @@ -2,7 +2,7 @@ # It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis: # $ ant generate-internal -# This file contains all public, deprecated API signatures in Java version 1.9 (extracted from build 1.9.0-ea). +# This file contains all internal packages listed in Security.getProperty("package.access") of Java version 1.9 (extracted from build 1.9.0-ea). @defaultMessage non-public internal runtime class in Java 1.9 diff --git a/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java b/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java index e5e865cb..513bb0b6 100644 --- a/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java +++ b/src/tools/java/de/thetaphi/forbiddenapis/InternalApiGen.java @@ -48,7 +48,7 @@ public final class InternalApiGen { .append("# It is provided here for reference, but can easily regenerated by executing from the source folder of forbidden-apis:").append(NL) .append("# $ ant generate-internal").append(NL) .append(NL) - .append("# This file contains all public, deprecated API signatures in Java version ").append(javaVersion) + .append("# This file contains all internal packages listed in Security.getProperty(\"package.access\") of Java version ").append(javaVersion) .append(" (extracted from build ").append(System.getProperty("java.version")).append(").").append(NL) .append(NL) .append("@defaultMessage non-public internal runtime class in Java ").append(javaVersion).append(NL) From 11f5b2584c85fdc10061686b71678b7d31d37506 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 27 Dec 2015 17:18:02 +0100 Subject: [PATCH 3/5] Issue #91: Fix isRuntime to mark all classes below ${java.home} or bootclasspath (for Apple JDK) as runtime classes (previously only bootclasspath was added, missing extension classes); improve lookup with reverse ordered tree set. --- .../de/thetaphi/forbiddenapis/Checker.java | 80 +++++++++++-------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index 5ec9e76d..64b3e176 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -43,8 +43,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; +import java.util.SortedSet; import java.util.StringTokenizer; +import java.util.TreeSet; import java.util.regex.Pattern; import java.lang.annotation.Annotation; import java.lang.management.ManagementFactory; @@ -68,8 +71,9 @@ public static enum Option { final Logger logger; - final Set bootClassPathJars; - final Set bootClassPathDirs; + // must be sorted backwards + final SortedSet runtimePaths; + final ClassLoader loader; final java.lang.reflect.Method method_Class_getModule, method_Module_getResourceAsStream; final EnumSet