Java Code Examples for jdk.testlibrary.FileUtils#deleteFileTreeWithRetry()
The following examples show how to use
jdk.testlibrary.FileUtils#deleteFileTreeWithRetry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test // META-INF/versions/9 contains an extra package private class -- this is okay public void test06() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); // add the new v9 class Path source = Paths.get(src, "data", "test06", "v9", "version"); javac(classes.resolve("v9"), source.resolve("Extra.java")); jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".", "--release", "9", "-C", classes.resolve("v9").toString(), ".") .shouldHaveExitValue(SUCCESS); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 2
Source File: JmodTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void testMissingPackages() throws IOException { Path apaDir = EXPLODED_DIR.resolve("apa"); Path classesDir = EXPLODED_DIR.resolve("apa").resolve("classes"); if (Files.exists(classesDir)) FileUtils.deleteFileTreeWithRetry(classesDir); assertTrue(compileModule("apa", classesDir)); FileUtils.deleteFileTreeWithRetry(classesDir.resolve("jdk")); Path jmod = MODS_DIR.resolve("apa.jmod"); jmod("create", "--class-path", classesDir.toString(), jmod.toString()) .assertFailure() .resultChecker(r -> { assertContains(r.output, "Packages that are exported or open in apa are not present: [jdk.test.apa]"); }); if (Files.exists(classesDir)) FileUtils.deleteFileTreeWithRetry(classesDir); }
Example 3
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test // create a regular, non-multi-release jar public void test00() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".") .shouldHaveExitValue(SUCCESS); checkMultiRelease(jarfile, false); Map<String, String[]> names = Map.of( "version/Main.class", new String[]{"base", "version", "Main.class"}, "version/Version.class", new String[]{"base", "version", "Version.class"} ); compare(jarfile, names); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 4
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test // META-INF/versions/9 contains an identical class to base entry class // this is okay but produces warning public void test07() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); // add the new v9 class Path source = Paths.get(src, "data", "test01", "base", "version"); javac(classes.resolve("v9"), source.resolve("Version.java")); jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".", "--release", "9", "-C", classes.resolve("v9").toString(), ".") .shouldHaveExitValue(SUCCESS) .shouldContain("contains a class that") .shouldContain("is identical"); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 5
Source File: CLICompatibility.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void extractReadFromStdin() throws IOException { Path path = Paths.get("extract"); Path jarPath = path.resolve("extractReadFromStdin.jar"); // for extracting createJar(jarPath, RES1); for (String opts : new String[]{"x" ,"-x", "--extract"}) { if (legacyOnly && opts.startsWith("--")) continue; jarWithStdinAndWorkingDir(jarPath.toFile(), path.toFile(), opts) .assertSuccess() .resultChecker(r -> assertTrue(Files.exists(path.resolve(RES1)), "Expected to find:" + path.resolve(RES1)) ); FileUtils.deleteFileIfExistsWithRetry(path.resolve(RES1)); } FileUtils.deleteFileTreeWithRetry(path); }
Example 6
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test // META-INF/versions/9 contains an extra public class public void test05() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); // add the new v9 class Path source = Paths.get(src, "data", "test05", "v9", "version"); javac(classes.resolve("v9"), source.resolve("Extra.java")); jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".", "--release", "9", "-C", classes.resolve("v9").toString(), ".") .shouldNotHaveExitValue(SUCCESS) .shouldContain("contains a new public class"); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 7
Source File: FileHandlerMaxLocksTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String maxLocksSet = System.getProperty(MX_LCK_SYS_PROPERTY); File loggerDir = createLoggerDir(); List<FileHandler> fileHandlers = new ArrayList<>(); try { // 200 raises the default limit of 100, we try 102 times for (int i = 0; i < 102; i++) { fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log")); } } catch (IOException ie) { if (maxLocksSet.equals("200ab") && ie.getMessage().contains("get lock for")) { // Ignore: Expected exception while passing bad value- 200ab } else { throw new RuntimeException("Test Failed: " + ie.getMessage()); } } finally { for (FileHandler fh : fileHandlers) { fh.close(); } FileUtils.deleteFileTreeWithRetry(Paths.get(loggerDir.getPath())); } }
Example 8
Source File: FileHandlerMaxLocksTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String maxLocksSet = System.getProperty(MX_LCK_SYS_PROPERTY); File loggerDir = createLoggerDir(); List<FileHandler> fileHandlers = new ArrayList<>(); try { // 200 raises the default limit of 100, we try 102 times for (int i = 0; i < 102; i++) { fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log")); } } catch (IOException ie) { if (maxLocksSet.equals("200ab") && ie.getMessage().contains("get lock for")) { // Ignore: Expected exception while passing bad value- 200ab } else { throw new RuntimeException("Test Failed: " + ie.getMessage()); } } finally { for (FileHandler fh : fileHandlers) { fh.close(); } FileUtils.deleteFileTreeWithRetry(Paths.get(loggerDir.getPath())); } }
Example 9
Source File: FileHandlerMaxLocksTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String maxLocksSet = System.getProperty(MX_LCK_SYS_PROPERTY); File loggerDir = createLoggerDir(); List<FileHandler> fileHandlers = new ArrayList<>(); try { // 200 raises the default limit of 100, we try 102 times for (int i = 0; i < 102; i++) { fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log")); } } catch (IOException ie) { if (maxLocksSet.equals("200ab") && ie.getMessage().contains("get lock for")) { // Ignore: Expected exception while passing bad value- 200ab } else { throw new RuntimeException("Test Failed: " + ie.getMessage()); } } finally { for (FileHandler fh : fileHandlers) { fh.close(); } FileUtils.deleteFileTreeWithRetry(Paths.get(loggerDir.getPath())); } }
Example 10
Source File: JmodNegativeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "partOfPathDoesNotExist") public Object[][] partOfPathDoesNotExist() throws IOException { Path jmod = MODS_DIR.resolve("output.jmod"); FileUtils.deleteFileIfExistsWithRetry(jmod); FileUtils.deleteFileIfExistsWithRetry(Paths.get("doesNotExist")); Path emptyDir = Paths.get("empty"); if (Files.exists(emptyDir)) FileUtils.deleteFileTreeWithRetry(emptyDir); Files.createDirectory(emptyDir); List<Supplier<JmodResult>> tasks = Arrays.asList( () -> jmod("create", "--hash-modules", "anyPattern", "--module-path","empty" + pathSeparator + "doesNotExist", "output.jmod"), () -> jmod("create", "--class-path", "empty" + pathSeparator + "doesNotExist", "output.jmod"), () -> jmod("create", "--class-path", "empty" + pathSeparator + "doesNotExist.jar", "output.jmod"), () -> jmod("create", "--cmds", "empty" + pathSeparator + "doesNotExist", "output.jmod"), () -> jmod("create", "--config", "empty" + pathSeparator + "doesNotExist", "output.jmod"), () -> jmod("create", "--libs", "empty" + pathSeparator + "doesNotExist", "output.jmod") ); String errMsg = "Error: path not found: doesNotExist"; return tasks.stream().map(t -> new Object[] {t, errMsg} ) .toArray(Object[][]::new); }
Example 11
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static void viaProviderWithTemplate(String protocol, Consumer<Result> resultChecker, Path template, String... sysProps) throws Exception { System.out.println("\nTesting " + protocol); Path testRoot = Paths.get("URLStreamHandlerProvider-" + protocol); if (Files.exists(testRoot)) FileUtils.deleteFileTreeWithRetry(testRoot); Files.createDirectory(testRoot); Path srcPath = Files.createDirectory(testRoot.resolve("src")); Path srcClass = createProvider(protocol, template, srcPath); Path build = Files.createDirectory(testRoot.resolve("build")); javac(build, srcClass); createServices(build, protocol); Path testJar = testRoot.resolve("test.jar"); jar(testJar, build); List<String> props = new ArrayList<>(); for (String p : sysProps) props.add(p); Result r = java(props, asList(testJar, TEST_CLASSES), "Child", protocol); resultChecker.accept(r); }
Example 12
Source File: JmodNegativeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@BeforeTest public void buildExplodedModules() throws IOException { if (Files.exists(EXPLODED_DIR)) FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR); for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) { Path dir = EXPLODED_DIR.resolve(name); assertTrue(compileModule(name, dir.resolve("classes"))); } if (Files.exists(MODS_DIR)) FileUtils.deleteFileTreeWithRetry(MODS_DIR); Files.createDirectories(MODS_DIR); }
Example 13
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test // update a regular jar to a multi-release jar public void test02() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".") .shouldHaveExitValue(SUCCESS); checkMultiRelease(jarfile, false); jar("uf", jarfile, "--release", "9", "-C", classes.resolve("v9").toString(), ".") .shouldHaveExitValue(SUCCESS); checkMultiRelease(jarfile, true); Map<String, String[]> names = Map.of( "version/Main.class", new String[]{"base", "version", "Main.class"}, "version/Version.class", new String[]{"base", "version", "Version.class"}, "META-INF/versions/9/version/Version.class", new String[]{"v9", "version", "Version.class"} ); compare(jarfile, names); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 14
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test // a base entry contains a nested class that doesn't have a matching top level class public void test11() throws Throwable { String jarfile = "test.jar"; compile("test01"); //use same data as test01 Path classes = Paths.get("classes"); // add a base class with a nested class Path source = Paths.get(src, "data", "test10", "base", "version"); javac(classes.resolve("base"), source.resolve("Nested.java")); // remove the top level class, thus isolating the nested class Files.delete(classes.resolve("base").resolve("version").resolve("Nested.class")); // add a versioned class with a nested class source = Paths.get(src, "data", "test10", "v9", "version"); javac(classes.resolve("v9"), source.resolve("Nested.java")); List<String> output = jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".", "--release", "9", "-C", classes.resolve("v9").toString(), ".") .shouldNotHaveExitValue(SUCCESS) .asLines(); assertTrue(output.size() == 4); assertTrue(output.get(0).contains("an isolated nested class"), output.get(0)); assertTrue(output.get(1).contains("contains a new public class"), output.get(1)); assertTrue(output.get(2).contains("an isolated nested class"), output.get(2)); assertTrue(output.get(3).contains("invalid multi-release jar file"), output.get(3)); FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 15
Source File: Common.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
static void rm_minus_rf (File path) throws IOException, InterruptedException { if (!path.exists()) return; FileUtils.deleteFileTreeWithRetry(path.toPath()); }
Example 16
Source File: Common.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
static void rm_minus_rf (File path) throws IOException, InterruptedException { if (!path.exists()) return; FileUtils.deleteFileTreeWithRetry(path.toPath()); }
Example 17
Source File: Common.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static void rm_minus_rf (File path) throws IOException, InterruptedException { if (!path.exists()) return; FileUtils.deleteFileTreeWithRetry(path.toPath()); }
Example 18
Source File: Basic.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void testCustomManifest() throws Throwable { String jarfile = "test.jar"; compile("test01"); Path classes = Paths.get("classes"); Path manifest = Paths.get("Manifest.txt"); // create Files.write(manifest, "Class-Path: MyUtils.jar\n".getBytes()); jar("cfm", jarfile, manifest.toString(), "-C", classes.resolve("base").toString(), ".", "--release", "10", "-C", classes.resolve("v10").toString(), ".") .shouldHaveExitValue(SUCCESS) .shouldBeEmpty(); try (JarFile jf = new JarFile(new File(jarfile), true, ZipFile.OPEN_READ, JarFile.runtimeVersion())) { assertTrue(jf.isMultiRelease(), "Not multi-release jar"); assertEquals(jf.getManifest() .getMainAttributes() .getValue("Class-Path"), "MyUtils.jar"); } // update Files.write(manifest, "Multi-release: false\n".getBytes()); jar("ufm", jarfile, manifest.toString(), "-C", classes.resolve("base").toString(), ".", "--release", "9", "-C", classes.resolve("v10").toString(), ".") .shouldHaveExitValue(SUCCESS) .shouldContain("WARNING: Duplicate name in Manifest: Multi-release."); try (JarFile jf = new JarFile(new File(jarfile), true, ZipFile.OPEN_READ, JarFile.runtimeVersion())) { assertTrue(jf.isMultiRelease(), "Not multi-release jar"); assertEquals(jf.getManifest() .getMainAttributes() .getValue("Class-Path"), "MyUtils.jar"); } FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile)); FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes")); }
Example 19
Source File: JmodTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void testLastOneWins() throws IOException { Path workDir = Paths.get("lastOneWins"); if (Files.exists(workDir)) FileUtils.deleteFileTreeWithRetry(workDir); Files.createDirectory(workDir); Path jmod = MODS_DIR.resolve("lastOneWins.jmod"); FileUtils.deleteFileIfExistsWithRetry(jmod); Path cp = EXPLODED_DIR.resolve("foo").resolve("classes"); Path bp = EXPLODED_DIR.resolve("foo").resolve("bin"); Path lp = EXPLODED_DIR.resolve("foo").resolve("lib"); Path cf = EXPLODED_DIR.resolve("foo").resolve("conf"); Path shouldNotBeAdded = workDir.resolve("shouldNotBeAdded"); Files.createDirectory(shouldNotBeAdded); Files.write(shouldNotBeAdded.resolve("aFile"), "hello".getBytes(UTF_8)); // Pairs of options. For options with required arguments the last one // should win ( first should be effectively ignored, but may still be // validated ). jmod("create", "--conf", shouldNotBeAdded.toString(), "--conf", cf.toString(), "--cmds", shouldNotBeAdded.toString(), "--cmds", bp.toString(), "--libs", shouldNotBeAdded.toString(), "--libs", lp.toString(), "--class-path", shouldNotBeAdded.toString(), "--class-path", cp.toString(), "--main-class", "does.NotExist", "--main-class", "jdk.test.foo.Foo", "--module-version", "00001", "--module-version", "5.4.3", "--do-not-resolve-by-default", "--do-not-resolve-by-default", "--warn-if-resolved=incubating", "--warn-if-resolved=deprecated", MODS_DIR.resolve("lastOneWins.jmod").toString()) .assertSuccess() .resultChecker(r -> { ModuleDescriptor md = getModuleDescriptor(jmod); Optional<String> omc = md.mainClass(); assertTrue(omc.isPresent()); assertEquals(omc.get(), "jdk.test.foo.Foo"); Optional<Version> ov = md.version(); assertTrue(ov.isPresent()); assertEquals(ov.get().toString(), "5.4.3"); try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p); Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p); Stream<String> s3 = findFiles(bp).map(p -> CMDS_PREFIX + p); Stream<String> s4 = findFiles(cf).map(p -> CONFIGS_PREFIX + p)) { Set<String> expectedFilenames = Stream.concat(Stream.concat(s1,s2), Stream.concat(s3, s4)) .collect(toSet()); assertJmodContent(jmod, expectedFilenames); } }); jmod("extract", "--dir", "blah", "--dir", "lastOneWinsExtractDir", jmod.toString()) .assertSuccess() .resultChecker(r -> { assertTrue(Files.exists(Paths.get("lastOneWinsExtractDir"))); assertTrue(Files.notExists(Paths.get("blah"))); }); }
Example 20
Source File: Common.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
static void rm_minus_rf (File path) throws IOException, InterruptedException { if (!path.exists()) return; FileUtils.deleteFileTreeWithRetry(path.toPath()); }