Java Code Examples for jdk.testlibrary.FileUtils#deleteFileIfExistsWithRetry()

The following examples show how to use jdk.testlibrary.FileUtils#deleteFileIfExistsWithRetry() . 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: JmodTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testMainClass() throws IOException {
    Path jmod = MODS_DIR.resolve("fooMainClass.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();

    jmod("create",
         "--class-path", cp,
         "--main-class", "jdk.test.foo.Foo",
         jmod.toString())
        .assertSuccess()
        .resultChecker(r -> {
            Optional<String> omc = getModuleDescriptor(jmod).mainClass();
            assertTrue(omc.isPresent());
            assertEquals(omc.get(), "jdk.test.foo.Foo");
        });
}
 
Example 2
Source File: CLICompatibility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void listReadFromStdinWriteToStdout() throws IOException {
    Path path = Paths.get("listReadFromStdinWriteToStdout.jar");
    createJar(path, RES1);

    for (String opts : new String[]{"t", "-t", "--list"} ){
        if (legacyOnly && opts.startsWith("--"))
            continue;

        jarWithStdin(path.toFile(), opts)
            .assertSuccess()
            .resultChecker(r ->
                assertTrue(r.output.contains("META-INF/MANIFEST.MF") && r.output.contains(RES1),
                           "Failed, got [" + r.output + "]")
            );
    }
    FileUtils.deleteFileIfExistsWithRetry(path);
}
 
Example 3
Source File: JmodTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testCmds() throws IOException {
    Path jmod = MODS_DIR.resolve("fooCmds.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
    Path bp = EXPLODED_DIR.resolve("foo").resolve("bin");

    jmod("create",
         "--cmds", bp.toString(),
         "--class-path", cp.toString(),
         jmod.toString())
        .assertSuccess()
        .resultChecker(r -> {
            try (Stream<String> s1 = findFiles(bp).map(p -> CMDS_PREFIX + p);
                 Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) {
                Set<String> expectedFilenames = Stream.concat(s1,s2)
                                                      .collect(toSet());
                assertJmodContent(jmod, expectedFilenames);
            }
        });
}
 
Example 4
Source File: MultiThreadedReadTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
    }
}
 
Example 5
Source File: JmodTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDuplicateEntries() throws IOException {
    Path jmod = MODS_DIR.resolve("testDuplicates.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
    Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");

    jmod("create",
         "--class-path", cp + pathSeparator + cp,
         jmod.toString())
         .assertSuccess()
         .resultChecker(r ->
             assertContains(r.output, "Warning: ignoring duplicate entry")
         );

    FileUtils.deleteFileIfExistsWithRetry(jmod);
    jmod("create",
         "--class-path", cp,
         "--libs", lp.toString() + pathSeparator + lp.toString(),
         jmod.toString())
         .assertSuccess()
         .resultChecker(r ->
             assertContains(r.output, "Warning: ignoring duplicate entry")
         );
}
 
Example 6
Source File: JmodNegativeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNoModuleHash() throws IOException {
    Path jmod = MODS_DIR.resolve("output.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path emptyDir = Paths.get("empty");
    if (Files.exists(emptyDir))
        FileUtils.deleteFileTreeWithRetry(emptyDir);
    Files.createDirectory(emptyDir);
    String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();

    jmod("create",
         "--class-path", cp,
         "--hash-modules", ".*",
         "--module-path", emptyDir.toString(),
        jmod.toString())
        .resultChecker(r ->
            assertContains(r.output, "No hashes recorded: " +
                "no module specified for hashing depends on foo")
        );
}
 
Example 7
Source File: CLICompatibility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void listReadFromFileWriteToStdout() throws IOException {
    Path path = Paths.get("listReadFromFileWriteToStdout.jar");  // for listing
    createJar(path, RES1);
    String jn = path.toString();

    for (String opts : new String[]{"tf " + jn, "-tf " + jn, "--list --file " + jn}) {
        if (legacyOnly && opts.startsWith("--"))
            continue;

        jar(opts)
            .assertSuccess()
            .resultChecker(r ->
                assertTrue(r.output.contains("META-INF/MANIFEST.MF") && r.output.contains(RES1),
                           "Failed, got [" + r.output + "]")
            );
    }
    FileUtils.deleteFileIfExistsWithRetry(path);
}
 
Example 8
Source File: CLICompatibility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void extractReadFromFile() throws IOException {
    Path path = Paths.get("extract");
    String jn = "extractReadFromFile.jar";
    Path jarPath = path.resolve(jn);
    createJar(jarPath, RES1);

    for (String opts : new String[]{"xf "+jn ,"-xf "+jn, "--extract --file "+jn}) {
        if (legacyOnly && opts.startsWith("--"))
            continue;

        jarWithStdinAndWorkingDir(null, 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 9
Source File: JmodNegativeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testFileInModulePath() throws IOException {
    Path jmod = MODS_DIR.resolve("output.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path file = MODS_DIR.resolve("testFileInModulePath.txt");
    FileUtils.deleteFileIfExistsWithRetry(file);
    Files.createFile(file);

    jmod("create",
         "--hash-modules", ".*",
         "--module-path", file.toString(),
         jmod.toString())
        .assertFailure()
        .resultChecker(r ->
            assertContains(r.output, "Error: path must be a directory")
        );
}
 
Example 10
Source File: JmodTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLibs() throws IOException {
    Path jmod = MODS_DIR.resolve("fooLibs.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
    Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");

    jmod("create",
         "--libs=", lp.toString(),
         "--class-path", cp.toString(),
         jmod.toString())
        .assertSuccess()
        .resultChecker(r -> {
            try (Stream<String> s1 = findFiles(lp).map(p -> LIBS_PREFIX + p);
                 Stream<String> s2 = findFiles(cp).map(p -> CLASSES_PREFIX + p)) {
                Set<String> expectedFilenames = Stream.concat(s1,s2)
                                                      .collect(toSet());
                assertJmodContent(jmod, expectedFilenames);
            }
        });
}
 
Example 11
Source File: MultiThreadedReadTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        long t = System.currentTimeMillis();
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
        System.out.println("Deleting zip file took:" +
                (System.currentTimeMillis() - t) + "ms");
    }
}
 
Example 12
Source File: MultiThreadedReadTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
    }
}
 
Example 13
Source File: MultiThreadedReadTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
    }
}
 
Example 14
Source File: MultiThreadedReadTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    createZipFile();
    try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
        is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
        Thread[] threadArray = new Thread[NUM_THREADS];
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i] = new MultiThreadedReadTest();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].start();
        }
        for (int i = 0; i < threadArray.length; i++) {
            threadArray[i].join();
        }
    } finally {
        FileUtils.deleteFileIfExistsWithRetry(Paths.get(ZIPFILE_NAME));
    }
}
 
Example 15
Source File: CLICompatibility.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void updateReadStdinWriteStdout() throws IOException {
    Path path = Paths.get("updateReadStdinWriteStdout.jar");

    for (String opts : new String[]{"u", "-u", "--update"}) {
        if (legacyOnly && opts.startsWith("--"))
            continue;

        createJar(path, RES1);
        jarWithStdin(path.toFile(), opts, RES2)
            .assertSuccess()
            .resultChecker(r -> {
                ASSERT_CONTAINS_RES1.accept(r.stdoutAsStream());
                ASSERT_CONTAINS_RES2.accept(r.stdoutAsStream());
                ASSERT_CONTAINS_MAINFEST.accept(r.stdoutAsStream());
            });
    }
    FileUtils.deleteFileIfExistsWithRetry(path);
}
 
