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
* 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
Set<String> fqDependencies = new HashSet<>();
@ -549,6 +549,7 @@ public class JavacState {
for (String cpDep : fqDependencies) {
onDiskPubApi.put(cpDep, pubApiExtractor.getPubApi(cpDep));
}
pubApiExtractor.close();
// 3. Compare them with the public APIs as of last compilation (loaded from javac_state)
nextPkg:

View file

@ -25,6 +25,7 @@
package com.sun.tools.sjavac;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
@ -46,8 +47,10 @@ import com.sun.tools.sjavac.pubapi.PubApi;
public class PubApiExtractor {
// Setup a compiler context for finding classes in the classpath
// and to execute annotation processors.
Context context;
CompilationTask task;
final Context context;
final CompilationTask task;
final SmartFileManager fileManager;
/**
* 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) {
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();
String[] args = options.prepJavacArgs();
task = compiler.getTask(new PrintWriter(System.err),
@ -82,4 +85,8 @@ public class PubApiExtractor {
v.visit(cs);
return v.getCollectedPubApi();
}
public void close() throws IOException {
fileManager.close();
}
}

View file

@ -209,21 +209,20 @@ public class SjavacImpl implements Sjavac {
// Go through all sources and taint all packages that miss artifacts.
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 {
// 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,
generated_sources, modules, current_module, false, true, false);

View file

@ -92,6 +92,7 @@ public class ApiExtraction {
Options options = Options.parseArgs("-d", "bin", "--state-dir=bin", "-cp", ".");
PubApiExtractor pubApiExtr = new PubApiExtractor(options);
PubApi actualApi = pubApiExtr.getPubApi("TestClass");
pubApiExtr.close();
// Validate result
PubApi expectedApi = getExpectedPubApi();