< prev index next >
test/jdk/tools/jpackage/helpers/JPackageHelper.java
Print this page
@@ -20,15 +20,19 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.File;
+import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.spi.ToolProvider;
@@ -147,10 +151,51 @@
}
return command;
}
+ private static void deleteRecursive(File path) throws IOException {
+ if (!path.exists()) {
+ return;
+ }
+
+ Path directory = path.toPath();
+ Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file,
+ BasicFileAttributes attr) throws IOException {
+ if (OS.startsWith("win")) {
+ Files.setAttribute(file, "dos:readonly", false);
+ }
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir,
+ BasicFileAttributes attr) throws IOException {
+ if (OS.startsWith("win")) {
+ Files.setAttribute(dir, "dos:readonly", false);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException e)
+ throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+
+ public static void deleteOutputFolder(String output) throws IOException {
+ File outputFolder = new File(output);
+ System.out.println("AMDEBUG output: " + outputFolder.getAbsolutePath());
+ deleteRecursive(outputFolder);
+ }
+
public static String executeCLI(boolean retValZero, String... args) throws Exception {
int retVal;
File outfile = new File("output.log");
try {
String[] command = getCommand(args);
< prev index next >