changeset 3144:130ae42e6da7

8144009: ToolBox should have a cleanDirectory method Summary: Added cleanDirectory method to ToolBox. Reviewed-by: jjg
author alundblad
date Thu, 26 Nov 2015 09:33:41 +0100
parents 73adc11fd50f
children ab5e0a945e78
files test/tools/lib/ToolBox.java test/tools/sjavac/CompileCircularSources.java test/tools/sjavac/CompileExcludingDependency.java test/tools/sjavac/CompileWithAtFile.java test/tools/sjavac/CompileWithInvisibleSources.java test/tools/sjavac/CompileWithOverrideSources.java test/tools/sjavac/IncCompileChangeNative.java test/tools/sjavac/IncCompileDropClasses.java test/tools/sjavac/IncCompileNoChanges.java test/tools/sjavac/IncCompileUpdateNative.java test/tools/sjavac/NoState.java test/tools/sjavac/PermittedArtifact.java test/tools/sjavac/SJavacTester.java test/tools/sjavac/StateDir.java
diffstat 14 files changed, 36 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/lib/ToolBox.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/lib/ToolBox.java	Thu Nov 26 09:33:41 2015 +0100
@@ -274,6 +274,34 @@
     }
 
     /**
+     * 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.
      * If the given destination exists and is a directory, the file will be moved
      * to that directory.  Otherwise, the file will be moved to the destination,
--- a/test/tools/sjavac/CompileCircularSources.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/CompileCircularSources.java	Thu Nov 26 09:33:41 2015 +0100
@@ -36,6 +36,7 @@
  * @run main Wrapper CompileCircularSources
  */
 
+import java.io.IOException;
 import java.util.*;
 import java.nio.file.*;
 
@@ -46,13 +47,11 @@
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, BIN);
+        Files.createDirectories(GENSRC);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
                      "package alfa.omega; public class A { beta.B b; }");
         tb.writeFile(GENSRC.resolve("beta/B.java"),
@@ -74,6 +73,5 @@
                                      BIN + "/beta/B.class",
                                      BIN + "/gamma/C.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
--- a/test/tools/sjavac/CompileExcludingDependency.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/CompileExcludingDependency.java	Thu Nov 26 09:33:41 2015 +0100
@@ -47,9 +47,7 @@
 
     // Verify that excluding classes from compilation but not from linking works
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC,BIN);
         Map<String,Long> previous_bin_state = collectState(BIN);
         ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
@@ -69,6 +67,5 @@
         verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
                                      BIN + "/alfa/omega/A.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
--- a/test/tools/sjavac/CompileWithAtFile.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/CompileWithAtFile.java	Thu Nov 26 09:33:41 2015 +0100
@@ -46,8 +46,6 @@
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("list.txt"),
                      "-if */alfa/omega/A.java\n" +
                      "-if */beta/B.java\n" +
@@ -55,11 +53,11 @@
                      "-d " + BIN + "\n" +
                      "--state-dir=" + BIN + "\n");
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
-                 "package alfa.omega; import beta.B; public class A { B b; }");
+                     "package alfa.omega; import beta.B; public class A { B b; }");
         tb.writeFile(GENSRC.resolve("beta/B.java"),
-                 "package beta; public class B { }");
+                     "package beta; public class B { }");
         tb.writeFile(GENSRC.resolve("beta/C.java"),
-                 "broken");
+                     "broken");
 
         Files.createDirectory(BIN);
         Map<String,Long> previous_bin_state = collectState(BIN);
@@ -71,6 +69,5 @@
                          BIN + "/javac_state",
                          BIN + "/alfa/omega/A.class",
                          BIN + "/beta/B.class");
-        clean(GENSRC, BIN);
     }
 }
--- a/test/tools/sjavac/CompileWithInvisibleSources.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/CompileWithInvisibleSources.java	Thu Nov 26 09:33:41 2015 +0100
@@ -49,9 +49,7 @@
     // gensrc2 contains broken code in beta.B, thus exclude that package
     // gensrc3 contains a proper beta.B
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, GENSRC2, GENSRC3, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
@@ -82,7 +80,7 @@
                                      BIN + "/javac_state");
 
         System.out.println("----- Compile with exluded beta went well!");
-        clean(BIN);
+        tb.cleanDirectory(BIN);
         compileExpectFailure(GENSRC.toString(),
                              "-sourcepath", GENSRC2.toString(),
                              "-sourcepath", GENSRC3.toString(),
@@ -93,6 +91,5 @@
                              SERVER_ARG);
 
         System.out.println("----- Compile without exluded beta failed, as expected! Good!");
