diff --git a/test/tools/pack200/AttributeTests.java b/test/tools/pack200/AttributeTests.java index bcf4c7c92825114a9f6943b00ef89b181cf08e2c..09b9986175cf090aaec9346c2e4d8d8975f60af0 100644 --- a/test/tools/pack200/AttributeTests.java +++ b/test/tools/pack200/AttributeTests.java @@ -37,6 +37,7 @@ public class AttributeTests { public static void main(String... args) throws Exception { test6746111(); testMethodParameters(); + Utils.cleanup(); } /* diff --git a/test/tools/pack200/BandIntegrity.java b/test/tools/pack200/BandIntegrity.java index 1145972267f11d1c4260d270b18301afe5cb611b..2a59f3b8c1397f119d7d918eda86f0d02adb59d4 100644 --- a/test/tools/pack200/BandIntegrity.java +++ b/test/tools/pack200/BandIntegrity.java @@ -40,7 +40,7 @@ import java.util.List; * the java packer and unpacker must be called in the same java instance. */ public class BandIntegrity { - public static void main(String... args) throws IOException { + public static void main(String... args) throws IOException { File testFile = new File("test.jar"); Utils.jar("cvf", testFile.getName(), "-C", Utils.TEST_CLS_DIR.getAbsolutePath(), @@ -56,6 +56,7 @@ public class BandIntegrity { Utils.createFile(configFile, scratch); File outFile = new File("out.jar"); Utils.repack(testFile, outFile, true, - "-v", "--config-file=" + configFile.getName()); + "-v", "--config-file=" + configFile.getName()); + Utils.cleanup(); } } diff --git a/test/tools/pack200/CommandLineTests.java b/test/tools/pack200/CommandLineTests.java index 4e0c8b1e0036ff23e755f74f042dd9ec3e235984..2a53b30904600f66237aaf26179b6c552ad50eee 100644 --- a/test/tools/pack200/CommandLineTests.java +++ b/test/tools/pack200/CommandLineTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -83,6 +83,11 @@ public class CommandLineTests { Utils.recursiveCopy(Utils.JavaSDK, EXP_SDK); creatConfigFile(); } + // cleanup the test area + static void cleanup() throws IOException { + Utils.recursiveDelete(EXP_SDK); + Utils.cleanup(); + } // Hopefully, this should be kept in sync with what the installer does. static void creatConfigFile() throws IOException { @@ -172,6 +177,7 @@ public class CommandLineTests { init(); testJRE(); testJDK(); + cleanup(); // cleanup only if we pass successfully } catch (IOException ioe) { throw new RuntimeException(ioe); } diff --git a/test/tools/pack200/InstructionTests.java b/test/tools/pack200/InstructionTests.java index 171fe4ee88a24e8377e9c84c4bcf80de42d7bb13..569b7a0acb09fbdb1c979f60ddd2d10b5e2d8ff8 100644 --- a/test/tools/pack200/InstructionTests.java +++ b/test/tools/pack200/InstructionTests.java @@ -35,6 +35,7 @@ import java.util.List; public class InstructionTests { public static void main(String... args) throws Exception { testInvokeOpCodes(); + Utils.cleanup(); } /* * the following should produce invokestatic and invokespecial diff --git a/test/tools/pack200/Pack200Props.java b/test/tools/pack200/Pack200Props.java index 61b718ea9d9d58959b916c6a1cda51342539e6df..50fb0b147430999c7962ef8a717a537448ec0d0b 100644 --- a/test/tools/pack200/Pack200Props.java +++ b/test/tools/pack200/Pack200Props.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,7 @@ */ import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -45,11 +46,12 @@ import java.util.jar.Pack200.Packer; public class Pack200Props { - public static void main(String... args) { + public static void main(String... args) throws IOException { verifyDefaults(); File out = new File("test" + Utils.PACK_FILE_EXT); out.delete(); verifySegmentLimit(out); + Utils.cleanup(); } static void verifySegmentLimit(File outFile) { diff --git a/test/tools/pack200/Pack200Test.java b/test/tools/pack200/Pack200Test.java index d897bf8682491d12d56a7c8a3526717d05277a31..b4226f2845a4e986c64499318a11e555369a2bae 100644 --- a/test/tools/pack200/Pack200Test.java +++ b/test/tools/pack200/Pack200Test.java @@ -66,7 +66,7 @@ public class Pack200Test { } } - private static void doPackUnpack() { + private static void doPackUnpack() throws IOException { for (File in : jarList) { JarOutputStream javaUnpackerStream = null; JarOutputStream nativeUnpackerStream = null; @@ -117,12 +117,13 @@ public class Pack200Test { Utils.close((Closeable) jarFile); } } + Utils.cleanup(); // cleanup artifacts, if successful run } /** * @param args the command line arguments */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { // select the jars carefully, adding more jars will increase the // testing time, especially for jprt. jarList.add(Utils.locateJar("tools.jar")); diff --git a/test/tools/pack200/PackageVersionTest.java b/test/tools/pack200/PackageVersionTest.java index fe6d5d9cb596d8a7040ae29300d3afb77934721e..dc109b8a39188d508715a89847cb4446fd812216 100644 --- a/test/tools/pack200/PackageVersionTest.java +++ b/test/tools/pack200/PackageVersionTest.java @@ -1,6 +1,5 @@ - /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,7 +53,7 @@ public class PackageVersionTest { public final static int JAVA7_PACKAGE_MAJOR_VERSION = 170; public final static int JAVA7_PACKAGE_MINOR_VERSION = 1; - public static void main(String... args) { + public static void main(String... args) throws IOException { if (!javaHome.getName().endsWith("jre")) { throw new RuntimeException("Error: requires an SDK to run"); } @@ -78,6 +77,7 @@ public class PackageVersionTest { // test for resource file, ie. no class files verifyPack("Test6.java", JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION); + Utils.cleanup(); } static void verify6991164() { diff --git a/test/tools/pack200/RepackTest.java b/test/tools/pack200/RepackTest.java index 774e0d66eb3141201364bfc32c76c4fef0136187..8a3d86e7c94c12fc7163c547d7daccc84d589d3e 100644 --- a/test/tools/pack200/RepackTest.java +++ b/test/tools/pack200/RepackTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ public class RepackTest { public static void main(String... args) throws Exception { testRepack(); + Utils.cleanup(); } /* diff --git a/test/tools/pack200/T7007157.java b/test/tools/pack200/T7007157.java index 72f8792c22b6888a24d950f36d3d247e834abf52..29a8ca7fc1faac2b23c23bb73982a18ec87e982f 100644 --- a/test/tools/pack200/T7007157.java +++ b/test/tools/pack200/T7007157.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,5 +63,6 @@ public class T7007157 { Utils.close(fos); Utils.close(jarFile); } + Utils.cleanup(); } } diff --git a/test/tools/pack200/TestExceptions.java b/test/tools/pack200/TestExceptions.java index 0778cf5c7e17fe4a837b9acd4a91e045871cf9c9..1b6f39a78cc8e56b17f2f0ee7a2a76af8af7ea38 100644 --- a/test/tools/pack200/TestExceptions.java +++ b/test/tools/pack200/TestExceptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -219,12 +219,13 @@ public class TestExceptions { } } - public static void main(String... args) { + public static void main(String... args) throws IOException { init(); pack200Test1(); pack200Test2(); pack200Test3(); unpack200Test1(); + Utils.cleanup(); } // containers for test inputs and management diff --git a/test/tools/pack200/TimeStamp.java b/test/tools/pack200/TimeStamp.java index 8dfc2d9bc2ea5fe13323b0b1ee86709a859b8ef2..acce4624aab82c026d4a30f64975b1a9dc210ca6 100644 --- a/test/tools/pack200/TimeStamp.java +++ b/test/tools/pack200/TimeStamp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -149,6 +149,7 @@ public class TimeStamp { Utils.close(jf1); Utils.close(jf2); } + Utils.cleanup(); if (errors > 0) { throw new RuntimeException("FAIL:" + errors + " error(s) encounted"); } diff --git a/test/tools/pack200/UnpackerMemoryTest.java b/test/tools/pack200/UnpackerMemoryTest.java index fc63d154f9061e68738a9d09383aecbe9808e3fb..ec8ffb6a402aa17c3cff8bf324d135c26da6792d 100644 --- a/test/tools/pack200/UnpackerMemoryTest.java +++ b/test/tools/pack200/UnpackerMemoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -81,6 +81,7 @@ public class UnpackerMemoryTest { Utils.close(fos); } } + Utils.cleanup(); } } diff --git a/test/tools/pack200/Utils.java b/test/tools/pack200/Utils.java index df3426431d4d56974830f2f015179272aa1f9eb1..b1bc2f894b1cebaf01d408f2f37ef8aa515f9186 100644 --- a/test/tools/pack200/Utils.java +++ b/test/tools/pack200/Utils.java @@ -75,6 +75,7 @@ class Utils { static final File TEST_CLS_DIR = new File(System.getProperty("test.classes")); static final String VERIFIER_DIR_NAME = "pack200-verifier"; static final File VerifierJar = new File(VERIFIER_DIR_NAME + JAR_FILE_EXT); + static final File XCLASSES = new File("xclasses"); private Utils() {} // all static @@ -95,8 +96,7 @@ class Utils { } List javaFileList = findFiles(srcDir, createFilter(JAVA_FILE_EXT)); File tmpFile = File.createTempFile("javac", ".tmp"); - File classesDir = new File("xclasses"); - classesDir.mkdirs(); + XCLASSES.mkdirs(); FileOutputStream fos = null; PrintStream ps = null; try { @@ -111,14 +111,14 @@ class Utils { } compiler("-d", - "xclasses", + XCLASSES.getName(), "@" + tmpFile.getAbsolutePath()); jar("cvfe", VerifierJar.getName(), "sun.tools.pack.verify.Main", "-C", - "xclasses", + XCLASSES.getName(), "."); } @@ -175,6 +175,33 @@ class Utils { }; } + /* + * clean up all the usual suspects + */ + static void cleanup() throws IOException { + recursiveDelete(XCLASSES); + List toDelete = new ArrayList<>(); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".out"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".bak"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".jar"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".pack"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".bnd"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".txt"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".idx"))); + toDelete.addAll(Utils.findFiles(new File("."), + Utils.createFilter(".gidx"))); + for (File f : toDelete) { + f.delete(); + } + } + static final FileFilter DIR_FILTER = new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { @@ -199,6 +226,9 @@ class Utils { Files.createDirectories(parent); } Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); + if (dst.isDirectory() && !dst.canWrite()) { + dst.setWritable(true); + } } static String baseName(File file, String extension) { diff --git a/test/tools/pack200/typeannos/TestTypeAnnotations.java b/test/tools/pack200/typeannos/TestTypeAnnotations.java index 598185aaabc783ba4f1128f8c7e99a059f7875ad..f00801b5b14c5fa6956fbc1fe24bb357fb4b330b 100644 --- a/test/tools/pack200/typeannos/TestTypeAnnotations.java +++ b/test/tools/pack200/typeannos/TestTypeAnnotations.java @@ -41,5 +41,6 @@ public class TestTypeAnnotations { "-C", Utils.TEST_CLS_DIR.getAbsolutePath(), "."); Utils.testWithRepack(testFile, "--unknown-attribute=error"); + Utils.cleanup(); } }