8137075: Sjavac tests are leaking file managers

Closing sjavac file managers.

Reviewed-by: jjg
This commit is contained in:
Andreas Lundblad 2015-11-03 21:29:46 +01:00
parent 7e33756aa5
commit 7cf539d35e
4 changed files with 26 additions and 18 deletions

View file

@ -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:

View file

@ -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();
}
} }

View file

@ -209,6 +209,7 @@ 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();
try {
// Check recorded classpath public apis. Taint packages that depend on // Check recorded classpath public apis. Taint packages that depend on
// classpath classes whose public apis have changed. // classpath classes whose public apis have changed.
javac_state.taintPackagesDependingOnChangedClasspathPackages(); javac_state.taintPackagesDependingOnChangedClasspathPackages();
@ -223,8 +224,6 @@ public class SjavacImpl implements Sjavac {
// (Generated sources must always have a package.) // (Generated sources must always have a package.)
Map<String,Source> generated_sources = new HashMap<>(); Map<String,Source> generated_sources = new HashMap<>();
try {
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);
javac_state.now().flattenPackagesSourcesAndArtifacts(modules); javac_state.now().flattenPackagesSourcesAndArtifacts(modules);

View file

@ -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();