mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8144009: ToolBox should have a cleanDirectory method
Added cleanDirectory method to ToolBox. Reviewed-by: jjg
This commit is contained in:
parent
68126c8ee9
commit
ea92f6bf06
14 changed files with 36 additions and 71 deletions
|
@ -273,6 +273,34 @@ public class ToolBox {
|
||||||
Files.delete(Paths.get(file));
|
Files.delete(Paths.get(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all content of a directory (but not the directory itself).
|
||||||
|
* @param root the directory to be cleaned
|
||||||
|
*/
|
||||||
|
public void cleanDirectory(Path root) throws IOException {
|
||||||
|
if (!Files.isDirectory(root)) {
|
||||||
|
throw new IOException(root + " is not a directory");
|
||||||
|
}
|
||||||
|
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes a) throws IOException {
|
||||||
|
Files.delete(file);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
|
||||||
|
if (e != null) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
if (!dir.equals(root)) {
|
||||||
|
Files.delete(dir);
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves a file.
|
* Moves a file.
|
||||||
* If the given destination exists and is a directory, the file will be moved
|
* If the given destination exists and is a directory, the file will be moved
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
* @run main Wrapper CompileCircularSources
|
* @run main Wrapper CompileCircularSources
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
|
|
||||||
|
@ -46,13 +47,11 @@ public class CompileCircularSources extends SJavacTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
clean(GENSRC, BIN);
|
Files.createDirectories(GENSRC);
|
||||||
|
|
||||||
Map<String,Long> previous_bin_state = collectState(BIN);
|
Map<String,Long> previous_bin_state = collectState(BIN);
|
||||||
|
|
||||||
ToolBox tb = new ToolBox();
|
|
||||||
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
||||||
"package alfa.omega; public class A { beta.B b; }");
|
"package alfa.omega; public class A { beta.B b; }");
|
||||||
tb.writeFile(GENSRC.resolve("beta/B.java"),
|
tb.writeFile(GENSRC.resolve("beta/B.java"),
|
||||||
|
@ -74,6 +73,5 @@ public class CompileCircularSources extends SJavacTester {
|
||||||
BIN + "/beta/B.class",
|
BIN + "/beta/B.class",
|
||||||
BIN + "/gamma/C.class",
|
BIN + "/gamma/C.class",
|
||||||
BIN + "/javac_state");
|
BIN + "/javac_state");
|
||||||
clean(GENSRC, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,7 @@ public class CompileExcludingDependency extends SJavacTester {
|
||||||
|
|
||||||
// Verify that excluding classes from compilation but not from linking works
|
// Verify that excluding classes from compilation but not from linking works
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
clean(GENSRC,BIN);
|
|
||||||
Map<String,Long> previous_bin_state = collectState(BIN);
|
Map<String,Long> previous_bin_state = collectState(BIN);
|
||||||
ToolBox tb = new ToolBox();
|
ToolBox tb = new ToolBox();
|
||||||
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
||||||
|
@ -69,6 +67,5 @@ public class CompileExcludingDependency extends SJavacTester {
|
||||||
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
|
||||||
BIN + "/alfa/omega/A.class",
|
BIN + "/alfa/omega/A.class",
|
||||||
BIN + "/javac_state");
|
BIN + "/javac_state");
|
||||||
clean(GENSRC, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,6 @@ public class CompileWithAtFile extends SJavacTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
ToolBox tb = new ToolBox();
|
|
||||||
tb.writeFile(GENSRC.resolve("list.txt"),
|
tb.writeFile(GENSRC.resolve("list.txt"),
|
||||||
"-if */alfa/omega/A.java\n" +
|
"-if */alfa/omega/A.java\n" +
|
||||||
"-if */beta/B.java\n" +
|
"-if */beta/B.java\n" +
|
||||||
|
@ -71,6 +69,5 @@ public class CompileWithAtFile extends SJavacTester {
|
||||||
BIN + "/javac_state",
|
BIN + "/javac_state",
|
||||||
BIN + "/alfa/omega/A.class",
|
BIN + "/alfa/omega/A.class",
|
||||||
BIN + "/beta/B.class");
|
BIN + "/beta/B.class");
|
||||||
clean(GENSRC, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
|
||||||
// gensrc2 contains broken code in beta.B, thus exclude that package
|
// gensrc2 contains broken code in beta.B, thus exclude that package
|
||||||
// gensrc3 contains a proper beta.B
|
// gensrc3 contains a proper beta.B
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
clean(GENSRC, GENSRC2, GENSRC3, BIN);
|
|
||||||
|
|
||||||
Map<String,Long> previous_bin_state = collectState(BIN);
|
Map<String,Long> previous_bin_state = collectState(BIN);
|
||||||
|
|
||||||
|
@ -82,7 +80,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
|
||||||
BIN + "/javac_state");
|
BIN + "/javac_state");
|
||||||
|
|
||||||
System.out.println("----- Compile with exluded beta went well!");
|
System.out.println("----- Compile with exluded beta went well!");
|
||||||
clean(BIN);
|
tb.cleanDirectory(BIN);
|
||||||
compileExpectFailure(GENSRC.toString(),
|
compileExpectFailure(GENSRC.toString(),
|
||||||
"-sourcepath", GENSRC2.toString(),
|
"-sourcepath", GENSRC2.toString(),
|
||||||
"-sourcepath", GENSRC3.toString(),
|
"-sourcepath", GENSRC3.toString(),
|
||||||
|
@ -93,6 +91,5 @@ public class CompileWithInvisibleSources extends SJavacTester {
|
||||||
SERVER_ARG);
|
SERVER_ARG);
|
||||||
|
|
||||||
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
|
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
|
||||||
clean(GENSRC, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,7 @@ public class CompileWithOverrideSources extends SJavacTester {
|
||||||
// Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,
|
// Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,
|
||||||
// only compile ok beta.B in gensrc2
|
// only compile ok beta.B in gensrc2
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
clean(GENSRC, GENSRC2, GENSRC3, BIN);
|
|
||||||
|
|
||||||
Map<String,Long> previous_bin_state = collectState(BIN);
|
Map<String,Long> previous_bin_state = collectState(BIN);
|
||||||
ToolBox tb = new ToolBox();
|
ToolBox tb = new ToolBox();
|
||||||
|
@ -80,7 +78,7 @@ public class CompileWithOverrideSources extends SJavacTester {
|
||||||
BIN + "/javac_state");
|
BIN + "/javac_state");
|
||||||
|
|
||||||
System.out.println("----- Compile with exluded beta went well!");
|
System.out.println("----- Compile with exluded beta went well!");
|
||||||
clean(BIN);
|
tb.cleanDirectory(BIN);
|
||||||
compileExpectFailure(GENSRC.toString(),
|
compileExpectFailure(GENSRC.toString(),
|
||||||
GENSRC2.toString(),
|
GENSRC2.toString(),
|
||||||
"-d", BIN.toString(),
|
"-d", BIN.toString(),
|
||||||
|
@ -90,6 +88,5 @@ public class CompileWithOverrideSources extends SJavacTester {
|
||||||
SERVER_ARG);
|
SERVER_ARG);
|
||||||
|
|
||||||
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
|
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
|
||||||
clean(GENSRC, GENSRC2, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class IncCompileChangeNative extends SJavacTester {
|
||||||
ToolBox tb = new ToolBox();
|
ToolBox tb = new ToolBox();
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(GENSRC);
|
Files.createDirectories(GENSRC);
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
Files.createDirectories(HEADERS);
|
Files.createDirectories(HEADERS);
|
||||||
|
@ -59,8 +58,6 @@ public class IncCompileChangeNative extends SJavacTester {
|
||||||
initialCompile();
|
initialCompile();
|
||||||
incrementalCompileDropAllNatives();
|
incrementalCompileDropAllNatives();
|
||||||
incrementalCompileAddNative();
|
incrementalCompileAddNative();
|
||||||
|
|
||||||
clean(GENSRC, BIN, HEADERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update B.java with one less native method i.e. it has no longer any methods
|
// Update B.java with one less native method i.e. it has no longer any methods
|
||||||
|
|
|
@ -51,15 +51,12 @@ public class IncCompileDropClasses extends SJavacTester {
|
||||||
ToolBox tb = new ToolBox();
|
ToolBox tb = new ToolBox();
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(GENSRC);
|
Files.createDirectories(GENSRC);
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
Files.createDirectories(HEADERS);
|
Files.createDirectories(HEADERS);
|
||||||
|
|
||||||
initialCompile();
|
initialCompile();
|
||||||
incrementalCompileDroppingClasses();
|
incrementalCompileDroppingClasses();
|
||||||
|
|
||||||
clean(GENSRC, BIN, HEADERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing that deleting AA.java deletes all generated inner class including AA.class
|
// Testing that deleting AA.java deletes all generated inner class including AA.class
|
||||||
|
|
|
@ -50,15 +50,12 @@ public class IncCompileNoChanges extends SJavacTester {
|
||||||
Map<String,Long> previous_headers_state;
|
Map<String,Long> previous_headers_state;
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(Paths.get(getClass().getSimpleName()));
|
|
||||||
Files.createDirectories(GENSRC);
|
Files.createDirectories(GENSRC);
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
Files.createDirectories(HEADERS);
|
Files.createDirectories(HEADERS);
|
||||||
|
|
||||||
initialCompile();
|
initialCompile();
|
||||||
incrementalCompileNoChanges();
|
incrementalCompileNoChanges();
|
||||||
|
|
||||||
clean(GENSRC, BIN, HEADERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing that no change in sources implies no change in binaries
|
// Testing that no change in sources implies no change in binaries
|
||||||
|
|
|
@ -51,15 +51,12 @@ public class IncCompileUpdateNative extends SJavacTester {
|
||||||
ToolBox tb = new ToolBox();
|
ToolBox tb = new ToolBox();
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(GENSRC);
|
Files.createDirectories(GENSRC);
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
Files.createDirectories(HEADERS);
|
Files.createDirectories(HEADERS);
|
||||||
|
|
||||||
initialCompile();
|
initialCompile();
|
||||||
incrementalCompileChangeNative();
|
incrementalCompileChangeNative();
|
||||||
|
|
||||||
clean(GENSRC, BIN, HEADERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update B.java with a new value for the final static annotated with @Native
|
// Update B.java with a new value for the final static annotated with @Native
|
||||||
|
|
|
@ -46,8 +46,6 @@ public class NoState extends SJavacTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
ToolBox tb = new ToolBox();
|
|
||||||
tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
|
tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
|
||||||
Files.createDirectory(BIN);
|
Files.createDirectory(BIN);
|
||||||
compile("-d", BIN.toString(),
|
compile("-d", BIN.toString(),
|
||||||
|
|
|
@ -47,9 +47,7 @@ public class PermittedArtifact extends SJavacTester {
|
||||||
|
|
||||||
//Verify that --permit-artifact=bin works
|
//Verify that --permit-artifact=bin works
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
clean(GENSRC, BIN);
|
|
||||||
|
|
||||||
Map<String,Long> previous_bin_state = collectState(BIN);
|
Map<String,Long> previous_bin_state = collectState(BIN);
|
||||||
|
|
||||||
|
@ -73,6 +71,5 @@ public class PermittedArtifact extends SJavacTester {
|
||||||
BIN + "/alfa/omega/A.class",
|
BIN + "/alfa/omega/A.class",
|
||||||
BIN + "/alfa/omega/AA.class",
|
BIN + "/alfa/omega/AA.class",
|
||||||
BIN + "/javac_state");
|
BIN + "/javac_state");
|
||||||
clean(GENSRC, BIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class SJavacTester {
|
||||||
+ "portfile=testportfile,"
|
+ "portfile=testportfile,"
|
||||||
+ "background=false";
|
+ "background=false";
|
||||||
|
|
||||||
|
final ToolBox tb = new ToolBox();
|
||||||
final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
|
final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
|
||||||
|
|
||||||
// Generated sources that will test aspects of sjavac
|
// Generated sources that will test aspects of sjavac
|
||||||
|
@ -53,7 +54,6 @@ public class SJavacTester {
|
||||||
|
|
||||||
void initialCompile() throws Exception {
|
void initialCompile() throws Exception {
|
||||||
System.out.println("\nInitial compile of gensrc.");
|
System.out.println("\nInitial compile of gensrc.");
|
||||||
ToolBox tb = new ToolBox();
|
|
||||||
tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
|
tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
|
||||||
"package alfa.omega; public interface AINT { void aint(); }");
|
"package alfa.omega; public interface AINT { void aint(); }");
|
||||||
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
|
||||||
|
@ -101,30 +101,6 @@ public class SJavacTester {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete(final Path root) throws IOException {
|
|
||||||
if (!Files.exists(root)) return;
|
|
||||||
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
|
|
||||||
@Override
|
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
|
||||||
{
|
|
||||||
Files.delete(file);
|
|
||||||
return FileVisitResult.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException
|
|
||||||
{
|
|
||||||
if (e == null) {
|
|
||||||
if (!dir.equals(root)) Files.delete(dir);
|
|
||||||
return FileVisitResult.CONTINUE;
|
|
||||||
} else {
|
|
||||||
// directory iteration failed
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void compile(String... args) throws Exception {
|
void compile(String... args) throws Exception {
|
||||||
int rc = Main.go(args);
|
int rc = Main.go(args);
|
||||||
if (rc != 0) throw new Exception("Error during compile!");
|
if (rc != 0) throw new Exception("Error during compile!");
|
||||||
|
@ -265,10 +241,4 @@ public class SJavacTester {
|
||||||
throw new Exception("The dir should not differ! But it does!");
|
throw new Exception("The dir should not differ! But it does!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clean(Path... listOfDirs) throws Exception {
|
|
||||||
for (Path dir : listOfDirs) {
|
|
||||||
delete(dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class StateDir extends SJavacTester {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
||||||
clean(TEST_ROOT);
|
|
||||||
Path BAR = TEST_ROOT.resolve("bar");
|
Path BAR = TEST_ROOT.resolve("bar");
|
||||||
Files.createDirectories(BAR);
|
Files.createDirectories(BAR);
|
||||||
Files.createDirectories(BIN);
|
Files.createDirectories(BIN);
|
||||||
|
@ -69,6 +68,5 @@ public class StateDir extends SJavacTester {
|
||||||
Map<String,Long> new_bar_state = collectState(BAR);
|
Map<String,Long> new_bar_state = collectState(BAR);
|
||||||
verifyThatFilesHaveBeenAdded(previous_bar_state, new_bar_state,
|
verifyThatFilesHaveBeenAdded(previous_bar_state, new_bar_state,
|
||||||
BAR + "/javac_state");
|
BAR + "/javac_state");
|
||||||
clean(GENSRC, BIN, BAR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue