mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8137075: Sjavac tests are leaking file managers
Closing sjavac file managers. Reviewed-by: jjg
This commit is contained in:
parent
7e33756aa5
commit
7cf539d35e
4 changed files with 26 additions and 18 deletions
|
@ -527,7 +527,7 @@ public class JavacState {
|
||||||
* Compare the javac_state recorded public apis of packages on the classpath
|
* Compare the javac_state recorded public apis of packages on the classpath
|
||||||
* with the actual public apis on the classpath.
|
* with the actual public apis on the classpath.
|
||||||
*/
|
*/
|
||||||
public void taintPackagesDependingOnChangedClasspathPackages() {
|
public void taintPackagesDependingOnChangedClasspathPackages() throws IOException {
|
||||||
|
|
||||||
// 1. Collect fully qualified names of all interesting classpath dependencies
|
// 1. Collect fully qualified names of all interesting classpath dependencies
|
||||||
Set<String> fqDependencies = new HashSet<>();
|
Set<String> fqDependencies = new HashSet<>();
|
||||||
|
@ -549,6 +549,7 @@ public class JavacState {
|
||||||
for (String cpDep : fqDependencies) {
|
for (String cpDep : fqDependencies) {
|
||||||
onDiskPubApi.put(cpDep, pubApiExtractor.getPubApi(cpDep));
|
onDiskPubApi.put(cpDep, pubApiExtractor.getPubApi(cpDep));
|
||||||
}
|
}
|
||||||
|
pubApiExtractor.close();
|
||||||
|
|
||||||
// 3. Compare them with the public APIs as of last compilation (loaded from javac_state)
|
// 3. Compare them with the public APIs as of last compilation (loaded from javac_state)
|
||||||
nextPkg:
|
nextPkg:
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package com.sun.tools.sjavac;
|
package com.sun.tools.sjavac;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@ -46,8 +47,10 @@ import com.sun.tools.sjavac.pubapi.PubApi;
|
||||||
public class PubApiExtractor {
|
public class PubApiExtractor {
|
||||||
// Setup a compiler context for finding classes in the classpath
|
// Setup a compiler context for finding classes in the classpath
|
||||||
// and to execute annotation processors.
|
// and to execute annotation processors.
|
||||||
Context context;
|
final Context context;
|
||||||
CompilationTask task;
|
final CompilationTask task;
|
||||||
|
|
||||||
|
final SmartFileManager fileManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup a compilation context, used for reading public apis of classes on the classpath
|
* Setup a compilation context, used for reading public apis of classes on the classpath
|
||||||
|
@ -55,7 +58,7 @@ public class PubApiExtractor {
|
||||||
*/
|
*/
|
||||||
public PubApiExtractor(Options options) {
|
public PubApiExtractor(Options options) {
|
||||||
JavacTool compiler = com.sun.tools.javac.api.JavacTool.create();
|
JavacTool compiler = com.sun.tools.javac.api.JavacTool.create();
|
||||||
SmartFileManager fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
|
fileManager = new SmartFileManager(compiler.getStandardFileManager(null, null, null));
|
||||||
context = new com.sun.tools.javac.util.Context();
|
context = new com.sun.tools.javac.util.Context();
|
||||||
String[] args = options.prepJavacArgs();
|
String[] args = options.prepJavacArgs();
|
||||||
task = compiler.getTask(new PrintWriter(System.err),
|
task = compiler.getTask(new PrintWriter(System.err),
|
||||||
|
@ -82,4 +85,8 @@ public class PubApiExtractor {
|
||||||
v.visit(cs);
|
v.visit(cs);
|
||||||
return v.getCollectedPubApi();
|
return v.getCollectedPubApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
fileManager.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,21 +209,20 @@ public class SjavacImpl implements Sjavac {
|
||||||
// Go through all sources and taint all packages that miss artifacts.
|
// Go through all sources and taint all packages that miss artifacts.
|
||||||
javac_state.taintPackagesThatMissArtifacts();
|
javac_state.taintPackagesThatMissArtifacts();
|
||||||
|
|
||||||
// Check recorded classpath public apis. Taint packages that depend on
|
|
||||||
// classpath classes whose public apis have changed.
|
|
||||||
javac_state.taintPackagesDependingOnChangedClasspathPackages();
|
|
||||||
|
|
||||||
// Now clean out all known artifacts belonging to tainted packages.
|
|
||||||
javac_state.deleteClassArtifactsInTaintedPackages();
|
|
||||||
// Copy files, for example property files, images files, xml files etc etc.
|
|
||||||
javac_state.performCopying(Util.pathToFile(options.getDestDir()), suffixRules);
|
|
||||||
// Translate files, for example compile properties or compile idls.
|
|
||||||
javac_state.performTranslation(Util.pathToFile(gensrc), suffixRules);
|
|
||||||
// Add any potentially generated java sources to the tobe compiled list.
|
|
||||||
// (Generated sources must always have a package.)
|
|
||||||
Map<String,Source> generated_sources = new HashMap<>();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Check recorded classpath public apis. Taint packages that depend on
|
||||||
|
// classpath classes whose public apis have changed.
|
||||||
|
javac_state.taintPackagesDependingOnChangedClasspathPackages();
|
||||||
|
|
||||||
|
// Now clean out all known artifacts belonging to tainted packages.
|
||||||
|
javac_state.deleteClassArtifactsInTaintedPackages();
|
||||||
|
// Copy files, for example property files, images files, xml files etc etc.
|
||||||
|
javac_state.performCopying(Util.pathToFile(options.getDestDir()), suffixRules);
|
||||||
|
// Translate files, for example compile properties or compile idls.
|
||||||
|
javac_state.performTranslation(Util.pathToFile(gensrc), suffixRules);
|
||||||
|
// Add any potentially generated java sources to the tobe compiled list.
|
||||||
|
// (Generated sources must always have a package.)
|
||||||
|
Map<String,Source> generated_sources = new HashMap<>();
|
||||||
|
|
||||||
Source.scanRoot(Util.pathToFile(options.getGenSrcDir()), Util.set(".java"), null, null, null, null,
|
Source.scanRoot(Util.pathToFile(options.getGenSrcDir()), Util.set(".java"), null, null, null, null,
|
||||||
generated_sources, modules, current_module, false, true, false);
|
generated_sources, modules, current_module, false, true, false);
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class ApiExtraction {
|
||||||
Options options = Options.parseArgs("-d", "bin", "--state-dir=bin", "-cp", ".");
|
Options options = Options.parseArgs("-d", "bin", "--state-dir=bin", "-cp", ".");
|
||||||
PubApiExtractor pubApiExtr = new PubApiExtractor(options);
|
PubApiExtractor pubApiExtr = new PubApiExtractor(options);
|
||||||
PubApi actualApi = pubApiExtr.getPubApi("TestClass");
|
PubApi actualApi = pubApiExtr.getPubApi("TestClass");
|
||||||
|
pubApiExtr.close();
|
||||||
|
|
||||||
// Validate result
|
// Validate result
|
||||||
PubApi expectedApi = getExpectedPubApi();
|
PubApi expectedApi = getExpectedPubApi();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue