Skip to content
Permalink
Browse files
8265078: jpackage tests on Windows leave large temp files
Reviewed-by: asemenyuk, kcr
  • Loading branch information
Andy Herrick committed Apr 14, 2021
1 parent 05f851e commit e167577888b8203001b1fc516ed382bc2a96c7b9
@@ -44,6 +44,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -56,6 +57,8 @@
public class IOUtils {

public static void deleteRecursive(Path directory) throws IOException {
final AtomicReference<IOException> exception = new AtomicReference<>();

if (!Files.exists(directory)) {
return;
}
@@ -67,7 +70,11 @@ public FileVisitResult visitFile(Path file,
if (Platform.getPlatform() == Platform.WINDOWS) {
Files.setAttribute(file, "dos:readonly", false);
}
Files.delete(file);
try {
Files.delete(file);
} catch (IOException ex) {
exception.compareAndSet(null, ex);
}
return FileVisitResult.CONTINUE;
}

@@ -83,10 +90,17 @@ public FileVisitResult preVisitDirectory(Path dir,
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
Files.delete(dir);
try {
Files.delete(dir);
} catch (IOException ex) {
exception.compareAndSet(null, ex);
}
return FileVisitResult.CONTINUE;
}
});
if (exception.get() != null) {
throw exception.get();
}
}

public static void copyRecursive(Path src, Path dest) throws IOException {
@@ -89,6 +89,13 @@ public Executor setRemovePath(boolean value) {
return this;
}

public Executor setWindowsTmpDir(String tmp) {
TKit.assertTrue(TKit.isWindows(),
"setWindowsTmpDir is only valid on Windows platform");
winTmpDir = tmp;
return this;
}

/**
* Configures this instance to save full output that command will produce.
* This function is mutual exclusive with
@@ -279,6 +286,9 @@ private Result runExecutable() throws IOException, InterruptedException {
command.add(executablePath().toString());
command.addAll(args);
ProcessBuilder builder = new ProcessBuilder(command);
if (winTmpDir != null) {
builder.environment().put("TMP", winTmpDir);
}
StringBuilder sb = new StringBuilder(getPrintableCommandLine());
if (withSavedOutput()) {
builder.redirectErrorStream(true);
@@ -426,6 +436,7 @@ private static void trace(String msg) {
private Set<SaveOutputType> saveOutputType;
private Path directory;
private boolean removePath;
private String winTmpDir = null;

private static enum SaveOutputType {
NONE, FULL, FIRST_LINE, DUMP
@@ -643,6 +643,9 @@ private Executor createExecutor() {
exec.setToolProvider(JavaTool.JPACKAGE);
} else {
exec.setExecutable(JavaTool.JPACKAGE);
if (TKit.isWindows()) {
exec.setWindowsTmpDir(System.getProperty("java.io.tmpdir"));
}
}

return exec;

1 comment on commit e167577

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on e167577 Apr 14, 2021

Please sign in to comment.