--- a/langtools/test/tools/javac/T6558476.java Mon Oct 27 14:55:47 2014 +0100
+++ b/langtools/test/tools/javac/T6558476.java Mon Oct 27 10:43:09 2014 -0700
@@ -23,8 +23,10 @@
/*
* @test
- * @bug 6558476
+ * @bug 6558476 5071352
* @summary com/sun/tools/javac/Main.compile don't release file handles on return
+ * @library /tools/lib
+ * @build ToolBox
* @run main/othervm -Xmx512m -Xms512m T6558476
*/
@@ -37,66 +39,34 @@
import com.sun.tools.javac.Main;
public class T6558476 {
- private static File copyFileTo(File file, File directory) throws IOException {
- File newFile = new File(directory, file.getName());
- FileInputStream fis = null;
- FileOutputStream fos = null;
- try {
- fis = new FileInputStream(file);
- fos = new FileOutputStream(newFile);
- byte buff[] = new byte[1024];
- int val;
- while ((val = fis.read(buff)) > 0)
- fos.write(buff, 0, val);
- } finally {
- if (fis != null)
- fis.close();
- if (fos != null)
- fos.close();
- }
- return newFile;
- }
- private static String generateJavaClass(String className) {
- StringBuffer sb = new StringBuffer();
- sb.append("import sun.net.spi.nameservice.dns.DNSNameService;\n");
- sb.append("public class ");
- sb.append(className);
- sb.append(" {\n");
- sb.append(" public void doStuff() {\n");
- sb.append(" DNSNameService dns = null;\n");
- sb.append(" }\n");
- sb.append("}\n");
- return sb.toString();
- }
+ private static final String classFoo = "class Foo {}";
+ private static final String classMyFoo =
+ "class MyFoo {\n" +
+ " public static void main(String[] args) {\n"+
+ " new Foo();\n"+
+ " }\n"+
+ "}";
public static void main(String[] args) throws IOException {
- File javaHomeDir = new File(System.getProperty("java.home"));
- File outputDir = new File("outputDir" + new Random().nextInt(65536));
- outputDir.mkdir();
- outputDir.deleteOnExit();
+ ToolBox tb = new ToolBox();
- File dnsjarfile = new File(javaHomeDir, "lib" + File.separator + "ext" + File.separator + "dnsns.jar");
- File tmpJar = copyFileTo(dnsjarfile, outputDir);
- String className = "TheJavaFile";
- File javaFile = new File(outputDir, className + ".java");
- javaFile.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(javaFile);
- fos.write(generateJavaClass(className).getBytes());
- fos.close();
+ tb.new JavacTask()
+ .sources(classFoo)
+ .run();
+ tb.new JarTask("foo.jar")
+ .files("Foo.class")
+ .run();
- int rc = Main.compile(new String[]{"-d", outputDir.getPath(),
- "-classpath",
- tmpJar.getPath(),
- javaFile.getAbsolutePath()});
- if (rc != 0) {
- throw new Error("Couldn't compile the file (exit code=" + rc + ")");
- }
-
- if (tmpJar.delete()) {
+ tb.new JavacTask()
+ .classpath("foo.jar")
+ .sources(classMyFoo)
+ .run();
+ File foo_jar = new File("foo.jar");
+ if (foo_jar.delete()) {
System.out.println("jar file successfully deleted");
} else {
- throw new Error("Error deleting file \"" + tmpJar.getPath() + "\"");
+ throw new Error("Error deleting file \"" + foo_jar.getPath() + "\"");
}
}
}
--- a/langtools/test/tools/javap/T6729471.java Mon Oct 27 14:55:47 2014 +0100
+++ b/langtools/test/tools/javap/T6729471.java Mon Oct 27 10:43:09 2014 -0700
@@ -25,7 +25,10 @@
/*
* @test
* @bug 6729471
- * @summary javap does not output inner interfaces of an interface
+ * @summary javap should accept class files on the command line
+ * @library /tools/lib
+ * @build ToolBox
+ * @run main T6729471
*/
import java.io.*;
@@ -57,30 +60,26 @@
verify(new File(testClasses, "T6729471.class").toURI().toString(),
"public static void main(java.lang.String...)");
- // jar url: rt.jar
- File java_home = new File(System.getProperty("java.home"));
- if (java_home.getName().equals("jre"))
- java_home = java_home.getParentFile();
- File rt_jar = new File(new File(new File(java_home, "jre"), "lib"), "rt.jar");
+ // jar url
+ // Create a temp jar
+ ToolBox tb = new ToolBox();
+ tb.new JavacTask()
+ .sources("class Foo { public void sayHello() {} }")
+ .run();
+ String foo_jar = "foo.jar";
+ tb.new JarTask(foo_jar)
+ .files("Foo.class")
+ .run();
+ File foo_jarFile = new File(foo_jar);
+
+ // Verify
try {
- verify("jar:" + rt_jar.toURL() + "!/java/util/Map.class",
- "public abstract boolean containsKey(java.lang.Object)");
+ verify("jar:" + foo_jarFile.toURL() + "!/Foo.class",
+ "public void sayHello()");
} catch (MalformedURLException e) {
error(e.toString());
}
- // jar url: ct.sym, if it exists
- File ct_sym = new File(new File(java_home, "lib"), "ct.sym");
- if (ct_sym.exists()) {
- try {
- verify("jar:" + ct_sym.toURL() + "!/META-INF/sym/rt.jar/java/util/Map.class",
- "public abstract boolean containsKey(java.lang.Object)");
- } catch (MalformedURLException e) {
- error(e.toString());
- }
- } else
- System.err.println("warning: ct.sym not found");
-
if (errors > 0)
throw new Error(errors + " found.");
}