8265078: jpackage tests on Windows leave large temp files
Reviewed-by: asemenyuk, kcr
This commit is contained in:
parent
05f851e45d
commit
e167577888
src/jdk.jpackage/share/classes/jdk/jpackage/internal
test/jdk/tools/jpackage/helpers/jdk/jpackage/test
@ -44,6 +44,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import javax.xml.stream.XMLOutputFactory;
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import javax.xml.stream.XMLStreamWriter;
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
@ -56,6 +57,8 @@ import javax.xml.stream.XMLStreamWriter;
|
|||||||
public class IOUtils {
|
public class IOUtils {
|
||||||
|
|
||||||
public static void deleteRecursive(Path directory) throws IOException {
|
public static void deleteRecursive(Path directory) throws IOException {
|
||||||
|
final AtomicReference<IOException> exception = new AtomicReference<>();
|
||||||
|
|
||||||
if (!Files.exists(directory)) {
|
if (!Files.exists(directory)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -67,7 +70,11 @@ public class IOUtils {
|
|||||||
if (Platform.getPlatform() == Platform.WINDOWS) {
|
if (Platform.getPlatform() == Platform.WINDOWS) {
|
||||||
Files.setAttribute(file, "dos:readonly", false);
|
Files.setAttribute(file, "dos:readonly", false);
|
||||||
}
|
}
|
||||||
Files.delete(file);
|
try {
|
||||||
|
Files.delete(file);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
exception.compareAndSet(null, ex);
|
||||||
|
}
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,10 +90,17 @@ public class IOUtils {
|
|||||||
@Override
|
@Override
|
||||||
public FileVisitResult postVisitDirectory(Path dir, IOException e)
|
public FileVisitResult postVisitDirectory(Path dir, IOException e)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Files.delete(dir);
|
try {
|
||||||
|
Files.delete(dir);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
exception.compareAndSet(null, ex);
|
||||||
|
}
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (exception.get() != null) {
|
||||||
|
throw exception.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyRecursive(Path src, Path dest) throws IOException {
|
public static void copyRecursive(Path src, Path dest) throws IOException {
|
||||||
|
@ -89,6 +89,13 @@ public final class Executor extends CommandArguments<Executor> {
|
|||||||
return this;
|
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.
|
* Configures this instance to save full output that command will produce.
|
||||||
* This function is mutual exclusive with
|
* This function is mutual exclusive with
|
||||||
@ -279,6 +286,9 @@ public final class Executor extends CommandArguments<Executor> {
|
|||||||
command.add(executablePath().toString());
|
command.add(executablePath().toString());
|
||||||
command.addAll(args);
|
command.addAll(args);
|
||||||
ProcessBuilder builder = new ProcessBuilder(command);
|
ProcessBuilder builder = new ProcessBuilder(command);
|
||||||
|
if (winTmpDir != null) {
|
||||||
|
builder.environment().put("TMP", winTmpDir);
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder(getPrintableCommandLine());
|
StringBuilder sb = new StringBuilder(getPrintableCommandLine());
|
||||||
if (withSavedOutput()) {
|
if (withSavedOutput()) {
|
||||||
builder.redirectErrorStream(true);
|
builder.redirectErrorStream(true);
|
||||||
@ -426,6 +436,7 @@ public final class Executor extends CommandArguments<Executor> {
|
|||||||
private Set<SaveOutputType> saveOutputType;
|
private Set<SaveOutputType> saveOutputType;
|
||||||
private Path directory;
|
private Path directory;
|
||||||
private boolean removePath;
|
private boolean removePath;
|
||||||
|
private String winTmpDir = null;
|
||||||
|
|
||||||
private static enum SaveOutputType {
|
private static enum SaveOutputType {
|
||||||
NONE, FULL, FIRST_LINE, DUMP
|
NONE, FULL, FIRST_LINE, DUMP
|
||||||
|
@ -643,6 +643,9 @@ public final class JPackageCommand extends CommandArguments<JPackageCommand> {
|
|||||||
exec.setToolProvider(JavaTool.JPACKAGE);
|
exec.setToolProvider(JavaTool.JPACKAGE);
|
||||||
} else {
|
} else {
|
||||||
exec.setExecutable(JavaTool.JPACKAGE);
|
exec.setExecutable(JavaTool.JPACKAGE);
|
||||||
|
if (TKit.isWindows()) {
|
||||||
|
exec.setWindowsTmpDir(System.getProperty("java.io.tmpdir"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return exec;
|
return exec;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user