< prev index next >
test/tools/jmod/JmodTest.java
Print this page
*** 578,631 ****
assertContains(r.output, "--warn-if-resolved");
});
}
@Test
- public void testTmpFileAlreadyExists() throws IOException {
- // Implementation detail: jmod tool creates <jmod-file>.tmp
- // Ensure that there are no problems if existing
-
- Path jmod = MODS_DIR.resolve("testTmpFileAlreadyExists.jmod");
- Path tmp = MODS_DIR.resolve("testTmpFileAlreadyExists.jmod.tmp");
- FileUtils.deleteFileIfExistsWithRetry(jmod);
- FileUtils.deleteFileIfExistsWithRetry(tmp);
- Files.createFile(tmp);
- String cp = EXPLODED_DIR.resolve("foo").resolve("classes").toString();
-
- jmod("create",
- "--class-path", cp,
- jmod.toString())
- .assertSuccess()
- .resultChecker(r ->
- assertTrue(Files.notExists(tmp), "Unexpected tmp file:" + tmp)
- );
- }
-
- @Test
public void testTmpFileRemoved() throws IOException {
// Implementation detail: jmod tool creates <jmod-file>.tmp
// Ensure that it is removed in the event of a failure.
// The failure in this case is a class in the unnamed package.
! Path jmod = MODS_DIR.resolve("testTmpFileRemoved.jmod");
! Path tmp = MODS_DIR.resolve("testTmpFileRemoved.jmod.tmp");
FileUtils.deleteFileIfExistsWithRetry(jmod);
FileUtils.deleteFileIfExistsWithRetry(tmp);
String cp = EXPLODED_DIR.resolve("foo").resolve("classes") + File.pathSeparator +
EXPLODED_DIR.resolve("foo").resolve("classes")
.resolve("jdk").resolve("test").resolve("foo").toString();
jmod("create",
"--class-path", cp,
jmod.toString())
.assertFailure()
.resultChecker(r -> {
assertContains(r.output, "unnamed package");
! assertTrue(Files.notExists(tmp), "Unexpected tmp file:" + tmp);
});
}
// ---
static boolean compileModule(String name, Path dest) throws IOException {
return CompilerUtils.compile(SRC_DIR.resolve(name), dest);
}
--- 578,631 ----
assertContains(r.output, "--warn-if-resolved");
});
}
@Test
public void testTmpFileRemoved() throws IOException {
// Implementation detail: jmod tool creates <jmod-file>.tmp
// Ensure that it is removed in the event of a failure.
// The failure in this case is a class in the unnamed package.
! String filename = "testTmpFileRemoved.jmod";
! Path jmod = MODS_DIR.resolve(filename);
!
! // clean up files
FileUtils.deleteFileIfExistsWithRetry(jmod);
+ findTmpFiles(filename).forEach(tmp -> {
+ try {
FileUtils.deleteFileIfExistsWithRetry(tmp);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ });
+
String cp = EXPLODED_DIR.resolve("foo").resolve("classes") + File.pathSeparator +
EXPLODED_DIR.resolve("foo").resolve("classes")
.resolve("jdk").resolve("test").resolve("foo").toString();
jmod("create",
"--class-path", cp,
jmod.toString())
.assertFailure()
.resultChecker(r -> {
assertContains(r.output, "unnamed package");
! Set<Path> tmpfiles = findTmpFiles(filename).collect(toSet());
! assertTrue(tmpfiles.isEmpty(), "Unexpected tmp file:" + tmpfiles);
});
}
+ private Stream<Path> findTmpFiles(String prefix) {
+ try {
+ Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir"));
+ return Files.find(tmpdir, 1, (p, attrs) ->
+ p.getFileName().toString().startsWith(prefix)
+ && p.getFileName().toString().endsWith(".tmp"));
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
// ---
static boolean compileModule(String name, Path dest) throws IOException {
return CompilerUtils.compile(SRC_DIR.resolve(name), dest);
}
< prev index next >