Example 16
Source File: JmodNegativeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "pathIsFile")
public Object[][] pathIsFile() throws IOException {
    Path jmod = MODS_DIR.resolve("output.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path aFile = Paths.get("aFile.txt");
    if (Files.exists(aFile) && !Files.isRegularFile(aFile))
        throw new InternalError("Unexpected file:" + aFile);
    else
        Files.createFile(aFile);

    List<Supplier<JmodResult>> tasks = Arrays.asList(
            () -> jmod("create",
                       "--class-path", "aFile.txt",
                       "output.jmod"),
            () -> jmod("create",
                       "--module-path", "aFile.txt",
                       "output.jmod"),
            () -> jmod("create",
                       "--cmds", "aFile.txt",
                       "output.jmod"),
            () -> jmod("create",
                       "--config", "aFile.txt",
                       "output.jmod"),
            () -> jmod("create",
                       "--libs", "aFile.txt",
                       "output.jmod") );

    String errMsg = "Error: path must be a directory: aFile.txt";
    Object[][] a = tasks.stream().map(t -> new Object[] {t, errMsg} )
                                 .toArray(Object[][]::new);
    a[0][1] = "invalid class path entry: aFile.txt";  // class path err msg
    return a;
}
 
Example 17
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
// a versioned entry contains a nested class that doesn't have a matching top level class
public void test12() 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"));

    // add a versioned class with a nested class
    source = Paths.get(src, "data", "test10", "v9", "version");
    javac(classes.resolve("v9"), source.resolve("Nested.java"));

    // remove the top level class, thus isolating the nested class
    Files.delete(classes.resolve("v9").resolve("version").resolve("Nested.class"));

    jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
            "--release", "9", "-C", classes.resolve("v9").toString(), ".")
            .shouldNotHaveExitValue(SUCCESS)
            .shouldContain("an isolated nested class");

    FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile));
    FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes"));
}
 
Example 18
Source File: JmodTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testExcludes() throws IOException {
    Path jmod = MODS_DIR.resolve("fooLibs.jmod");
    FileUtils.deleteFileIfExistsWithRetry(jmod);
    Path cp = EXPLODED_DIR.resolve("foo").resolve("classes");
    Path lp = EXPLODED_DIR.resolve("foo").resolve("lib");

    jmod("create",
         "--libs=", lp.toString(),
         "--class-path", cp.toString(),
         "--exclude", "**internal**",
         "--exclude", "first.so",
         jmod.toString())
         .assertSuccess()
         .resultChecker(r -> {
             Set<String> expectedFilenames = new HashSet<>();
             expectedFilenames.add(CLASSES_PREFIX + "module-info.class");
             expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/Foo.class");
             expectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/resources/foo.properties");
             expectedFilenames.add(LIBS_PREFIX + "second.so");
             expectedFilenames.add(LIBS_PREFIX + "third/third.so");
             assertJmodContent(jmod, expectedFilenames);

             Set<String> unexpectedFilenames = new HashSet<>();
             unexpectedFilenames.add(CLASSES_PREFIX + "jdk/test/foo/internal/Message.class");
             unexpectedFilenames.add(LIBS_PREFIX + "first.so");
             assertJmodDoesNotContain(jmod, unexpectedFilenames);
         });
}
 
Example 19
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@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 20
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
// replace a base entry and a versioned entry
public void test03() 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(), ".",
            "--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);

    // write the v9 version/Version.class entry in base and the v10
    // version/Version.class entry in versions/9 section
    jar("uf", jarfile, "-C", classes.resolve("v9").toString(), "version",
            "--release", "9", "-C", classes.resolve("v10").toString(), ".")
            .shouldHaveExitValue(SUCCESS);

    checkMultiRelease(jarfile, true);

    names = Map.of(
            "version/Main.class",
            new String[]{"base", "version", "Main.class"},

            "version/Version.class",
            new String[]{"v9", "version", "Version.class"},

            "META-INF/versions/9/version/Version.class",
            new String[]{"v10", "version", "Version.class"}
    );

    compare(jarfile, names);

    FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile));
    FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes"));
}