mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-22 11:28:11 +00:00
8257514: Fix the issues in jdk.jpackage identified by SpotBugs
Reviewed-by: asemenyuk, almatvee, shade
This commit is contained in:
parent
bbc44f57c4
commit
e3793e5a60
@ -112,7 +112,7 @@ final class CfgFile {
|
||||
}
|
||||
|
||||
Path cfgFile = appImagelayout.appDirectory().resolve(launcherName + ".cfg");
|
||||
Files.createDirectories(cfgFile.getParent());
|
||||
Files.createDirectories(IOUtils.getParent(cfgFile));
|
||||
|
||||
boolean[] addLineBreakAtSection = new boolean[1];
|
||||
Stream<String> lines = content.stream().map(entry -> {
|
||||
|
||||
@ -111,7 +111,7 @@ public class DeployParams {
|
||||
if (forApp) {
|
||||
return;
|
||||
} else {
|
||||
throw new PackagerException(exceptionKey, s);
|
||||
throw new PackagerException(exceptionKey);
|
||||
}
|
||||
}
|
||||
if (s.length() == 0 || s.charAt(s.length() - 1) == '\\') {
|
||||
@ -208,7 +208,9 @@ public class DeployParams {
|
||||
Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
|
||||
if (appImage != null) {
|
||||
Path appImageDir = Path.of(appImage);
|
||||
if (!Files.exists(appImageDir) || appImageDir.toFile().list().length == 0) {
|
||||
if (!Files.exists(appImageDir)
|
||||
|| appImageDir.toFile().list() == null
|
||||
|| appImageDir.toFile().list().length == 0) {
|
||||
throw new PackagerException("ERR_AppImageNotExist", appImage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ public class IOUtils {
|
||||
|
||||
public static void copyFile(Path sourceFile, Path destFile)
|
||||
throws IOException {
|
||||
Files.createDirectories(destFile.getParent());
|
||||
Files.createDirectories(getParent(destFile));
|
||||
|
||||
Files.copy(sourceFile, destFile,
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
@ -140,8 +140,9 @@ public class IOUtils {
|
||||
throws IOException {
|
||||
if (IOUtils.exists(paramFile)) {
|
||||
ProcessBuilder pb =
|
||||
new ProcessBuilder(launcher, paramFile.getFileName().toString());
|
||||
pb = pb.directory(paramFile.getParent().toFile());
|
||||
new ProcessBuilder(launcher,
|
||||
getFileName(paramFile).toString());
|
||||
pb = pb.directory(getParent(paramFile).toFile());
|
||||
exec(pb);
|
||||
}
|
||||
}
|
||||
@ -254,20 +255,20 @@ public class IOUtils {
|
||||
|
||||
public static Path replaceSuffix(Path path, String suffix) {
|
||||
Path parent = path.getParent();
|
||||
String filename = path.getFileName().toString().replaceAll("\\.[^.]*$", "")
|
||||
String filename = getFileName(path).toString().replaceAll("\\.[^.]*$", "")
|
||||
+ Optional.ofNullable(suffix).orElse("");
|
||||
return parent != null ? parent.resolve(filename) : Path.of(filename);
|
||||
}
|
||||
|
||||
public static Path addSuffix(Path path, String suffix) {
|
||||
Path parent = path.getParent();
|
||||
String filename = path.getFileName().toString() + suffix;
|
||||
String filename = getFileName(path).toString() + suffix;
|
||||
return parent != null ? parent.resolve(filename) : Path.of(filename);
|
||||
}
|
||||
|
||||
public static String getSuffix(Path path) {
|
||||
String filename = replaceSuffix(path.getFileName(), null).toString();
|
||||
return path.getFileName().toString().substring(filename.length());
|
||||
String filename = replaceSuffix(getFileName(path), null).toString();
|
||||
return getFileName(path).toString().substring(filename.length());
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
@ -278,7 +279,7 @@ public class IOUtils {
|
||||
public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws
|
||||
IOException {
|
||||
XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
|
||||
Files.createDirectories(dstFile.getParent());
|
||||
Files.createDirectories(getParent(dstFile));
|
||||
try (Writer w = Files.newBufferedWriter(dstFile)) {
|
||||
// Wrap with pretty print proxy
|
||||
XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance(
|
||||
@ -298,6 +299,28 @@ public class IOUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Path getParent(Path p) {
|
||||
Path parent = p.getParent();
|
||||
if (parent == null) {
|
||||
IllegalArgumentException iae =
|
||||
new IllegalArgumentException(p.toString());
|
||||
Log.verbose(iae);
|
||||
throw iae;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
public static Path getFileName(Path p) {
|
||||
Path filename = p.getFileName();
|
||||
if (filename == null) {
|
||||
IllegalArgumentException iae =
|
||||
new IllegalArgumentException(p.toString());
|
||||
Log.verbose(iae);
|
||||
throw iae;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
private static class PrettyPrintHandler implements InvocationHandler {
|
||||
|
||||
PrettyPrintHandler(XMLStreamWriter target) {
|
||||
|
||||
@ -173,7 +173,7 @@ final class OverridableResource {
|
||||
|
||||
@Override
|
||||
public void consume(InputStream in) throws IOException {
|
||||
Files.createDirectories(dest.getParent());
|
||||
Files.createDirectories(IOUtils.getParent(dest));
|
||||
Files.copy(in, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
});
|
||||
|
||||
@ -179,7 +179,7 @@ final class PathGroup {
|
||||
handler = new TransformHandler() {
|
||||
@Override
|
||||
public void copyFile(Path src, Path dst) throws IOException {
|
||||
Files.createDirectories(dst.getParent());
|
||||
Files.createDirectories(IOUtils.getParent(dst));
|
||||
if (move) {
|
||||
Files.move(src, dst);
|
||||
} else {
|
||||
|
||||
@ -84,7 +84,7 @@ public final class ToolValidator {
|
||||
cmdline.add(toolPath.toString());
|
||||
cmdline.addAll(args);
|
||||
|
||||
String name = toolPath.getFileName().toString();
|
||||
String name = IOUtils.getFileName(toolPath).toString();
|
||||
try {
|
||||
ProcessBuilder pb = new ProcessBuilder(cmdline);
|
||||
AtomicBoolean canUseTool = new AtomicBoolean();
|
||||
|
||||
@ -170,6 +170,8 @@ class CommandLine {
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
sb.append((char) ch);
|
||||
|
||||
@ -181,7 +181,7 @@ final class ExecutableRebrander {
|
||||
private void rebrandProperties(long resourceLock, OverridableResource properties,
|
||||
Map<String, String> data, Path target) throws IOException {
|
||||
|
||||
String targetExecutableName = target.getFileName().toString();
|
||||
String targetExecutableName = IOUtils.getFileName(target).toString();
|
||||
data.put("INTERNAL_NAME", targetExecutableName);
|
||||
data.put("ORIGINAL_FILENAME", targetExecutableName);
|
||||
|
||||
|
||||
@ -426,7 +426,7 @@ public class WinMsiBundler extends AbstractBundler {
|
||||
|
||||
String licenseFile = LICENSE_FILE.fetchFrom(params);
|
||||
if (licenseFile != null) {
|
||||
String lname = Path.of(licenseFile).getFileName().toString();
|
||||
String lname = IOUtils.getFileName(Path.of(licenseFile)).toString();
|
||||
Path destFile = CONFIG_ROOT.fetchFrom(params).resolve(lname);
|
||||
data.put("JpLicenseRtf", destFile.toAbsolutePath().toString());
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public class WindowsAppImageBuilder extends AbstractAppImageBuilder {
|
||||
}
|
||||
|
||||
private void writeEntry(InputStream in, Path dstFile) throws IOException {
|
||||
Files.createDirectories(dstFile.getParent());
|
||||
Files.createDirectories(IOUtils.getParent(dstFile));
|
||||
Files.copy(in, dstFile);
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ public class WixPipeline {
|
||||
lightCmdline.addAll(lightOptions);
|
||||
wixObjs.stream().map(Path::toString).forEach(lightCmdline::add);
|
||||
|
||||
Files.createDirectories(msi.getParent());
|
||||
Files.createDirectories(IOUtils.getParent(msi));
|
||||
execute(lightCmdline);
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ public class WixPipeline {
|
||||
};
|
||||
|
||||
Path wixObj = adjustPath.apply(wixObjDir).resolve(IOUtils.replaceSuffix(
|
||||
wixSource.source.getFileName(), ".wixobj"));
|
||||
IOUtils.getFileName(wixSource.source), ".wixobj"));
|
||||
|
||||
List<String> cmdline = new ArrayList<>(List.of(
|
||||
toolset.get(WixTool.Candle).toString(),
|
||||
|
||||
@ -236,7 +236,7 @@ class WixSourcesBuilder {
|
||||
|
||||
String of(Path path) {
|
||||
if (this == Folder && KNOWN_DIRS.contains(path)) {
|
||||
return path.getFileName().toString();
|
||||
return IOUtils.getFileName(path).toString();
|
||||
}
|
||||
|
||||
String result = of(path, prefix, name());
|
||||
@ -437,7 +437,7 @@ class WixSourcesBuilder {
|
||||
}
|
||||
|
||||
String launcherBasename = IOUtils.replaceSuffix(
|
||||
launcherPath.getFileName(), "").toString();
|
||||
IOUtils.getFileName(launcherPath), "").toString();
|
||||
|
||||
Path shortcutPath = folder.getPath(this).resolve(launcherBasename);
|
||||
return addComponent(xml, shortcutPath, Component.Shortcut, unused -> {
|
||||
@ -612,7 +612,7 @@ class WixSourcesBuilder {
|
||||
xml.writeAttribute("Id", Id.Folder.of(dir.getParent()));
|
||||
xml.writeStartElement("Directory");
|
||||
xml.writeAttribute("Id", Id.Folder.of(dir));
|
||||
xml.writeAttribute("Name", dir.getFileName().toString());
|
||||
xml.writeAttribute("Name", IOUtils.getFileName(dir).toString());
|
||||
xml.writeEndElement();
|
||||
xml.writeEndElement();
|
||||
}
|
||||
@ -669,7 +669,7 @@ class WixSourcesBuilder {
|
||||
srcPathGroup.transform(dstPathGroup, new PathGroup.TransformHandler() {
|
||||
@Override
|
||||
public void copyFile(Path src, Path dst) throws IOException {
|
||||
if (src.getFileName().toString().endsWith(".ico")) {
|
||||
if (IOUtils.getFileName(src).toString().endsWith(".ico")) {
|
||||
icoFiles.add(Map.entry(src, dst));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user