-        clean(GENSRC, BIN);
     }
 }
--- a/test/tools/sjavac/CompileWithOverrideSources.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/CompileWithOverrideSources.java	Thu Nov 26 09:33:41 2015 +0100
@@ -48,9 +48,7 @@
     // Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,
     // only compile ok beta.B in gensrc2
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, GENSRC2, GENSRC3, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
         ToolBox tb = new ToolBox();
@@ -80,7 +78,7 @@
                                      BIN + "/javac_state");
 
         System.out.println("----- Compile with exluded beta went well!");
-        clean(BIN);
+        tb.cleanDirectory(BIN);
         compileExpectFailure(GENSRC.toString(),
                              GENSRC2.toString(),
                              "-d", BIN.toString(),
@@ -90,6 +88,5 @@
                              SERVER_ARG);
 
         System.out.println("----- Compile without exluded beta failed, as expected! Good!");
-        clean(GENSRC, GENSRC2, BIN);
     }
 }
--- a/test/tools/sjavac/IncCompileChangeNative.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/IncCompileChangeNative.java	Thu Nov 26 09:33:41 2015 +0100
@@ -51,7 +51,6 @@
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
@@ -59,8 +58,6 @@
         initialCompile();
         incrementalCompileDropAllNatives();
         incrementalCompileAddNative();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Update B.java with one less native method i.e. it has no longer any methods
--- a/test/tools/sjavac/IncCompileDropClasses.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/IncCompileDropClasses.java	Thu Nov 26 09:33:41 2015 +0100
@@ -51,15 +51,12 @@
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileDroppingClasses();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Testing that deleting AA.java deletes all generated inner class including AA.class
--- a/test/tools/sjavac/IncCompileNoChanges.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/IncCompileNoChanges.java	Thu Nov 26 09:33:41 2015 +0100
@@ -50,15 +50,12 @@
     Map<String,Long> previous_headers_state;
 
     void test() throws Exception {
-        clean(Paths.get(getClass().getSimpleName()));
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileNoChanges();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Testing that no change in sources implies no change in binaries
--- a/test/tools/sjavac/IncCompileUpdateNative.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/IncCompileUpdateNative.java	Thu Nov 26 09:33:41 2015 +0100
@@ -51,15 +51,12 @@
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileChangeNative();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Update B.java with a new value for the final static annotated with @Native
--- a/test/tools/sjavac/NoState.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/NoState.java	Thu Nov 26 09:33:41 2015 +0100
@@ -46,8 +46,6 @@
     }
 
     public void run() throws Exception {
-        clean(TEST_ROOT);
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
         Files.createDirectory(BIN);
         compile("-d", BIN.toString(),
--- a/test/tools/sjavac/PermittedArtifact.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/PermittedArtifact.java	Thu Nov 26 09:33:41 2015 +0100
@@ -47,9 +47,7 @@
 
     //Verify that --permit-artifact=bin works
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
@@ -73,6 +71,5 @@
                                      BIN + "/alfa/omega/A.class",
                                      BIN + "/alfa/omega/AA.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
--- a/test/tools/sjavac/SJavacTester.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/SJavacTester.java	Thu Nov 26 09:33:41 2015 +0100
@@ -34,6 +34,7 @@
             + "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 @@
 
     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 @@
         }
     }
 
-    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 @@
             throw new Exception("The dir should not differ! But it does!");
         }
     }
-
-    void clean(Path... listOfDirs) throws Exception {
-        for (Path dir : listOfDirs) {
-            delete(dir);
-        }
-    }
 }
--- a/test/tools/sjavac/StateDir.java	Thu Nov 26 07:44:23 2015 +0530
+++ b/test/tools/sjavac/StateDir.java	Thu Nov 26 09:33:41 2015 +0100
@@ -46,7 +46,6 @@
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Path BAR = TEST_ROOT.resolve("bar");
         Files.createDirectories(BAR);
         Files.createDirectories(BIN);
@@ -69,6 +68,5 @@
         Map<String,Long> new_bar_state = collectState(BAR);
         verifyThatFilesHaveBeenAdded(previous_bar_state, new_bar_state,
                                      BAR + "/javac_state");
-        clean(GENSRC, BIN, BAR);
     }
 }