8144009: ToolBox should have a cleanDirectory method

Added cleanDirectory method to ToolBox.

Reviewed-by: jjg
This commit is contained in:
Andreas Lundblad 2015-11-26 09:33:41 +01:00
parent 68126c8ee9
commit ea92f6bf06
14 changed files with 36 additions and 71 deletions

View file

@ -34,6 +34,7 @@ public class SJavacTester {
+ "portfile=testportfile,"
+ "background=false";
final ToolBox tb = new ToolBox();
final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
// Generated sources that will test aspects of sjavac
@ -53,7 +54,6 @@ public class SJavacTester {
void initialCompile() throws Exception {
System.out.println("\nInitial compile of gensrc.");
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
"package alfa.omega; public interface AINT { void aint(); }");
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 {
int rc = Main.go(args);
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!");
}
}
void clean(Path... listOfDirs) throws Exception {
for (Path dir : listOfDirs) {
delete(dir);
}
}
}