mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8153042: jdeps should continue to report JDK internal APIs that are removed/renamed in JDK
Reviewed-by: dfuchs
This commit is contained in:
parent
2a791e9edd
commit
0bafc010b2
12 changed files with 409 additions and 56 deletions
|
@ -369,9 +369,9 @@ public class Analyzer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final JdkInternals REMOVED_JDK_INTERNALS = new JdkInternals();
|
static final JdkInternals REMOVED_JDK_INTERNALS = new JdkInternals();
|
||||||
|
|
||||||
private static class JdkInternals extends Module {
|
static class JdkInternals extends Module {
|
||||||
private final String BUNDLE = "com.sun.tools.jdeps.resources.jdkinternals";
|
private final String BUNDLE = "com.sun.tools.jdeps.resources.jdkinternals";
|
||||||
|
|
||||||
private final Set<String> jdkinternals;
|
private final Set<String> jdkinternals;
|
||||||
|
@ -405,6 +405,11 @@ public class Analyzer {
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isJDK() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isExported(String pn) {
|
public boolean isExported(String pn) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -266,7 +266,8 @@ public class DepsAnalyzer {
|
||||||
MODULE_PRIVATE,
|
MODULE_PRIVATE,
|
||||||
QUALIFIED_EXPORTED_API,
|
QUALIFIED_EXPORTED_API,
|
||||||
INTERNAL_API,
|
INTERNAL_API,
|
||||||
JDK_INTERNAL_API
|
JDK_INTERNAL_API,
|
||||||
|
JDK_REMOVED_INTERNAL_API
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Node {
|
public static class Node {
|
||||||
|
@ -372,8 +373,9 @@ public class DepsAnalyzer {
|
||||||
info = Info.EXPORTED_API;
|
info = Info.EXPORTED_API;
|
||||||
} else {
|
} else {
|
||||||
Module module = target.getModule();
|
Module module = target.getModule();
|
||||||
|
if (module == Analyzer.REMOVED_JDK_INTERNALS) {
|
||||||
if (!source.getModule().isJDK() && module.isJDK())
|
info = Info.JDK_REMOVED_INTERNAL_API;
|
||||||
|
} else if (!source.getModule().isJDK() && module.isJDK())
|
||||||
info = Info.JDK_INTERNAL_API;
|
info = Info.JDK_INTERNAL_API;
|
||||||
// qualified exports or inaccessible
|
// qualified exports or inaccessible
|
||||||
else if (module.isExported(pn, source.getModule().name()))
|
else if (module.isExported(pn, source.getModule().name()))
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
package com.sun.tools.jdeps;
|
package com.sun.tools.jdeps;
|
||||||
|
|
||||||
import static com.sun.tools.jdeps.Analyzer.NOT_FOUND;
|
import static com.sun.tools.jdeps.Analyzer.NOT_FOUND;
|
||||||
|
import static com.sun.tools.jdeps.Analyzer.REMOVED_JDK_INTERNALS;
|
||||||
import static com.sun.tools.jdeps.Analyzer.Type.*;
|
import static com.sun.tools.jdeps.Analyzer.Type.*;
|
||||||
import static com.sun.tools.jdeps.JdepsWriter.*;
|
import static com.sun.tools.jdeps.JdepsWriter.*;
|
||||||
import static com.sun.tools.jdeps.JdepsConfiguration.ALL_MODULE_PATH;
|
import static com.sun.tools.jdeps.JdepsConfiguration.ALL_MODULE_PATH;
|
||||||
|
@ -666,19 +667,17 @@ class JdepsTask {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ok && !options.nowarning) {
|
if (!ok && !options.nowarning) {
|
||||||
log.println("Missing dependencies");
|
log.println("ERROR: missing dependencies");
|
||||||
builder.visitMissingDeps(
|
builder.visitMissingDeps(
|
||||||
new Analyzer.Visitor() {
|
new Analyzer.Visitor() {
|
||||||
@Override
|
@Override
|
||||||
public void visitDependence(String origin, Archive originArchive,
|
public void visitDependence(String origin, Archive originArchive,
|
||||||
String target, Archive targetArchive) {
|
String target, Archive targetArchive) {
|
||||||
if (targetArchive == NOT_FOUND)
|
if (builder.notFound(targetArchive))
|
||||||
log.format(" %-50s -> %-50s %s%n",
|
log.format(" %-50s -> %-50s %s%n",
|
||||||
origin, target, targetArchive.getName());
|
origin, target, targetArchive.getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log.println("ERROR: missing dependencies (check \"requires NOT_FOUND;\")");
|
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
package com.sun.tools.jdeps;
|
package com.sun.tools.jdeps;
|
||||||
|
|
||||||
import static com.sun.tools.jdeps.JdepsTask.*;
|
import static com.sun.tools.jdeps.JdepsTask.*;
|
||||||
import static com.sun.tools.jdeps.Analyzer.NOT_FOUND;
|
import static com.sun.tools.jdeps.Analyzer.*;
|
||||||
import static com.sun.tools.jdeps.JdepsFilter.DEFAULT_FILTER;
|
import static com.sun.tools.jdeps.JdepsFilter.DEFAULT_FILTER;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -39,6 +39,7 @@ import java.lang.module.ModuleFinder;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -56,7 +57,10 @@ public class ModuleInfoBuilder {
|
||||||
|
|
||||||
final DependencyFinder dependencyFinder;
|
final DependencyFinder dependencyFinder;
|
||||||
final Analyzer analyzer;
|
final Analyzer analyzer;
|
||||||
final Map<Module, Module> strictModules;
|
|
||||||
|
// an input JAR file (loaded as an automatic module for analysis)
|
||||||
|
// maps to an explicit module to generate module-info.java
|
||||||
|
final Map<Module, Module> automaticToExplicitModule;
|
||||||
public ModuleInfoBuilder(JdepsConfiguration configuration,
|
public ModuleInfoBuilder(JdepsConfiguration configuration,
|
||||||
List<String> args,
|
List<String> args,
|
||||||
Path outputdir) {
|
Path outputdir) {
|
||||||
|
@ -64,27 +68,27 @@ public class ModuleInfoBuilder {
|
||||||
this.outputdir = outputdir;
|
this.outputdir = outputdir;
|
||||||
|
|
||||||
this.dependencyFinder = new DependencyFinder(configuration, DEFAULT_FILTER);
|
this.dependencyFinder = new DependencyFinder(configuration, DEFAULT_FILTER);
|
||||||
this.analyzer = new Analyzer(configuration, Analyzer.Type.CLASS, DEFAULT_FILTER);
|
this.analyzer = new Analyzer(configuration, Type.CLASS, DEFAULT_FILTER);
|
||||||
|
|
||||||
// add targets to modulepath if it has module-info.class
|
// add targets to modulepath if it has module-info.class
|
||||||
List<Path> paths = args.stream()
|
List<Path> paths = args.stream()
|
||||||
.map(fn -> Paths.get(fn))
|
.map(fn -> Paths.get(fn))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// automatic module to convert to strict module
|
// automatic module to convert to explicit module
|
||||||
this.strictModules = ModuleFinder.of(paths.toArray(new Path[0]))
|
this.automaticToExplicitModule = ModuleFinder.of(paths.toArray(new Path[0]))
|
||||||
.findAll().stream()
|
.findAll().stream()
|
||||||
.map(configuration::toModule)
|
.map(configuration::toModule)
|
||||||
.collect(Collectors.toMap(Function.identity(), Function.identity()));
|
.collect(Collectors.toMap(Function.identity(), Function.identity()));
|
||||||
|
|
||||||
Optional<Module> om = strictModules.keySet().stream()
|
Optional<Module> om = automaticToExplicitModule.keySet().stream()
|
||||||
.filter(m -> !m.descriptor().isAutomatic())
|
.filter(m -> !m.descriptor().isAutomatic())
|
||||||
.findAny();
|
.findAny();
|
||||||
if (om.isPresent()) {
|
if (om.isPresent()) {
|
||||||
throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile",
|
throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile",
|
||||||
om.get().getPathName()));
|
om.get().getPathName()));
|
||||||
}
|
}
|
||||||
if (strictModules.isEmpty()) {
|
if (automaticToExplicitModule.isEmpty()) {
|
||||||
throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args));
|
throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,68 +103,90 @@ public class ModuleInfoBuilder {
|
||||||
|
|
||||||
analyzer.run(automaticModules(), dependencyFinder.locationToArchive());
|
analyzer.run(automaticModules(), dependencyFinder.locationToArchive());
|
||||||
|
|
||||||
// computes requires and requires public
|
boolean missingDeps = false;
|
||||||
automaticModules().forEach(m -> {
|
|
||||||
Map<String, Boolean> requires;
|
|
||||||
if (requiresPublic.containsKey(m)) {
|
|
||||||
requires = requiresPublic.get(m).stream()
|
|
||||||
.map(Archive::getModule)
|
|
||||||
.collect(Collectors.toMap(Module::name, (v) -> Boolean.TRUE));
|
|
||||||
} else {
|
|
||||||
requires = new HashMap<>();
|
|
||||||
}
|
|
||||||
analyzer.requires(m)
|
|
||||||
.map(Archive::getModule)
|
|
||||||
.forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE));
|
|
||||||
|
|
||||||
strictModules.put(m, m.toStrictModule(requires));
|
|
||||||
});
|
|
||||||
|
|
||||||
// generate module-info.java
|
|
||||||
descriptors().forEach(md -> writeModuleInfo(outputdir, md));
|
|
||||||
|
|
||||||
// done parsing
|
|
||||||
for (Module m : automaticModules()) {
|
for (Module m : automaticModules()) {
|
||||||
m.close();
|
Set<Archive> apiDeps = requiresPublic.containsKey(m)
|
||||||
|
? requiresPublic.get(m)
|
||||||
|
: Collections.emptySet();
|
||||||
|
|
||||||
|
Path file = outputdir.resolve(m.name()).resolve("module-info.java");
|
||||||
|
|
||||||
|
// computes requires and requires public
|
||||||
|
Module explicitModule = toExplicitModule(m, apiDeps);
|
||||||
|
if (explicitModule != null) {
|
||||||
|
automaticToExplicitModule.put(m, explicitModule);
|
||||||
|
|
||||||
|
// generate module-info.java
|
||||||
|
System.out.format("writing to %s%n", file);
|
||||||
|
writeModuleInfo(file, explicitModule.descriptor());
|
||||||
|
} else {
|
||||||
|
// find missing dependences
|
||||||
|
System.out.format("Missing dependence: %s not generated%n", file);
|
||||||
|
missingDeps = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find any missing dependences
|
return !missingDeps;
|
||||||
return automaticModules().stream()
|
|
||||||
.flatMap(analyzer::requires)
|
|
||||||
.allMatch(m -> !m.equals(NOT_FOUND));
|
|
||||||
} finally {
|
} finally {
|
||||||
dependencyFinder.shutdown();
|
dependencyFinder.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean notFound(Archive m) {
|
||||||
|
return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Module toExplicitModule(Module module, Set<Archive> requiresPublic)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// done analysis
|
||||||
|
module.close();
|
||||||
|
|
||||||
|
if (analyzer.requires(module).anyMatch(this::notFound)) {
|
||||||
|
// missing dependencies
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Boolean> requires = new HashMap<>();
|
||||||
|
requiresPublic.stream()
|
||||||
|
.map(Archive::getModule)
|
||||||
|
.forEach(m -> requires.put(m.name(), Boolean.TRUE));
|
||||||
|
|
||||||
|
analyzer.requires(module)
|
||||||
|
.map(Archive::getModule)
|
||||||
|
.forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE));
|
||||||
|
|
||||||
|
return module.toStrictModule(requires);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the stream of resulting modules
|
* Returns the stream of resulting modules
|
||||||
*/
|
*/
|
||||||
Stream<Module> modules() {
|
Stream<Module> modules() {
|
||||||
return strictModules.values().stream();
|
return automaticToExplicitModule.values().stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the stream of resulting ModuleDescriptors
|
* Returns the stream of resulting ModuleDescriptors
|
||||||
*/
|
*/
|
||||||
public Stream<ModuleDescriptor> descriptors() {
|
public Stream<ModuleDescriptor> descriptors() {
|
||||||
return strictModules.values().stream().map(Module::descriptor);
|
return automaticToExplicitModule.entrySet().stream()
|
||||||
|
.map(Map.Entry::getValue)
|
||||||
|
.map(Module::descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitMissingDeps(Analyzer.Visitor visitor) {
|
void visitMissingDeps(Analyzer.Visitor visitor) {
|
||||||
automaticModules().stream()
|
automaticModules().stream()
|
||||||
.filter(m -> analyzer.requires(m).anyMatch(d -> d.equals(NOT_FOUND)))
|
.filter(m -> analyzer.requires(m).anyMatch(this::notFound))
|
||||||
.forEach(m -> {
|
.forEach(m -> {
|
||||||
analyzer.visitDependences(m, visitor, Analyzer.Type.VERBOSE);
|
analyzer.visitDependences(m, visitor, Analyzer.Type.VERBOSE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void writeModuleInfo(Path dir, ModuleDescriptor descriptor) {
|
|
||||||
String mn = descriptor.name();
|
void writeModuleInfo(Path file, ModuleDescriptor descriptor) {
|
||||||
Path srcFile = dir.resolve(mn).resolve("module-info.java");
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(srcFile.getParent());
|
Files.createDirectories(file.getParent());
|
||||||
System.out.println("writing to " + srcFile);
|
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(file))) {
|
||||||
try (PrintWriter pw = new PrintWriter(Files.newOutputStream(srcFile))) {
|
|
||||||
printModuleInfo(pw, descriptor);
|
printModuleInfo(pw, descriptor);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -197,7 +223,7 @@ public class ModuleInfoBuilder {
|
||||||
|
|
||||||
|
|
||||||
private Set<Module> automaticModules() {
|
private Set<Module> automaticModules() {
|
||||||
return strictModules.keySet();
|
return automaticToExplicitModule.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,10 +11,9 @@ com.sun.tools.javac=Use javax.tools and javax.lang.model @since 1.6
|
||||||
java.awt.peer=Should not use. See https://bugs.openjdk.java.net/browse/JDK-8037739
|
java.awt.peer=Should not use. See https://bugs.openjdk.java.net/browse/JDK-8037739
|
||||||
java.awt.dnd.peer=Should not use. See https://bugs.openjdk.java.net/browse/JDK-8037739
|
java.awt.dnd.peer=Should not use. See https://bugs.openjdk.java.net/browse/JDK-8037739
|
||||||
jdk.internal.ref.Cleaner=Use java.lang.ref.PhantomReference @since 1.2 or java.lang.ref.Cleaner @since 9
|
jdk.internal.ref.Cleaner=Use java.lang.ref.PhantomReference @since 1.2 or java.lang.ref.Cleaner @since 9
|
||||||
sun.awt.image.codec=Use javax.imageio @since 1.4
|
|
||||||
sun.awt.CausedFocusEvent=Use java.awt.event.FocusEvent::getCause @since 9
|
sun.awt.CausedFocusEvent=Use java.awt.event.FocusEvent::getCause @since 9
|
||||||
sun.font.FontUtilities=See java.awt.Font.textRequiresLayout @since 9
|
sun.font.FontUtilities=See java.awt.Font.textRequiresLayout @since 9
|
||||||
sun.reflect.Reflection=See StackWalker API @since 9
|
sun.reflect.Reflection=Use java.lang.StackWalker @since 9
|
||||||
sun.reflect.ReflectionFactory=See http://openjdk.java.net/jeps/260
|
sun.reflect.ReflectionFactory=See http://openjdk.java.net/jeps/260
|
||||||
sun.misc.Unsafe=See http://openjdk.java.net/jeps/260
|
sun.misc.Unsafe=See http://openjdk.java.net/jeps/260
|
||||||
sun.misc.Signal=See http://openjdk.java.net/jeps/260
|
sun.misc.Signal=See http://openjdk.java.net/jeps/260
|
||||||
|
@ -25,11 +24,12 @@ sun.security.provider.PolicyFile=Use java.security.Policy.getInstance("JavaPolic
|
||||||
sun.security.provider.Sun=Use java.security.Security.getProvider(provider-name) @since 1.3
|
sun.security.provider.Sun=Use java.security.Security.getProvider(provider-name) @since 1.3
|
||||||
sun.security.util.SecurityConstants=Use appropriate java.security.Permission subclass @since 1.1
|
sun.security.util.SecurityConstants=Use appropriate java.security.Permission subclass @since 1.1
|
||||||
sun.security.x509.X500Name=Use javax.security.auth.x500.X500Principal @since 1.4
|
sun.security.x509.X500Name=Use javax.security.auth.x500.X500Principal @since 1.4
|
||||||
sun.tools.jar=Use java.util.jar or jar tool @since 1.2\
|
sun.tools.jar=Use java.util.jar or jar tool @since 1.2
|
||||||
# Internal APIs removed in JDK 9
|
# Internal APIs removed in JDK 9
|
||||||
com.apple.eawt=Use java.awt.desktop and JEP 272 @since 9
|
com.apple.eawt=Use java.awt.desktop and JEP 272 @since 9
|
||||||
com.apple.concurrent=Removed. See https://bugs.openjdk.java.net/browse/JDK-8148187
|
com.apple.concurrent=Removed. See https://bugs.openjdk.java.net/browse/JDK-8148187
|
||||||
com.sun.image.codec=Use javax.imageio @since 1.4
|
com.sun.image.codec.jpeg=Use javax.imageio @since 1.4
|
||||||
|
sun.awt.image.codec=Use javax.imageio @since 1.4
|
||||||
sun.misc.BASE64Encoder=Use java.util.Base64 @since 1.8
|
sun.misc.BASE64Encoder=Use java.util.Base64 @since 1.8
|
||||||
sun.misc.BASE64Decoder=Use java.util.Base64 @since 1.8
|
sun.misc.BASE64Decoder=Use java.util.Base64 @since 1.8
|
||||||
sun.misc.Cleaner=Use java.lang.ref.PhantomReference @since 1.2 or java.lang.ref.Cleaner @since 9
|
sun.misc.Cleaner=Use java.lang.ref.PhantomReference @since 1.2 or java.lang.ref.Cleaner @since 9
|
||||||
|
|
148
langtools/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java
Normal file
148
langtools/test/tools/jdeps/jdkinternals/RemovedJDKInternals.java
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8153042
|
||||||
|
* @summary Tests JDK internal APIs that have been removed.
|
||||||
|
* @library ../lib
|
||||||
|
* @build CompilerUtils JdepsUtil ModuleMetaData
|
||||||
|
* @modules jdk.jdeps/com.sun.tools.jdeps
|
||||||
|
* @run testng RemovedJDKInternals
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sun.tools.jdeps.DepsAnalyzer;
|
||||||
|
import com.sun.tools.jdeps.Graph;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class RemovedJDKInternals {
|
||||||
|
private static final String TEST_SRC = System.getProperty("test.src");
|
||||||
|
|
||||||
|
private static final Path CLASSES_DIR = Paths.get("classes");
|
||||||
|
private static final Path PATCHES_DIR = Paths.get("patches");
|
||||||
|
|
||||||
|
private static final String JDK_UNSUPPORTED = "jdk.unsupported";
|
||||||
|
/**
|
||||||
|
* Compiles classes used by the test
|
||||||
|
*/
|
||||||
|
@BeforeTest
|
||||||
|
public void compileAll() throws Exception {
|
||||||
|
CompilerUtils.cleanDir(PATCHES_DIR);
|
||||||
|
CompilerUtils.cleanDir(CLASSES_DIR);
|
||||||
|
|
||||||
|
// compile sun.misc types
|
||||||
|
Path sunMiscSrc = Paths.get(TEST_SRC, "patches", JDK_UNSUPPORTED);
|
||||||
|
Path patchDir = PATCHES_DIR.resolve(JDK_UNSUPPORTED);
|
||||||
|
assertTrue(CompilerUtils.compile(sunMiscSrc, patchDir,
|
||||||
|
"-Xmodule:" + JDK_UNSUPPORTED));
|
||||||
|
|
||||||
|
// compile com.sun.image.codec.jpeg types
|
||||||
|
Path codecSrc = Paths.get(TEST_SRC, "patches", "java.desktop");
|
||||||
|
Path codecDest = PATCHES_DIR;
|
||||||
|
assertTrue(CompilerUtils.compile(codecSrc, codecDest));
|
||||||
|
|
||||||
|
// patch jdk.unsupported and set -cp to codec types
|
||||||
|
assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src"),
|
||||||
|
CLASSES_DIR,
|
||||||
|
"-Xpatch:jdk.unsupported=" + patchDir,
|
||||||
|
"-cp", codecDest.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DataProvider(name = "deps")
|
||||||
|
public Object[][] deps() {
|
||||||
|
return new Object[][] {
|
||||||
|
{ "classes", new ModuleMetaData("classes", false)
|
||||||
|
.reference("p.Main", "java.lang.Class", "java.base")
|
||||||
|
.reference("p.Main", "java.lang.Object", "java.base")
|
||||||
|
.reference("p.Main", "java.util.Iterator", "java.base")
|
||||||
|
.reference("p.S", "java.lang.Object", "java.base")
|
||||||
|
.jdkInternal("p.Main", "sun.reflect.Reflection", "jdk.unsupported")
|
||||||
|
.removedJdkInternal("p.Main", "com.sun.image.codec.jpeg.JPEGCodec")
|
||||||
|
.removedJdkInternal("p.Main", "sun.misc.Service")
|
||||||
|
.removedJdkInternal("p.Main", "sun.misc.SoftCache")
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "deps")
|
||||||
|
public void runTest(String name, ModuleMetaData data) throws Exception {
|
||||||
|
String cmd = String.format("jdeps -verbose:class %s%n", CLASSES_DIR);
|
||||||
|
try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
|
||||||
|
jdeps.verbose("-verbose:class")
|
||||||
|
.addRoot(CLASSES_DIR);
|
||||||
|
|
||||||
|
DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
|
||||||
|
assertTrue(analyzer.run());
|
||||||
|
jdeps.dumpOutput(System.err);
|
||||||
|
|
||||||
|
Graph<DepsAnalyzer.Node> g = analyzer.dependenceGraph();
|
||||||
|
// there are two node with p.Main as origin
|
||||||
|
// one for exported API and one for removed JDK internal
|
||||||
|
g.nodes().stream()
|
||||||
|
.filter(u -> u.source.equals(data.moduleName))
|
||||||
|
.forEach(u -> g.adjacentNodes(u).stream()
|
||||||
|
.forEach(v -> data.checkDependence(u.name, v.name, v.source, v.info)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<String, String> REPLACEMENTS = Map.of(
|
||||||
|
"com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4",
|
||||||
|
"sun.misc.Service", "Use java.util.ServiceLoader @since 1.6",
|
||||||
|
"sun.misc.SoftCache", "Removed. See http://openjdk.java.net/jeps/260",
|
||||||
|
"sun.reflect.Reflection", "Use java.lang.StackWalker @since 9"
|
||||||
|
);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkReplacement() {
|
||||||
|
String[] output = JdepsUtil.jdeps("-jdkinternals", CLASSES_DIR.toString());
|
||||||
|
int i = 0;
|
||||||
|
while (!output[i].contains("Suggested Replacement")) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// must match the number of JDK internal APIs
|
||||||
|
int count = output.length-i-2;
|
||||||
|
assertEquals(count, REPLACEMENTS.size());
|
||||||
|
|
||||||
|
for (int j=i+2; j < output.length; j++) {
|
||||||
|
String line = output[j];
|
||||||
|
int pos = line.indexOf("Use ");
|
||||||
|
if (pos < 0)
|
||||||
|
pos = line.indexOf("Removed. ");
|
||||||
|
|
||||||
|
assertTrue(pos > 0);
|
||||||
|
String name = line.substring(0, pos).trim();
|
||||||
|
String repl = line.substring(pos, line.length()).trim();
|
||||||
|
assertEquals(REPLACEMENTS.get(name), repl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sun.image.codec.jpeg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JDK removed internal API
|
||||||
|
*/
|
||||||
|
public class JPEGCodec {
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sun.misc;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JDK removed internal API
|
||||||
|
*/
|
||||||
|
public final class Service<S> {
|
||||||
|
public static <S> Iterator<S> providers(Class<S> service) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sun.misc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* JDK removed internal API
|
||||||
|
*/
|
||||||
|
public class SoftCache {
|
||||||
|
}
|
45
langtools/test/tools/jdeps/jdkinternals/src/p/Main.java
Normal file
45
langtools/test/tools/jdeps/jdkinternals/src/p/Main.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package p;
|
||||||
|
|
||||||
|
import com.sun.image.codec.jpeg.JPEGCodec;
|
||||||
|
import sun.misc.Service;
|
||||||
|
import sun.misc.SoftCache;
|
||||||
|
import sun.reflect.Reflection;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main() {
|
||||||
|
// in jdk.unsupported
|
||||||
|
Class<?> caller = Reflection.getCallerClass(2);
|
||||||
|
|
||||||
|
// removed
|
||||||
|
JPEGCodec r = new JPEGCodec();
|
||||||
|
|
||||||
|
// removed
|
||||||
|
SoftCache s = new SoftCache();
|
||||||
|
|
||||||
|
// removed
|
||||||
|
Service.providers(S.class);
|
||||||
|
}
|
||||||
|
}
|
27
langtools/test/tools/jdeps/jdkinternals/src/p/S.java
Normal file
27
langtools/test/tools/jdeps/jdkinternals/src/p/S.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package p;
|
||||||
|
|
||||||
|
public interface S {
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ public class ModuleMetaData {
|
||||||
static final String INTERNAL = "(internal)";
|
static final String INTERNAL = "(internal)";
|
||||||
static final String QUALIFIED = "(qualified)";
|
static final String QUALIFIED = "(qualified)";
|
||||||
static final String JDK_INTERNAL = "JDK internal API";
|
static final String JDK_INTERNAL = "JDK internal API";
|
||||||
|
static final String REMOVED_JDK_INTERNAL = "JDK removed internal API";
|
||||||
|
|
||||||
final String moduleName;
|
final String moduleName;
|
||||||
final boolean isNamed;
|
final boolean isNamed;
|
||||||
|
@ -95,6 +96,9 @@ public class ModuleMetaData {
|
||||||
ModuleMetaData jdkInternal(String origin, String target, String module) {
|
ModuleMetaData jdkInternal(String origin, String target, String module) {
|
||||||
return dependence(origin, target, module, JDK_INTERNAL);
|
return dependence(origin, target, module, JDK_INTERNAL);
|
||||||
}
|
}
|
||||||
|
ModuleMetaData removedJdkInternal(String origin, String target) {
|
||||||
|
return dependence(origin, target, REMOVED_JDK_INTERNAL, REMOVED_JDK_INTERNAL);
|
||||||
|
}
|
||||||
|
|
||||||
ModuleMetaData exports(String pn, Set<String> targets) {
|
ModuleMetaData exports(String pn, Set<String> targets) {
|
||||||
exports.put(pn, targets);
|
exports.put(pn, targets);
|
||||||
|
@ -154,6 +158,8 @@ public class ModuleMetaData {
|
||||||
access = QUALIFIED;
|
access = QUALIFIED;
|
||||||
else if (info == JDK_INTERNAL_API)
|
else if (info == JDK_INTERNAL_API)
|
||||||
access = JDK_INTERNAL;
|
access = JDK_INTERNAL;
|
||||||
|
else if (info == JDK_REMOVED_INTERNAL_API)
|
||||||
|
access = REMOVED_JDK_INTERNAL;
|
||||||
else if (info == INTERNAL_API)
|
else if (info == INTERNAL_API)
|
||||||
access = INTERNAL;
|
access = INTERNAL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue