diff options
author | Stephan Herrmann | 2011-11-09 14:49:26 +0000 |
---|---|---|
committer | Stephan Herrmann | 2011-11-09 14:49:26 +0000 |
commit | 2a6ccc4326c5f51715033b769f3fad2752538c59 (patch) | |
tree | 28744b910bfa3164779b643fb49992dc85796c12 /org.eclipse.jdt.compiler.tool.tests | |
parent | 24886323fed59fa7df90089efb8e6a1735628edf (diff) | |
download | eclipse.jdt.core-2a6ccc4326c5f51715033b769f3fad2752538c59.tar.gz eclipse.jdt.core-2a6ccc4326c5f51715033b769f3fad2752538c59.tar.xz eclipse.jdt.core-2a6ccc4326c5f51715033b769f3fad2752538c59.zip |
HEAD - Fixed bug 363293: resource leaks in
org.eclipse.jdt.compiler.tool.tests
Diffstat (limited to 'org.eclipse.jdt.compiler.tool.tests')
3 files changed, 32 insertions, 14 deletions
diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java index cd6cbfe4c4..cb2623330e 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java @@ -12,6 +12,7 @@ package org.eclipse.jdt.compiler.tool.tests; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -98,16 +99,24 @@ public class AbstractCompilerToolTest extends BatchCompilerTest { if (manager == null) { manager = COMPILER.getStandardFileManager(null, null, null); // will pick defaults up } - List<File> files = new ArrayList<File>(); - String[] fileNames = arguments.fileNames; - for (int i = 0, l = fileNames.length; i < l; i++) { - if (fileNames[i].startsWith(OUTPUT_DIR)) { - files.add(new File(fileNames[i])); - } else { - files.add(new File(OUTPUT_DIR + File.separator + fileNames[i])); + try { + List<File> files = new ArrayList<File>(); + String[] fileNames = arguments.fileNames; + for (int i = 0, l = fileNames.length; i < l; i++) { + if (fileNames[i].startsWith(OUTPUT_DIR)) { + files.add(new File(fileNames[i])); + } else { + files.add(new File(OUTPUT_DIR + File.separator + fileNames[i])); + } } - } - CompilationTask task = COMPILER.getTask(out, arguments.standardJavaFileManager /* carry the null over */, new CompilerInvocationDiagnosticListener(err), arguments.options, null, manager.getJavaFileObjectsFromFiles(files)); - return task.call(); + CompilationTask task = COMPILER.getTask(out, arguments.standardJavaFileManager /* carry the null over */, new CompilerInvocationDiagnosticListener(err), arguments.options, null, manager.getJavaFileObjectsFromFiles(files)); + return task.call(); + } finally { + try { + manager.close(); + } catch (IOException e) { + // nop + } + } } } diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java index 60be95f52c..09a1689d3f 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java @@ -502,7 +502,9 @@ public void test007_options_consumption() throws IOException { remaining = remainingAsList.iterator(); assertTrue("does not support -d option", javacStandardJavaFileManager.handleOption("-d", remaining)); assertEquals("unexpected consumption rate", "remainder", remaining.next()); + javacStandardJavaFileManager.close(); } + ecjStandardJavaFileManager.close(); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=226918 // options consumption - check consumption rate on supported zero-args options @@ -525,6 +527,7 @@ public void test008_options_consumption() throws IOException { assertEquals("unexpected consumption rate", REMAINDER, remaining.next()); } } + ecjStandardJavaFileManager.close(); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=226918 // options consumption - check consumption rate on supported one-arg options @@ -540,6 +543,7 @@ public void test009_options_consumption() throws IOException { assertEquals("unexpected consumption rate", REMAINDER, remaining.next()); } } + ecjStandardJavaFileManager.close(); } // tests #10-11 show that ecj throws a RuntimeException when encountering a wrong // encoding in its parameters, while the default compiler swallows it silently diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java index 84e2c1f422..bf44e407ca 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java @@ -19,6 +19,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -604,7 +605,7 @@ static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { assertTrue("delete failed", inputFile.delete()); } - public void testCompilerOneClassWithEclipseCompiler4() { + public void testCompilerOneClassWithEclipseCompiler4() throws IOException { JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler(); if (systemCompiler == null) { System.out.println("No system java compiler available"); @@ -653,6 +654,7 @@ static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { } // check that the .class file exist for X assertTrue("delete failed", inputFile.delete()); + manager.close(); } public void testCompilerOneClassWithEclipseCompiler5() { @@ -869,6 +871,7 @@ static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { builder.append(name.substring(lastIndexOf + 1)); } assertEquals("Wrong contents", "X.java", String.valueOf(builder)); + fileManager.close(); } catch (IOException e) { e.printStackTrace(); } @@ -934,15 +937,17 @@ static final String[] FAKE_ZERO_ARG_OPTIONS = new String[] { Iterable<? extends JavaFileObject> compilationUnits = fileManager.list(sourceLoc, "", fileTypes, true); Iterator<? extends JavaFileObject> it = compilationUnits.iterator(); - StringBuilder builder = new StringBuilder(); + List<String> names = new ArrayList<String>(); while (it.hasNext()) { JavaFileObject next = it.next(); String name = next.getName(); name = name.replace('\\', '/'); int lastIndexOf = name.lastIndexOf('/'); - builder.append(name.substring(lastIndexOf + 1)); + names.add(name.substring(lastIndexOf + 1)); } - assertEquals("Wrong contents", "X2.javaX.java", String.valueOf(builder)); + Collections.sort(names); + assertEquals("Wrong contents", "[X.java, X2.java]", names.toString()); + fileManager.close(); } catch (IOException e) { e.printStackTrace(); } |