8223955: Eliminate or reduce mixing of old File API and new Path/Files APIs

Reviewed-by: herrick, asemenyuk
This commit is contained in:
Alexander Matveev 2020-07-07 16:08:29 -07:00
parent c782d0e486
commit ed05d57603
34 changed files with 537 additions and 514 deletions

View File

@ -435,8 +435,8 @@ final class DesktopIntegration {
File.separatorChar, '-') + IOUtils.getSuffix(
assoc.data.iconPath));
IOUtils.copyFile(assoc.data.iconPath.toFile(),
faIconFile.srcPath().toFile());
IOUtils.copyFile(assoc.data.iconPath,
faIconFile.srcPath());
shellCommands.addIcon(mimeType, faIconFile.installPath(),
assoc.iconSize);

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@ -39,20 +38,21 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS
public class LinuxAppImageBuilder extends AbstractAppImageBuilder {
static final BundlerParamInfo<File> ICON_PNG =
static final BundlerParamInfo<Path> ICON_PNG =
new StandardBundlerParam<>(
"icon.png",
File.class,
Path.class,
params -> {
File f = ICON.fetchFrom(params);
if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
Path f = ICON.fetchFrom(params);
if (f != null && f.getFileName() != null && !f.getFileName()
.toString().toLowerCase().endsWith(".png")) {
Log.error(MessageFormat.format(
I18N.getString("message.icon-not-png"), f));
return null;
}
return f;
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
final static String DEFAULT_ICON = "java32.png";

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
@ -178,13 +177,13 @@ public class LinuxDebBundler extends LinuxPackageBundler {
}
@Override
protected File buildPackageBundle(
protected Path buildPackageBundle(
Map<String, String> replacementData,
Map<String, ? super Object> params, File outputParentDir) throws
Map<String, ? super Object> params, Path outputParentDir) throws
PackagerException, IOException {
prepareProjectConfig(replacementData, params);
adjustPermissionsRecursive(createMetaPackage(params).sourceRoot().toFile());
adjustPermissionsRecursive(createMetaPackage(params).sourceRoot());
return buildDeb(params, outputParentDir);
}
@ -309,12 +308,12 @@ public class LinuxDebBundler extends LinuxPackageBundler {
*
* This cannot be directly backport to 22u which is built with 1.6
*/
private void setPermissions(File file, String permissions) {
private void setPermissions(Path file, String permissions) {
Set<PosixFilePermission> filePermissions =
PosixFilePermissions.fromString(permissions);
try {
if (file.exists()) {
Files.setPosixFilePermissions(file.toPath(), filePermissions);
if (Files.exists(file)) {
Files.setPosixFilePermissions(file, filePermissions);
}
} catch (IOException ex) {
Log.error(ex.getMessage());
@ -335,16 +334,16 @@ public class LinuxDebBundler extends LinuxPackageBundler {
return false;
}
private void adjustPermissionsRecursive(File dir) throws IOException {
Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() {
private void adjustPermissionsRecursive(Path dir) throws IOException {
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs)
throws IOException {
if (file.endsWith(".so") || !Files.isExecutable(file)) {
setPermissions(file.toFile(), "rw-r--r--");
setPermissions(file, "rw-r--r--");
} else if (Files.isExecutable(file)) {
setPermissions(file.toFile(), "rwxr-xr-x");
setPermissions(file, "rwxr-xr-x");
}
return FileVisitResult.CONTINUE;
}
@ -353,7 +352,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
if (e == null) {
setPermissions(dir.toFile(), "rwxr-xr-x");
setPermissions(dir, "rwxr-xr-x");
return FileVisitResult.CONTINUE;
} else {
// directory iteration failed
@ -383,7 +382,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
.setSubstitutionData(data)
.saveToFile(dstFilePath);
if (permissions != null) {
setPermissions(dstFilePath.toFile(), permissions);
setPermissions(dstFilePath, permissions);
}
}
@ -415,7 +414,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
if (!StandardBundlerParam.isRuntimeInstaller(params)) {
debianFiles.add(new DebianFile(
getConfig_CopyrightFile(params).toPath(),
getConfig_CopyrightFile(params),
"resource.copyright-file"));
}
@ -440,7 +439,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
return data;
}
private File getConfig_CopyrightFile(Map<String, ? super Object> params) {
private Path getConfig_CopyrightFile(Map<String, ? super Object> params) {
final String installDir = LINUX_INSTALL_DIR.fetchFrom(params);
final String packageName = PACKAGE_NAME.fetchFrom(params);
@ -452,15 +451,15 @@ public class LinuxDebBundler extends LinuxPackageBundler {
}
return createMetaPackage(params).sourceRoot().resolve(
Path.of("/").relativize(installPath)).toFile();
Path.of("/").relativize(installPath));
}
private File buildDeb(Map<String, ? super Object> params,
File outdir) throws IOException {
File outFile = new File(outdir,
private Path buildDeb(Map<String, ? super Object> params,
Path outdir) throws IOException {
Path outFile = outdir.resolve(
FULL_PACKAGE_NAME.fetchFrom(params)+".deb");
Log.verbose(MessageFormat.format(I18N.getString(
"message.outputting-to-location"), outFile.getAbsolutePath()));
"message.outputting-to-location"), outFile.toAbsolutePath().toString()));
PlatformPackage thePackage = createMetaPackage(params);
@ -470,13 +469,13 @@ public class LinuxDebBundler extends LinuxPackageBundler {
cmdline.add("--verbose");
}
cmdline.addAll(List.of("-b", thePackage.sourceRoot().toString(),
outFile.getAbsolutePath()));
outFile.toAbsolutePath().toString()));
// run dpkg
Executor.of(cmdline.toArray(String[]::new)).executeExpectSuccess();
Log.verbose(MessageFormat.format(I18N.getString(
"message.output-to-location"), outFile.getAbsolutePath()));
"message.output-to-location"), outFile.toAbsolutePath().toString()));
return outFile;
}

View File

@ -24,7 +24,6 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
@ -104,21 +103,21 @@ abstract class LinuxPackageBundler extends AbstractBundler {
}
@Override
final public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
IOUtils.writableOutputDir(outputParentDir.toPath());
final public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
IOUtils.writableOutputDir(outputParentDir);
PlatformPackage thePackage = createMetaPackage(params);
Function<File, ApplicationLayout> initAppImageLayout = imageRoot -> {
Function<Path, ApplicationLayout> initAppImageLayout = imageRoot -> {
ApplicationLayout layout = appImageLayout(params);
layout.pathGroup().setPath(new Object(),
AppImageFile.getPathInAppImage(Path.of("")));
return layout.resolveAt(imageRoot.toPath());
return layout.resolveAt(imageRoot);
};
try {
File appImage = StandardBundlerParam.getPredefinedAppImage(params);
Path appImage = StandardBundlerParam.getPredefinedAppImage(params);
// we either have an application image or need to build one
if (appImage != null) {
@ -126,7 +125,7 @@ abstract class LinuxPackageBundler extends AbstractBundler {
thePackage.sourceApplicationLayout());
} else {
final Path srcAppImageRoot = thePackage.sourceRoot().resolve("src");
appImage = appImageBundler.execute(params, srcAppImageRoot.toFile());
appImage = appImageBundler.execute(params, srcAppImageRoot);
ApplicationLayout srcAppLayout = initAppImageLayout.apply(
appImage);
if (appImage.equals(PREDEFINED_RUNTIME_IMAGE.fetchFrom(params))) {
@ -137,7 +136,7 @@ abstract class LinuxPackageBundler extends AbstractBundler {
// Application image is a newly created directory tree.
// Move it.
srcAppLayout.move(thePackage.sourceApplicationLayout());
IOUtils.deleteRecursive(srcAppImageRoot.toFile());
IOUtils.deleteRecursive(srcAppImageRoot);
}
}
@ -153,10 +152,10 @@ abstract class LinuxPackageBundler extends AbstractBundler {
data.putAll(createReplacementData(params));
File packageBundle = buildPackageBundle(Collections.unmodifiableMap(
Path packageBundle = buildPackageBundle(Collections.unmodifiableMap(
data), params, outputParentDir);
verifyOutputBundle(params, packageBundle.toPath()).stream()
verifyOutputBundle(params, packageBundle).stream()
.filter(Objects::nonNull)
.forEachOrdered(ex -> {
Log.verbose(ex.getLocalizedMessage());
@ -240,9 +239,9 @@ abstract class LinuxPackageBundler extends AbstractBundler {
abstract protected Map<String, String> createReplacementData(
Map<String, ? super Object> params) throws IOException;
abstract protected File buildPackageBundle(
abstract protected Path buildPackageBundle(
Map<String, String> replacementData,
Map<String, ? super Object> params, File outputParentDir) throws
Map<String, ? super Object> params, Path outputParentDir) throws
PackagerException, IOException;
final protected PlatformPackage createMetaPackage(
@ -266,7 +265,7 @@ abstract class LinuxPackageBundler extends AbstractBundler {
@Override
public Path sourceRoot() {
return IMAGES_ROOT.fetchFrom(params).toPath().toAbsolutePath();
return IMAGES_ROOT.fetchFrom(params).toAbsolutePath();
}
@Override

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.text.MessageFormat;
@ -147,9 +146,9 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
}
@Override
protected File buildPackageBundle(
protected Path buildPackageBundle(
Map<String, String> replacementData,
Map<String, ? super Object> params, File outputParentDir) throws
Map<String, ? super Object> params, Path outputParentDir) throws
PackagerException, IOException {
Path specFile = specFile(params);
@ -160,7 +159,7 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
.setSubstitutionData(replacementData)
.saveToFile(specFile);
return buildRPM(params, outputParentDir.toPath()).toFile();
return buildRPM(params, outputParentDir);
}
@Override
@ -275,7 +274,7 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
}
private Path specFile(Map<String, ? super Object> params) {
return TEMP_ROOT.fetchFrom(params).toPath().resolve(Path.of("SPECS",
return TEMP_ROOT.fetchFrom(params).resolve(Path.of("SPECS",
PACKAGE_NAME.fetchFrom(params) + ".spec"));
}
@ -302,7 +301,7 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
"--define", String.format("%%_rpmdir %s", rpmFile.getParent()),
// do not use other system directories to build as current user
"--define", String.format("%%_topdir %s",
TEMP_ROOT.fetchFrom(params).toPath().toAbsolutePath()),
TEMP_ROOT.fetchFrom(params).toAbsolutePath()),
"--define", String.format("%%_rpmfilename %s", rpmFile.getFileName())
).executeExpectSuccess();

View File

@ -25,8 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@ -120,20 +118,21 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
},
(s, p) -> s);
public static final BundlerParamInfo<File> ICON_ICNS =
public static final BundlerParamInfo<Path> ICON_ICNS =
new StandardBundlerParam<>(
"icon.icns",
File.class,
Path.class,
params -> {
File f = ICON.fetchFrom(params);
if (f != null && !f.getName().toLowerCase().endsWith(".icns")) {
Path f = ICON.fetchFrom(params);
if (f != null && f.getFileName() != null && !f.getFileName()
.toString().toLowerCase().endsWith(".icns")) {
Log.error(MessageFormat.format(
I18N.getString("message.icon-not-icns"), f));
return null;
}
return f;
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
public static final StandardBundlerParam<Boolean> SIGN_BUNDLE =
new StandardBundlerParam<>(
@ -242,8 +241,8 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
Map<String, ? super Object> originalParams = new HashMap<>(params);
// Generate PkgInfo
File pkgInfoFile = new File(contentsDir.toFile(), "PkgInfo");
pkgInfoFile.createNewFile();
Path pkgInfoFile = contentsDir.resolve("PkgInfo");
Files.createFile(pkgInfoFile);
writePkgInfo(pkgInfoFile);
Path executable = macOSDir.resolve(getLauncherName(params));
@ -290,11 +289,9 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
// copy file association icons
for (Map<String, ?
super Object> fa : FILE_ASSOCIATIONS.fetchFrom(params)) {
File f = FA_ICON.fetchFrom(fa);
if (f != null && f.exists()) {
try (InputStream in2 = new FileInputStream(f)) {
Files.copy(in2, resourcesDir.resolve(f.getName()));
}
Path f = FA_ICON.fetchFrom(fa);
if (IOUtils.exists(f)) {
IOUtils.copyFile(f, resourcesDir.resolve(f.getFileName()));
}
}
@ -306,11 +303,11 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
private void copyRuntimeFiles(Map<String, ? super Object> params)
throws IOException {
// Generate Info.plist
writeInfoPlist(contentsDir.resolve("Info.plist").toFile(), params);
writeInfoPlist(contentsDir.resolve("Info.plist"), params);
// generate java runtime info.plist
writeRuntimeInfoPlist(
runtimeDir.resolve("Contents/Info.plist").toFile(), params);
runtimeDir.resolve("Contents/Info.plist"), params);
// copy library
Path runtimeMacOSDir = Files.createDirectories(
@ -346,8 +343,8 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
}
}
static File getConfig_Entitlements(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
static Path getConfig_Entitlements(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
getLauncherName(params) + ".entitlements");
}
@ -382,7 +379,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
}
}
private void writeRuntimeInfoPlist(File file,
private void writeRuntimeInfoPlist(Path file,
Map<String, ? super Object> params) throws IOException {
Map<String, String> data = new HashMap<>();
String identifier = StandardBundlerParam.isRuntimeInstaller(params) ?
@ -427,10 +424,10 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
}
}
private void writeInfoPlist(File file, Map<String, ? super Object> params)
private void writeInfoPlist(Path file, Map<String, ? super Object> params)
throws IOException {
Log.verbose(MessageFormat.format(I18N.getString(
"message.preparing-info-plist"), file.getAbsolutePath()));
"message.preparing-info-plist"), file.toAbsolutePath()));
//prepare config for exe
//Note: do not need CFBundleDisplayName if we don't support localization
@ -460,7 +457,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
+ "." + ((extensions == null || extensions.isEmpty())
? "mime" : extensions.get(0));
String description = FA_DESCRIPTION.fetchFrom(fileAssociation);
File icon = FA_ICON.fetchFrom(fileAssociation);
Path icon = FA_ICON.fetchFrom(fileAssociation);
bundleDocumentTypes.append(" <dict>\n");
writeStringArrayPlist(bundleDocumentTypes, "LSItemContentTypes",
@ -482,9 +479,9 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
FA_MAC_LSDOCINPLACE.fetchFrom(fileAssociation));
writeBoolPlist(bundleDocumentTypes, "UISupportsDocumentBrowser",
FA_MAC_UIDOCBROWSER.fetchFrom(fileAssociation));
if (icon != null && icon.exists()) {
if (IOUtils.exists(icon)) {
writeStringPlist(bundleDocumentTypes, "CFBundleTypeIconFile",
icon.getName());
icon.getFileName().toString());
}
bundleDocumentTypes.append(" </dict>\n");
@ -496,8 +493,9 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
writeStringArrayPlist(exportedTypes, "UTTypeConformsTo",
FA_MAC_UTTYPECONFORMSTO.fetchFrom(fileAssociation));
if (icon != null && icon.exists()) {
writeStringPlist(exportedTypes, "UTTypeIconFile", icon.getName());
if (IOUtils.exists(icon)) {
writeStringPlist(exportedTypes, "UTTypeIconFile",
icon.getFileName().toString());
}
exportedTypes.append("\n")
.append(" <key>UTTypeTagSpecification</key>\n")
@ -532,11 +530,11 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
.saveToFile(file);
}
private void writePkgInfo(File file) throws IOException {
private void writePkgInfo(Path file) throws IOException {
//hardcoded as it does not seem we need to change it ever
String signature = "????";
try (Writer out = Files.newBufferedWriter(file.toPath())) {
try (Writer out = Files.newBufferedWriter(file)) {
out.write(OS_TYPE_CODE + signature);
out.flush();
}
@ -557,7 +555,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
}
// get current keychain list
String keyChainPath = new File (keyChain).getAbsolutePath().toString();
String keyChainPath = Path.of(keyChain).toAbsolutePath().toString();
List<String> keychainList = new ArrayList<>();
int ret = IOUtils.getProcessOutput(
keychainList, "security", "list-keychains");
@ -621,7 +619,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
static void signAppBundle(
Map<String, ? super Object> params, Path appLocation,
String signingIdentity, String identifierPrefix, File entitlements)
String signingIdentity, String identifierPrefix, Path entitlements)
throws IOException {
AtomicReference<IOException> toThrow = new AtomicReference<>();
String appExecutable = "/Contents/MacOS/" + APP_NAME.fetchFrom(params);
@ -683,8 +681,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
try {
Set<PosixFilePermission> oldPermissions =
Files.getPosixFilePermissions(p);
File f = p.toFile();
f.setWritable(true, true);
p.toFile().setWritable(true, true);
ProcessBuilder pb = new ProcessBuilder(args);
@ -798,17 +795,15 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
}
try {
File infoPList = new File(PREDEFINED_APP_IMAGE.fetchFrom(params) +
File.separator + "Contents" +
File.separator + "Info.plist");
Path infoPList = PREDEFINED_APP_IMAGE.fetchFrom(params).resolve("Contents").
resolve("Info.plist");
DocumentBuilderFactory dbf
= DocumentBuilderFactory.newDefaultInstance();
dbf.setFeature("http://apache.org/xml/features/" +
"nonvalidating/load-external-dtd", false);
DocumentBuilder b = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = b.parse(new FileInputStream(
infoPList.getAbsolutePath()));
org.w3c.dom.Document doc = b.parse(Files.newInputStream(infoPList));
XPath xPath = XPathFactory.newInstance().newXPath();
// Query for the value of <string> element preceding <key>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,8 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@ -103,21 +104,21 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
params -> "-MacAppStore",
(s, p) -> s);
public File bundle(Map<String, ? super Object> params,
File outdir) throws PackagerException {
public Path bundle(Map<String, ? super Object> params,
Path outdir) throws PackagerException {
Log.verbose(MessageFormat.format(I18N.getString(
"message.building-bundle"), APP_NAME.fetchFrom(params)));
IOUtils.writableOutputDir(outdir.toPath());
IOUtils.writableOutputDir(outdir);
// first, load in some overrides
// icns needs @2 versions, so load in the @2 default
params.put(DEFAULT_ICNS_ICON.getID(), TEMPLATE_BUNDLE_ICON_HIDPI);
// now we create the app
File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
Path appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
try {
appImageDir.mkdirs();
Files.createDirectories(appImageDir);
try {
MacAppImageBuilder.addNewKeychain(params);
@ -126,7 +127,7 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
}
// first, make sure we don't use the local signing key
params.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null);
File appLocation = prepareAppBundle(params);
Path appLocation = prepareAppBundle(params);
String signingIdentity =
MAC_APP_STORE_APP_SIGNING_KEY.fetchFrom(params);
@ -134,7 +135,7 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params);
MacAppImageBuilder.prepareEntitlements(params);
MacAppImageBuilder.signAppBundle(params, appLocation.toPath(),
MacAppImageBuilder.signAppBundle(params, appLocation,
signingIdentity, identifierPrefix,
MacAppImageBuilder.getConfig_Entitlements(params));
MacAppImageBuilder.restoreKeychainList(params);
@ -142,10 +143,10 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
ProcessBuilder pb;
// create the final pkg file
File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
Path finalPKG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
+ INSTALLER_SUFFIX.fetchFrom(params)
+ ".pkg");
outdir.mkdirs();
Files.createDirectories(outdir);
String installIdentify =
MAC_APP_STORE_PKG_SIGNING_KEY.fetchFrom(params);
@ -164,7 +165,7 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
buildOptions.add("--keychain");
buildOptions.add(keychainName);
}
buildOptions.add(finalPKG.getAbsolutePath());
buildOptions.add(finalPKG.toAbsolutePath().toString());
pb = new ProcessBuilder(buildOptions);
@ -243,8 +244,8 @@ public class MacAppStoreBundler extends MacBaseInstallerBundler {
}
@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
return bundle(params, outputParentDir);
}

View File

@ -26,10 +26,10 @@
package jdk.incubator.jpackage.internal;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@ -43,21 +43,23 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.VERSION;
public abstract class MacBaseInstallerBundler extends AbstractBundler {
public final BundlerParamInfo<File> APP_IMAGE_TEMP_ROOT =
public final BundlerParamInfo<Path> APP_IMAGE_TEMP_ROOT =
new StandardBundlerParam<>(
"mac.app.imageRoot",
File.class,
Path.class,
params -> {
File imageDir = IMAGES_ROOT.fetchFrom(params);
if (!imageDir.exists()) imageDir.mkdirs();
Path imageDir = IMAGES_ROOT.fetchFrom(params);
try {
if (!IOUtils.exists(imageDir)) {
Files.createDirectories(imageDir);
}
return Files.createTempDirectory(
imageDir.toPath(), "image-").toFile();
imageDir, "image-");
} catch (IOException e) {
return new File(imageDir, getID()+ ".image");
return imageDir.resolve(getID()+ ".image");
}
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
public static final BundlerParamInfo<String> SIGNING_KEY_USER =
new StandardBundlerParam<>(
@ -110,8 +112,8 @@ public abstract class MacBaseInstallerBundler extends AbstractBundler {
protected void validateAppImageAndBundeler(
Map<String, ? super Object> params) throws ConfigException {
if (PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
File applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
if (!applicationImage.exists()) {
Path applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
if (!IOUtils.exists(applicationImage)) {
throw new ConfigException(
MessageFormat.format(I18N.getString(
"message.app-image-dir-does-not-exist"),
@ -132,14 +134,14 @@ public abstract class MacBaseInstallerBundler extends AbstractBundler {
}
}
protected File prepareAppBundle(Map<String, ? super Object> params)
protected Path prepareAppBundle(Map<String, ? super Object> params)
throws PackagerException {
File predefinedImage =
Path predefinedImage =
StandardBundlerParam.getPredefinedAppImage(params);
if (predefinedImage != null) {
return predefinedImage;
}
File appImageRoot = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
Path appImageRoot = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
return appImageBundler.execute(params, appImageRoot);
}

View File

@ -27,11 +27,11 @@ package jdk.incubator.jpackage.internal;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.StandardCopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -52,8 +52,8 @@ public final class MacCertificate {
return verifyCertificate(this.certificate);
}
private static File findCertificate(String certificate) {
File result = null;
private static Path findCertificate(String certificate) {
Path result = null;
List<String> args = new ArrayList<>();
args.add("security");
@ -68,10 +68,10 @@ public final class MacCertificate {
ProcessBuilder security = new ProcessBuilder(args);
IOUtils.exec(security, false, ps);
File output = File.createTempFile("tempfile", ".tmp");
Path output = Files.createTempFile("tempfile", ".tmp");
Files.copy(new ByteArrayInputStream(baos.toByteArray()),
output.toPath(), StandardCopyOption.REPLACE_EXISTING);
output, StandardCopyOption.REPLACE_EXISTING);
result = output;
}
@ -111,7 +111,7 @@ public final class MacCertificate {
boolean result = false;
try {
File file = null;
Path file = null;
Date certificateDate = null;
try {
@ -119,12 +119,12 @@ public final class MacCertificate {
if (file != null) {
certificateDate = findCertificateDate(
file.getCanonicalPath());
file.toFile().getCanonicalPath());
}
}
finally {
if (file != null) {
file.delete();
Files.delete(file);
}
}

View File

@ -69,22 +69,22 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
params -> "",
(s, p) -> s);
public File bundle(Map<String, ? super Object> params,
File outdir) throws PackagerException {
public Path bundle(Map<String, ? super Object> params,
Path outdir) throws PackagerException {
Log.verbose(MessageFormat.format(I18N.getString("message.building-dmg"),
APP_NAME.fetchFrom(params)));
IOUtils.writableOutputDir(outdir.toPath());
IOUtils.writableOutputDir(outdir);
try {
File appLocation = prepareAppBundle(params);
Path appLocation = prepareAppBundle(params);
if (appLocation != null && prepareConfigFiles(params)) {
File configScript = getConfig_Script(params);
if (configScript.exists()) {
Path configScript = getConfig_Script(params);
if (IOUtils.exists(configScript)) {
Log.verbose(MessageFormat.format(
I18N.getString("message.running-script"),
configScript.getAbsolutePath()));
configScript.toAbsolutePath().toString()));
IOUtils.run("bash", configScript);
}
@ -101,16 +101,19 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
private void prepareDMGSetupScript(Map<String, ? super Object> params)
throws IOException {
File dmgSetup = getConfig_VolumeScript(params);
Path dmgSetup = getConfig_VolumeScript(params);
Log.verbose(MessageFormat.format(
I18N.getString("message.preparing-dmg-setup"),
dmgSetup.getAbsolutePath()));
dmgSetup.toAbsolutePath().toString()));
// We need to use URL for DMG to find it. We cannot use volume name, since
// user might have open DMG with same volume name already. Url should end with
// '/' and it should be real path (no symbolic links).
File imageDir = IMAGES_ROOT.fetchFrom(params);
if (!imageDir.exists()) imageDir.mkdirs(); // Create it, since it does not exist
Path imageDir = IMAGES_ROOT.fetchFrom(params);
if (!Files.exists(imageDir)) {
// Create it, since it does not exist
Files.createDirectories(imageDir);
}
Path rootPath = Path.of(imageDir.toString()).toRealPath();
Path volumePath = rootPath.resolve(APP_NAME.fetchFrom(params));
String volumeUrl = volumePath.toUri().toString() + File.separator;
@ -134,24 +137,24 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
.saveToFile(dmgSetup);
}
private File getConfig_VolumeScript(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_VolumeScript(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-dmg-setup.scpt");
}
private File getConfig_VolumeBackground(
private Path getConfig_VolumeBackground(
Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-background.tiff");
}
private File getConfig_VolumeIcon(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_VolumeIcon(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-volume.icns");
}
private File getConfig_LicenseFile(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_LicenseFile(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-license.plist");
}
@ -162,9 +165,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
return;
}
File licFile = new File(licFileStr);
Path licFile = Path.of(licFileStr);
byte[] licenseContentOriginal =
Files.readAllBytes(licFile.toPath());
Files.readAllBytes(licFile);
String licenseInBase64 =
Base64.getEncoder().encodeToString(licenseContentOriginal);
@ -205,8 +208,8 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
}
// name of post-image script
private File getConfig_Script(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_Script(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-post-image.sh");
}
@ -218,9 +221,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
"/usr/bin/SetFile", "/Developer/usr/bin/SetFile"};
String setFilePath = null;
for (String path: typicalPaths) {
File f = new File(path);
if (f.exists() && f.canExecute()) {
for (String path : typicalPaths) {
Path f = Path.of(path);
if (Files.exists(f) && Files.isExecutable(f)) {
setFilePath = path;
break;
}
@ -251,9 +254,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
BufferedReader br = new BufferedReader(isr);
String lineRead = br.readLine();
if (lineRead != null) {
File f = new File(lineRead);
if (f.exists() && f.canExecute()) {
return f.getAbsolutePath();
Path f = Path.of(lineRead);
if (Files.exists(f) && Files.isExecutable(f)) {
return f.toAbsolutePath().toString();
}
}
} catch (IOException ignored) {}
@ -261,31 +264,30 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
return null;
}
private File buildDMG( Map<String, ? super Object> params,
File appLocation, File outdir) throws IOException, PackagerException {
private Path buildDMG( Map<String, ? super Object> params,
Path appLocation, Path outdir) throws IOException {
boolean copyAppImage = false;
File imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!imagesRoot.exists()) imagesRoot.mkdirs();
Path imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!Files.exists(imagesRoot)) {
Files.createDirectories(imagesRoot);
}
File protoDMG = new File(imagesRoot,
APP_NAME.fetchFrom(params) +"-tmp.dmg");
File finalDMG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
Path protoDMG = imagesRoot.resolve(APP_NAME.fetchFrom(params) +"-tmp.dmg");
Path finalDMG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
+ INSTALLER_SUFFIX.fetchFrom(params) + ".dmg");
File srcFolder = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
File predefinedImage =
StandardBundlerParam.getPredefinedAppImage(params);
Path srcFolder = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
Path predefinedImage = StandardBundlerParam.getPredefinedAppImage(params);
if (predefinedImage != null) {
srcFolder = predefinedImage;
} else if (StandardBundlerParam.isRuntimeInstaller(params)) {
Path newRoot = Files.createTempDirectory(
TEMP_ROOT.fetchFrom(params).toPath(), "root-");
Path newRoot = Files.createTempDirectory(TEMP_ROOT.fetchFrom(params),
"root-");
// first, is this already a runtime with
// <runtime>/Contents/Home - if so we need the Home dir
Path original = appLocation.toPath();
Path home = original.resolve("Contents/Home");
Path source = (Files.exists(home)) ? home : original;
Path home = appLocation.resolve("Contents/Home");
Path source = (Files.exists(home)) ? home : appLocation;
// Then we need to put back the <NAME>/Content/Home
Path root = newRoot.resolve(
@ -294,21 +296,23 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
IOUtils.copyRecursive(source, dest);
srcFolder = newRoot.toFile();
srcFolder = newRoot;
}
Log.verbose(MessageFormat.format(I18N.getString(
"message.creating-dmg-file"), finalDMG.getAbsolutePath()));
"message.creating-dmg-file"), finalDMG.toAbsolutePath()));
protoDMG.delete();
if (finalDMG.exists() && !finalDMG.delete()) {
Files.deleteIfExists(protoDMG);
try {
Files.deleteIfExists(finalDMG);
} catch (IOException ex) {
throw new IOException(MessageFormat.format(I18N.getString(
"message.dmg-cannot-be-overwritten"),
finalDMG.getAbsolutePath()));
finalDMG.toAbsolutePath()));
}
protoDMG.getParentFile().mkdirs();
finalDMG.getParentFile().mkdirs();
Files.createDirectories(protoDMG.getParent());
Files.createDirectories(finalDMG.getParent());
String hdiUtilVerbosityFlag = VERBOSE.fetchFrom(params) ?
"-verbose" : "-quiet";
@ -318,9 +322,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
hdiutil,
"create",
hdiUtilVerbosityFlag,
"-srcfolder", srcFolder.getAbsolutePath(),
"-srcfolder", srcFolder.toAbsolutePath().toString(),
"-volname", APP_NAME.fetchFrom(params),
"-ov", protoDMG.getAbsolutePath(),
"-ov", protoDMG.toAbsolutePath().toString(),
"-fs", "HFS+",
"-format", "UDRW");
try {
@ -332,8 +336,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
// DMG and copy files manually. See JDK-8248059.
copyAppImage = true;
long size = new PathGroup(Map.of(new Object(), srcFolder.toPath()))
.sizeInBytes();
long size = new PathGroup(Map.of(new Object(), srcFolder)).sizeInBytes();
size += 50 * 1024 * 1024; // Add extra 50 megabytes. Actually DMG size will
// not be bigger, but it will able to hold additional 50 megabytes of data.
// We need extra room for icons and background image. When we providing
@ -344,7 +347,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
hdiUtilVerbosityFlag,
"-size", String.valueOf(size),
"-volname", APP_NAME.fetchFrom(params),
"-ov", protoDMG.getAbsolutePath(),
"-ov", protoDMG.toAbsolutePath().toString(),
"-fs", "HFS+");
IOUtils.exec(pb);
}
@ -353,13 +356,12 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
pb = new ProcessBuilder(
hdiutil,
"attach",
protoDMG.getAbsolutePath(),
protoDMG.toAbsolutePath().toString(),
hdiUtilVerbosityFlag,
"-mountroot", imagesRoot.getAbsolutePath());
"-mountroot", imagesRoot.toAbsolutePath().toString());
IOUtils.exec(pb, false, null, true);
File mountedRoot = new File(imagesRoot.getAbsolutePath(),
APP_NAME.fetchFrom(params));
Path mountedRoot = imagesRoot.resolve(APP_NAME.fetchFrom(params));
// Copy app image, since we did not create DMG with it, but instead we created
// empty one.
@ -367,36 +369,36 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
// In case of predefine app image srcFolder will point to app bundle, so if
// we use it as is we will copy content of app bundle, but we need app bundle
// folder as well.
if (srcFolder.toPath().toString().toLowerCase().endsWith(".app")) {
Path destPath = mountedRoot.toPath()
.resolve(srcFolder.toPath().getFileName());
if (srcFolder.toString().toLowerCase().endsWith(".app")) {
Path destPath = mountedRoot
.resolve(srcFolder.getFileName());
Files.createDirectory(destPath);
IOUtils.copyRecursive(srcFolder.toPath(), destPath);
IOUtils.copyRecursive(srcFolder, destPath);
} else {
IOUtils.copyRecursive(srcFolder.toPath(), mountedRoot.toPath());
IOUtils.copyRecursive(srcFolder, mountedRoot);
}
}
try {
// background image
File bgdir = new File(mountedRoot, BACKGROUND_IMAGE_FOLDER);
bgdir.mkdirs();
Path bgdir = mountedRoot.resolve(BACKGROUND_IMAGE_FOLDER);
Files.createDirectories(bgdir);
IOUtils.copyFile(getConfig_VolumeBackground(params),
new File(bgdir, BACKGROUND_IMAGE));
bgdir.resolve(BACKGROUND_IMAGE));
// We will not consider setting background image and creating link
// to install-dir in DMG as critical error, since it can fail in
// headless enviroment.
try {
pb = new ProcessBuilder("osascript",
getConfig_VolumeScript(params).getAbsolutePath());
getConfig_VolumeScript(params).toAbsolutePath().toString());
IOUtils.exec(pb);
} catch (IOException ex) {
Log.verbose(ex);
}
// volume icon
File volumeIconFile = new File(mountedRoot, ".VolumeIcon.icns");
Path volumeIconFile = mountedRoot.resolve(".VolumeIcon.icns");
IOUtils.copyFile(getConfig_VolumeIcon(params),
volumeIconFile);
@ -408,7 +410,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
if (setFileUtility != null) {
//can not find utility => keep going without icon
try {
volumeIconFile.setWritable(true);
volumeIconFile.toFile().setWritable(true);
// The "creator" attribute on a file is a legacy attribute
// but it seems Finder excepts these bytes to be
// "icnC" for the volume icon
@ -416,14 +418,14 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
pb = new ProcessBuilder(
setFileUtility,
"-c", "icnC",
volumeIconFile.getAbsolutePath());
volumeIconFile.toAbsolutePath().toString());
IOUtils.exec(pb);
volumeIconFile.setReadOnly();
volumeIconFile.toFile().setReadOnly();
pb = new ProcessBuilder(
setFileUtility,
"-a", "C",
mountedRoot.getAbsolutePath());
mountedRoot.toAbsolutePath().toString());
IOUtils.exec(pb);
} catch (IOException ex) {
Log.error(ex.getMessage());
@ -440,7 +442,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
"detach",
"-force",
hdiUtilVerbosityFlag,
mountedRoot.getAbsolutePath());
mountedRoot.toAbsolutePath().toString());
IOUtils.exec(pb);
}
@ -448,19 +450,19 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
pb = new ProcessBuilder(
hdiutil,
"convert",
protoDMG.getAbsolutePath(),
protoDMG.toAbsolutePath().toString(),
hdiUtilVerbosityFlag,
"-format", "UDZO",
"-o", finalDMG.getAbsolutePath());
"-o", finalDMG.toAbsolutePath().toString());
IOUtils.exec(pb);
//add license if needed
if (getConfig_LicenseFile(params).exists()) {
if (Files.exists(getConfig_LicenseFile(params))) {
//hdiutil unflatten your_image_file.dmg
pb = new ProcessBuilder(
hdiutil,
"unflatten",
finalDMG.getAbsolutePath()
finalDMG.toAbsolutePath().toString()
);
IOUtils.exec(pb);
@ -468,9 +470,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
pb = new ProcessBuilder(
hdiutil,
"udifrez",
finalDMG.getAbsolutePath(),
finalDMG.toAbsolutePath().toString(),
"-xml",
getConfig_LicenseFile(params).getAbsolutePath()
getConfig_LicenseFile(params).toAbsolutePath().toString()
);
IOUtils.exec(pb);
@ -478,18 +480,18 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
pb = new ProcessBuilder(
hdiutil,
"flatten",
finalDMG.getAbsolutePath()
finalDMG.toAbsolutePath().toString()
);
IOUtils.exec(pb);
}
//Delete the temporary image
protoDMG.delete();
Files.deleteIfExists(protoDMG);
Log.verbose(MessageFormat.format(I18N.getString(
"message.output-to-location"),
APP_NAME.fetchFrom(params), finalDMG.getAbsolutePath()));
APP_NAME.fetchFrom(params), finalDMG.toAbsolutePath().toString()));
return finalDMG;
}
@ -530,8 +532,8 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
}
@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
return bundle(params, outputParentDir);
}
@ -545,8 +547,8 @@ public class MacDmgBundler extends MacBaseInstallerBundler {
public static boolean isSupported() {
try {
for (String s : required) {
File f = new File(s);
if (!f.exists() || !f.canExecute()) {
Path f = Path.of(s);
if (!Files.exists(f) || !Files.isExecutable(f)) {
return false;
}
}

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
@ -64,30 +63,38 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
private static final String TEMPLATE_POSTINSTALL_SCRIPT =
"postinstall.template";
private static final BundlerParamInfo<File> PACKAGES_ROOT =
private static final BundlerParamInfo<Path> PACKAGES_ROOT =
new StandardBundlerParam<>(
"mac.pkg.packagesRoot",
File.class,
Path.class,
params -> {
File packagesRoot =
new File(TEMP_ROOT.fetchFrom(params), "packages");
packagesRoot.mkdirs();
Path packagesRoot =
TEMP_ROOT.fetchFrom(params).resolve("packages");
try {
Files.createDirectories(packagesRoot);
} catch (IOException ioe) {
return null;
}
return packagesRoot;
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
protected final BundlerParamInfo<File> SCRIPTS_DIR =
protected final BundlerParamInfo<Path> SCRIPTS_DIR =
new StandardBundlerParam<>(
"mac.pkg.scriptsDir",
File.class,
Path.class,
params -> {
File scriptsDir =
new File(CONFIG_ROOT.fetchFrom(params), "scripts");
scriptsDir.mkdirs();
Path scriptsDir =
CONFIG_ROOT.fetchFrom(params).resolve("scripts");
try {
Files.createDirectories(scriptsDir);
} catch (IOException ioe) {
return null;
}
return scriptsDir;
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
public static final
BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY =
@ -121,23 +128,23 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
params -> "",
(s, p) -> s);
public File bundle(Map<String, ? super Object> params,
File outdir) throws PackagerException {
public Path bundle(Map<String, ? super Object> params,
Path outdir) throws PackagerException {
Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"),
APP_NAME.fetchFrom(params)));
IOUtils.writableOutputDir(outdir.toPath());
IOUtils.writableOutputDir(outdir);
try {
File appImageDir = prepareAppBundle(params);
Path appImageDir = prepareAppBundle(params);
if (appImageDir != null && prepareConfigFiles(params)) {
File configScript = getConfig_Script(params);
if (configScript.exists()) {
Path configScript = getConfig_Script(params);
if (IOUtils.exists(configScript)) {
Log.verbose(MessageFormat.format(I18N.getString(
"message.running-script"),
configScript.getAbsolutePath()));
configScript.toAbsolutePath().toString()));
IOUtils.run("bash", configScript);
}
@ -150,33 +157,33 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
}
}
private File getPackages_AppPackage(Map<String, ? super Object> params) {
return new File(PACKAGES_ROOT.fetchFrom(params),
private Path getPackages_AppPackage(Map<String, ? super Object> params) {
return PACKAGES_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-app.pkg");
}
private File getConfig_DistributionXMLFile(
private Path getConfig_DistributionXMLFile(
Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist");
return CONFIG_ROOT.fetchFrom(params).resolve("distribution.dist");
}
private File getConfig_BackgroundImage(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_BackgroundImage(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-background.png");
}
private File getConfig_BackgroundImageDarkAqua(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_BackgroundImageDarkAqua(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-background-darkAqua.png");
}
private File getScripts_PreinstallFile(Map<String, ? super Object> params) {
return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall");
private Path getScripts_PreinstallFile(Map<String, ? super Object> params) {
return SCRIPTS_DIR.fetchFrom(params).resolve("preinstall");
}
private File getScripts_PostinstallFile(
private Path getScripts_PostinstallFile(
Map<String, ? super Object> params) {
return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall");
return SCRIPTS_DIR.fetchFrom(params).resolve("postinstall");
}
private String getAppIdentifier(Map<String, ? super Object> params) {
@ -199,13 +206,13 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
.setCategory(I18N.getString("resource.pkg-preinstall-script"))
.setSubstitutionData(data)
.saveToFile(getScripts_PreinstallFile(params));
getScripts_PreinstallFile(params).setExecutable(true, false);
getScripts_PreinstallFile(params).toFile().setExecutable(true, false);
createResource(TEMPLATE_POSTINSTALL_SCRIPT, params)
.setCategory(I18N.getString("resource.pkg-postinstall-script"))
.setSubstitutionData(data)
.saveToFile(getScripts_PostinstallFile(params));
getScripts_PostinstallFile(params).setExecutable(true, false);
getScripts_PostinstallFile(params).toFile().setExecutable(true, false);
}
private static String URLEncoding(String pkgName) throws URISyntaxException {
@ -215,12 +222,12 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
private void prepareDistributionXMLFile(Map<String, ? super Object> params)
throws IOException {
File f = getConfig_DistributionXMLFile(params);
Path f = getConfig_DistributionXMLFile(params);
Log.verbose(MessageFormat.format(I18N.getString(
"message.preparing-distribution-dist"), f.getAbsolutePath()));
"message.preparing-distribution-dist"), f.toAbsolutePath().toString()));
IOUtils.createXml(f.toPath(), xml -> {
IOUtils.createXml(f, xml -> {
xml.writeStartElement("installer-gui-script");
xml.writeAttribute("minSpecVersion", "1");
@ -229,14 +236,16 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
xml.writeEndElement();
xml.writeStartElement("background");
xml.writeAttribute("file", getConfig_BackgroundImage(params).getName());
xml.writeAttribute("file",
getConfig_BackgroundImage(params).getFileName().toString());
xml.writeAttribute("mime-type", "image/png");
xml.writeAttribute("alignment", "bottomleft");
xml.writeAttribute("scaling", "none");
xml.writeEndElement();
xml.writeStartElement("background-darkAqua");
xml.writeAttribute("file", getConfig_BackgroundImageDarkAqua(params).getName());
xml.writeAttribute("file",
getConfig_BackgroundImageDarkAqua(params).getFileName().toString());
xml.writeAttribute("mime-type", "image/png");
xml.writeAttribute("alignment", "bottomleft");
xml.writeAttribute("scaling", "none");
@ -244,9 +253,9 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
String licFileStr = LICENSE_FILE.fetchFrom(params);
if (licFileStr != null) {
File licFile = new File(licFileStr);
Path licFile = Path.of(licFileStr);
xml.writeStartElement("license");
xml.writeAttribute("file", licFile.getAbsolutePath());
xml.writeAttribute("file", licFile.toAbsolutePath().toString());
xml.writeAttribute("mime-type", "text/rtf");
xml.writeEndElement();
}
@ -288,7 +297,7 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
xml.writeAttribute("onConclusion", "none");
try {
xml.writeCharacters(URLEncoding(
getPackages_AppPackage(params).getName()));
getPackages_AppPackage(params).getFileName().toString()));
} catch (URISyntaxException ex) {
throw new IOException(ex);
}
@ -319,16 +328,15 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
}
// name of post-image script
private File getConfig_Script(Map<String, ? super Object> params) {
return new File(CONFIG_ROOT.fetchFrom(params),
private Path getConfig_Script(Map<String, ? super Object> params) {
return CONFIG_ROOT.fetchFrom(params).resolve(
APP_NAME.fetchFrom(params) + "-post-image.sh");
}
private void patchCPLFile(File cpl) throws IOException {
String cplData = Files.readString(cpl.toPath());
private void patchCPLFile(Path cpl) throws IOException {
String cplData = Files.readString(cpl);
String[] lines = cplData.split("\n");
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(
cpl.toPath()))) {
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(cpl))) {
int skip = 0;
// Used to skip Java.runtime bundle, since
// pkgbuild with --root will find two bundles app and Java runtime.
@ -360,35 +368,34 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
// So easy aproach will be to copy user provided app-image into temp folder
// if root path contains other files.
private String getRoot(Map<String, ? super Object> params,
File appLocation) throws IOException {
String root = appLocation.getParent() == null ?
"." : appLocation.getParent();
File rootDir = new File(root);
Path appLocation) throws IOException {
Path rootDir = appLocation.getParent() == null ?
Path.of(".") : appLocation.getParent();
File[] list = rootDir.listFiles();
Path[] list = Files.list(rootDir).toArray(Path[]::new);
if (list != null) { // Should not happend
// We should only have app image and/or .DS_Store
if (list.length == 1) {
return root;
return rootDir.toString();
} else if (list.length == 2) {
// Check case with app image and .DS_Store
if (list[0].toString().toLowerCase().endsWith(".ds_store") ||
list[1].toString().toLowerCase().endsWith(".ds_store")) {
return root; // Only app image and .DS_Store
return rootDir.toString(); // Only app image and .DS_Store
}
}
}
// Copy to new root
Path newRoot = Files.createTempDirectory(
TEMP_ROOT.fetchFrom(params).toPath(), "root-");
TEMP_ROOT.fetchFrom(params), "root-");
Path source, dest;
if (StandardBundlerParam.isRuntimeInstaller(params)) {
// firs, is this already a runtime with
// <runtime>/Contents/Home - if so we need the Home dir
Path original = appLocation.toPath();
Path original = appLocation;
Path home = original.resolve("Contents/Home");
source = (Files.exists(home)) ? home : original;
@ -396,32 +403,31 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
dest = newRoot.resolve(
MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) + "/Contents/Home");
} else {
source = appLocation.toPath();
dest = newRoot.resolve(appLocation.getName());
source = appLocation;
dest = newRoot.resolve(appLocation.getFileName());
}
IOUtils.copyRecursive(source, dest);
return newRoot.toString();
}
private File createPKG(Map<String, ? super Object> params,
File outdir, File appLocation) {
private Path createPKG(Map<String, ? super Object> params,
Path outdir, Path appLocation) {
// generic find attempt
try {
File appPKG = getPackages_AppPackage(params);
Path appPKG = getPackages_AppPackage(params);
String root = getRoot(params, appLocation);
// Generate default CPL file
File cpl = new File(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()
+ File.separator + "cpl.plist");
Path cpl = CONFIG_ROOT.fetchFrom(params).resolve("cpl.plist");
ProcessBuilder pb = new ProcessBuilder("pkgbuild",
"--root",
root,
"--install-location",
getInstallDir(params),
"--analyze",
cpl.getAbsolutePath());
cpl.toAbsolutePath().toString());
IOUtils.exec(pb);
@ -436,25 +442,25 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
"--install-location",
getInstallDir(params),
"--component-plist",
cpl.getAbsolutePath(),
cpl.toAbsolutePath().toString(),
"--scripts",
SCRIPTS_DIR.fetchFrom(params).getAbsolutePath(),
SCRIPTS_DIR.fetchFrom(params).toAbsolutePath().toString(),
"--identifier",
MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params),
appPKG.getAbsolutePath());
appPKG.toAbsolutePath().toString());
IOUtils.exec(pb);
// build final package
File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
Path finalPKG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
+ INSTALLER_SUFFIX.fetchFrom(params)
+ ".pkg");
outdir.mkdirs();
Files.createDirectories(outdir);
List<String> commandLine = new ArrayList<>();
commandLine.add("productbuild");
commandLine.add("--resources");
commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
commandLine.add(CONFIG_ROOT.fetchFrom(params).toAbsolutePath().toString());
// maybe sign
if (Optional.ofNullable(MacAppImageBuilder.
@ -482,11 +488,11 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
commandLine.add("--distribution");
commandLine.add(
getConfig_DistributionXMLFile(params).getAbsolutePath());
getConfig_DistributionXMLFile(params).toAbsolutePath().toString());
commandLine.add("--package-path");
commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath());
commandLine.add(PACKAGES_ROOT.fetchFrom(params).toAbsolutePath().toString());
commandLine.add(finalPKG.getAbsolutePath());
commandLine.add(finalPKG.toAbsolutePath().toString());
pb = new ProcessBuilder(commandLine);
IOUtils.exec(pb);
@ -577,8 +583,8 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
}
@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
return bundle(params, outputParentDir);
}

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
@ -79,7 +78,7 @@ public abstract class AbstractAppImageBuilder {
}
public static OverridableResource createIconResource(String defaultIconName,
BundlerParamInfo<File> iconParam, Map<String, ? super Object> params,
BundlerParamInfo<Path> iconParam, Map<String, ? super Object> params,
Map<String, ? super Object> mainParams) throws IOException {
if (mainParams != null) {
@ -119,12 +118,12 @@ public abstract class AbstractAppImageBuilder {
private enum IconType { DefaultOrResourceDirIcon, CustomIcon, NoIcon };
private static IconType getLauncherIconType(Map<String, ? super Object> params) {
File launcherIcon = ICON.fetchFrom(params);
Path launcherIcon = ICON.fetchFrom(params);
if (launcherIcon == null) {
return IconType.DefaultOrResourceDirIcon;
}
if (launcherIcon.getName().isEmpty()) {
if (launcherIcon.toFile().getName().isEmpty()) {
return IconType.NoIcon;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,8 +25,8 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
@ -39,12 +39,12 @@ import java.util.Map;
*/
abstract class AbstractBundler implements Bundler {
static final BundlerParamInfo<File> IMAGES_ROOT =
static final BundlerParamInfo<Path> IMAGES_ROOT =
new StandardBundlerParam<>(
"imagesRoot",
File.class,
params -> new File(
StandardBundlerParam.TEMP_ROOT.fetchFrom(params), "images"),
Path.class,
params ->
StandardBundlerParam.TEMP_ROOT.fetchFrom(params).resolve("images"),
(s, p) -> null);
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,9 @@
package jdk.incubator.jpackage.internal;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.util.List;
import jdk.incubator.jpackage.internal.Arguments.CLIOptions;
@ -116,7 +116,7 @@ class AddLauncherArguments {
String value = getOptionValue(CLIOptions.ICON);
Arguments.putUnlessNull(bundleParams, CLIOptions.ICON.getId(),
(value == null) ? null : new File(value));
(value == null) ? null : Path.of(value));
// "arguments" and "java-options" even if value is null:
if (allArgs.containsKey(CLIOptions.ARGUMENTS.getId())) {

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -82,14 +81,14 @@ class AppImageBundler extends AbstractBundler {
}
@Override
final public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
final public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
if (StandardBundlerParam.isRuntimeInstaller(params)) {
return PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
}
try {
return createAppBundle(params, outputParentDir.toPath()).toFile();
return createAppBundle(params, outputParentDir);
} catch (PackagerException pe) {
throw pe;
} catch (RuntimeException|IOException|ConfigException ex) {

View File

@ -24,8 +24,8 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -192,7 +192,7 @@ public class AppImageFile {
"http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);
DocumentBuilder b = dbf.newDocumentBuilder();
return b.parse(new FileInputStream(path.toFile()));
return b.parse(Files.newInputStream(path));
} catch (ParserConfigurationException | SAXException ex) {
// Let caller sort this out
throw new IOException(ex);

View File

@ -24,9 +24,10 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -89,7 +90,7 @@ public class Arguments {
private List<CLIOptions> allOptions = null;
private String input = null;
private String output = null;
private Path output = null;
private boolean hasMainJar = false;
private boolean hasMainClass = false;
@ -130,8 +131,8 @@ public class Arguments {
addLaunchers = new ArrayList<>();
output = Paths.get("").toAbsolutePath().toString();
deployParams.setOutput(new File(output));
output = Paths.get("").toAbsolutePath();
deployParams.setOutput(output);
}
// CLIOptions is public for DeployParamsTest
@ -146,8 +147,8 @@ public class Arguments {
}),
OUTPUT ("dest", "d", OptionCategories.PROPERTY, () -> {
context().output = popArg();
context().deployParams.setOutput(new File(context().output));
context().output = Path.of(popArg());
context().deployParams.setOutput(context().output);
}),
DESCRIPTION ("description", OptionCategories.PROPERTY),
@ -670,7 +671,7 @@ public class Arguments {
Map<String, ? super Object> localParams = new HashMap<>(params);
try {
bundler.validate(localParams);
File result = bundler.execute(localParams, deployParams.outdir);
Path result = bundler.execute(localParams, deployParams.outdir);
if (result == null) {
throw new PackagerException("MSG_BundlerFailed",
bundler.getID(), bundler.getName());
@ -696,7 +697,7 @@ public class Arguments {
if (userProvidedBuildRoot) {
Log.verbose(MessageFormat.format(
I18N.getString("message.debug-working-directory"),
(new File(buildRoot)).getAbsolutePath()));
(Path.of(buildRoot)).toAbsolutePath().toString()));
} else {
// always clean up the temporary directory created
// when --temp option not used.
@ -716,10 +717,9 @@ public class Arguments {
static Map<String, String> getPropertiesFromFile(String filename) {
Map<String, String> map = new HashMap<>();
// load properties file
File file = new File(filename);
Properties properties = new Properties();
try (FileInputStream in = new FileInputStream(file)) {
properties.load(in);
try (Reader reader = Files.newBufferedReader(Path.of(filename))) {
properties.load(reader);
} catch (IOException e) {
Log.error("Exception: " + e.getMessage());
}
@ -808,11 +808,11 @@ public class Arguments {
JarFile jf;
try {
File file = new File(input, mainJarPath);
if (!file.exists()) {
Path file = Path.of(input, mainJarPath);
if (!Files.exists(file)) {
return null;
}
jf = new JarFile(file);
jf = new JarFile(file.toFile());
Manifest m = jf.getManifest();
Attributes attrs = (m != null) ? m.getMainAttributes() : null;
if (attrs != null) {

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.util.HashMap;
import java.util.Map;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.APP_NAME;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.nio.file.Path;
import java.util.Map;
/**
@ -104,8 +104,8 @@ public interface Bundler {
* forward slashes.</li>
* </ul>
*/
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException;
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException;
/**
* Removes temporary files that are used for bundling.

View File

@ -26,6 +26,7 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.InvalidPathException;
@ -37,6 +38,8 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* DeployParams
@ -48,20 +51,20 @@ public class DeployParams {
String targetFormat = null; // means default type for this platform
File outdir = null;
Path outdir = null;
// raw arguments to the bundler
Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
public void setOutput(File output) {
public void setOutput(Path output) {
outdir = output;
}
static class Template {
File in;
File out;
Path in;
Path out;
Template(File in, File out) {
Template(Path in, Path out) {
this.in = in;
this.out = out;
}
@ -72,15 +75,19 @@ public class DeployParams {
// we may get "." as filename and assumption is we include
// everything in the given folder
// (IOUtils.copyfiles() have recursive behavior)
List<File> expandFileset(File root) {
List<File> files = new LinkedList<>();
if (!Files.isSymbolicLink(root.toPath())) {
if (root.isDirectory()) {
File[] children = root.listFiles();
if (children != null && children.length > 0) {
for (File f : children) {
files.addAll(expandFileset(f));
}
List<Path> expandFileset(Path root) throws IOException {
List<Path> files = new LinkedList<>();
if (!Files.isSymbolicLink(root)) {
if (Files.isDirectory(root)) {
List<Path> children = Files.list(root).collect(Collectors.toList());
if (children != null && children.size() > 0) {
children.forEach(f -> {
try {
files.addAll(expandFileset(f));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
} else {
// Include empty folders
files.add(root);
@ -110,7 +117,7 @@ public class DeployParams {
}
try {
// name must be valid path element for this file system
Path p = (new File(s)).toPath();
Path p = Path.of(s);
// and it must be a single name element in a path
if (p.getNameCount() != 1) {
throw new PackagerException(exceptionKey, s);
@ -198,8 +205,8 @@ public class DeployParams {
String appImage = (String)bundlerArguments.get(
Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
if (appImage != null) {
File appImageDir = new File(appImage);
if (!appImageDir.exists() || appImageDir.list().length == 0) {
Path appImageDir = Path.of(appImage);
if (!Files.exists(appImageDir) || appImageDir.toFile().list().length == 0) {
throw new PackagerException("ERR_AppImageNotExist", appImage);
}
}
@ -208,10 +215,15 @@ public class DeployParams {
String root = (String)bundlerArguments.get(
Arguments.CLIOptions.TEMP_ROOT.getId());
if (root != null) {
String [] contents = (new File(root)).list();
try {
String [] contents = Files.list(Path.of(root))
.toArray(String[]::new);
if (contents != null && contents.length > 0) {
throw new PackagerException("ERR_BuildRootInvalid", root);
if (contents != null && contents.length > 0) {
throw new PackagerException("ERR_BuildRootInvalid", root);
}
} catch (IOException ioe) {
throw new PackagerException(ioe);
}
}
@ -219,7 +231,7 @@ public class DeployParams {
String resources = (String)bundlerArguments.get(
Arguments.CLIOptions.RESOURCE_DIR.getId());
if (resources != null) {
if (!(new File(resources)).exists()) {
if (!(Files.exists(Path.of(resources)))) {
throw new PackagerException(
"message.resource-dir-does-not-exist",
Arguments.CLIOptions.RESOURCE_DIR.getId(), resources);
@ -230,7 +242,7 @@ public class DeployParams {
String runtime = (String)bundlerArguments.get(
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId());
if (runtime != null) {
if (!(new File(runtime)).exists()) {
if (!(Files.exists(Path.of(runtime)))) {
throw new PackagerException(
"message.runtime-image-dir-does-not-exist",
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
@ -243,8 +255,7 @@ public class DeployParams {
String license = (String)bundlerArguments.get(
Arguments.CLIOptions.LICENSE_FILE.getId());
if (license != null) {
File licenseFile = new File(license);
if (!licenseFile.exists()) {
if (!(Files.exists(Path.of(license)))) {
throw new PackagerException("ERR_LicenseFileNotExit");
}
}
@ -253,10 +264,9 @@ public class DeployParams {
String icon = (String)bundlerArguments.get(
Arguments.CLIOptions.ICON.getId());
if (icon != null) {
File iconFile = new File(icon);
if (!iconFile.exists()) {
if (!(Files.exists(Path.of(icon)))) {
throw new PackagerException("ERR_IconFileNotExit",
iconFile.getAbsolutePath());
Path.of(icon).toAbsolutePath().toString());
}
}
}

View File

@ -25,10 +25,10 @@
package jdk.incubator.jpackage.internal;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
@ -82,12 +82,12 @@ final public class Executor {
output = null;
boolean needProcessOutput = outputConsumer != null || Log.isVerbose() || saveOutput;
File outputFile = null;
Path outputFile = null;
if (needProcessOutput) {
pb.redirectErrorStream(true);
if (writeOutputToFile) {
outputFile = File.createTempFile("jpackageOutputTempFile", ".tmp");
pb.redirectOutput(outputFile);
outputFile = Files.createTempFile("jpackageOutputTempFile", ".tmp");
pb.redirectOutput(outputFile.toFile());
}
} else {
// We are not going to read process output, so need to notify
@ -115,8 +115,8 @@ final public class Executor {
Supplier<Stream<String>> outputStream;
if (writeOutputToFile) {
savedOutput = Files.readAllLines(outputFile.toPath());
outputFile.delete();
savedOutput = Files.readAllLines(outputFile);
Files.delete(outputFile);
outputStream = () -> {
if (savedOutput != null) {
return savedOutput.stream();

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Collections;
@ -86,9 +85,9 @@ final class FileAssociation {
assoc.mimeTypes = Optional.ofNullable(
FA_CONTENT_TYPE.fetchFrom(fa)).orElse(Collections.emptyList());
File icon = FA_ICON.fetchFrom(fa);
Path icon = FA_ICON.fetchFrom(fa);
if (icon != null) {
assoc.iconPath = icon.toPath();
assoc.iconPath = icon;
}
return assoc;

View File

@ -28,7 +28,6 @@ package jdk.incubator.jpackage.internal;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.File;
import java.io.PrintStream;
import java.io.Writer;
import java.lang.reflect.InvocationHandler;
@ -56,11 +55,11 @@ import javax.xml.stream.XMLStreamWriter;
*/
public class IOUtils {
public static void deleteRecursive(File path) throws IOException {
if (!path.exists()) {
public static void deleteRecursive(Path directory) throws IOException {
if (!Files.exists(directory)) {
return;
}
Path directory = path.toPath();
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
@ -119,22 +118,30 @@ public class IOUtils {
});
}
public static void copyFile(File sourceFile, File destFile)
public static void copyFile(Path sourceFile, Path destFile)
throws IOException {
Files.createDirectories(destFile.getParentFile().toPath());
Files.createDirectories(destFile.getParent());
Files.copy(sourceFile.toPath(), destFile.toPath(),
Files.copy(sourceFile, destFile,
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
}
public static boolean exists(Path path) {
if (path == null) {
return false;
}
return Files.exists(path);
}
// run "launcher paramfile" in the directory where paramfile is kept
public static void run(String launcher, File paramFile)
public static void run(String launcher, Path paramFile)
throws IOException {
if (paramFile != null && paramFile.exists()) {
if (IOUtils.exists(paramFile)) {
ProcessBuilder pb =
new ProcessBuilder(launcher, paramFile.getName());
pb = pb.directory(paramFile.getParentFile());
new ProcessBuilder(launcher, paramFile.getFileName().toString());
pb = pb.directory(paramFile.getParent().toFile());
exec(pb);
}
}
@ -222,15 +229,18 @@ public class IOUtils {
}
static void writableOutputDir(Path outdir) throws PackagerException {
File file = outdir.toFile();
if (!file.isDirectory() && !file.mkdirs()) {
throw new PackagerException("error.cannot-create-output-dir",
file.getAbsolutePath());
if (!Files.isDirectory(outdir)) {
try {
Files.createDirectories(outdir);
} catch (IOException ex) {
throw new PackagerException("error.cannot-create-output-dir",
outdir.toAbsolutePath().toString());
}
}
if (!file.canWrite()) {
if (!Files.isWritable(outdir)) {
throw new PackagerException("error.cannot-write-to-output-dir",
file.getAbsolutePath());
outdir.toAbsolutePath().toString());
}
}

View File

@ -145,7 +145,7 @@ final class LauncherData {
// Failed to find module in the specified module path list and
// there is external runtime given to jpackage.
// Lookup module in this runtime.
Path cookedRuntime = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params).toPath();
Path cookedRuntime = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
launcherData.moduleInfo = ModuleInfo.fromCookedRuntime(moduleName,
cookedRuntime);
}
@ -293,7 +293,7 @@ final class LauncherData {
List<Path> modulePath = getPathListParameter(Arguments.CLIOptions.MODULE_PATH.getId(), params);
if (params.containsKey(PREDEFINED_RUNTIME_IMAGE.getID())) {
Path runtimePath = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params).toPath();
Path runtimePath = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
runtimePath = runtimePath.resolve("lib");
modulePath = Stream.of(modulePath, List.of(runtimePath))
.flatMap(List::stream)

View File

@ -24,7 +24,6 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -200,7 +199,7 @@ final class PathGroup {
for (var action: entries) {
Path src = action.getKey();
Path dst = action.getValue();
if (src.toFile().isDirectory()) {
if (Files.isDirectory(src)) {
try (Stream<Path> stream = Files.walk(src)) {
stream.sequential().forEach(path -> actions.put(dst.resolve(
src.relativize(path)).normalize(), path));
@ -222,7 +221,7 @@ final class PathGroup {
continue;
}
if (src.toFile().isDirectory()) {
if (Files.isDirectory(src)) {
handler.createDirectory(dst);
} else {
handler.copyFile(src, dst);
@ -232,8 +231,8 @@ final class PathGroup {
if (move) {
// Delete source dirs.
for (var entry: entries) {
File srcFile = entry.getKey().toFile();
if (srcFile.isDirectory()) {
Path srcFile = entry.getKey();
if (Files.isDirectory(srcFile)) {
IOUtils.deleteRecursive(srcFile);
}
}

View File

@ -76,7 +76,7 @@ class ScriptRunner {
public void run(Map<String, ? super Object> params) throws IOException {
String scriptName = String.format("%s-%s%s", APP_NAME.fetchFrom(params),
scriptNameSuffix, scriptSuffix());
Path scriptPath = CONFIG_ROOT.fetchFrom(params).toPath().resolve(
Path scriptPath = CONFIG_ROOT.fetchFrom(params).resolve(
scriptName);
createResource(null, params)
.setCategory(I18N.getString(resourceCategoryId))

View File

@ -120,12 +120,12 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(s, p) -> s
);
static final StandardBundlerParam<File> PREDEFINED_RUNTIME_IMAGE =
static final StandardBundlerParam<Path> PREDEFINED_RUNTIME_IMAGE =
new StandardBundlerParam<>(
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
File.class,
Path.class,
params -> null,
(s, p) -> new File(s)
(s, p) -> Path.of(s)
);
static final StandardBundlerParam<String> APP_NAME =
@ -141,9 +141,9 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
}
return s;
} else if (isRuntimeInstaller(params)) {
File f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
Path f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
if (f != null) {
return f.getName();
return f.getFileName().toString();
}
}
return null;
@ -151,12 +151,12 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(s, p) -> s
);
static final StandardBundlerParam<File> ICON =
static final StandardBundlerParam<Path> ICON =
new StandardBundlerParam<>(
Arguments.CLIOptions.ICON.getId(),
File.class,
Path.class,
params -> null,
(s, p) -> new File(s)
(s, p) -> Path.of(s)
);
static final StandardBundlerParam<String> VENDOR =
@ -229,29 +229,31 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(s, p) -> s
);
static final StandardBundlerParam<File> TEMP_ROOT =
static final StandardBundlerParam<Path> TEMP_ROOT =
new StandardBundlerParam<>(
Arguments.CLIOptions.TEMP_ROOT.getId(),
File.class,
Path.class,
params -> {
try {
return Files.createTempDirectory(
"jdk.incubator.jpackage").toFile();
return Files.createTempDirectory("jdk.incubator.jpackage");
} catch (IOException ioe) {
return null;
}
},
(s, p) -> new File(s)
(s, p) -> Path.of(s)
);
public static final StandardBundlerParam<File> CONFIG_ROOT =
public static final StandardBundlerParam<Path> CONFIG_ROOT =
new StandardBundlerParam<>(
"configRoot",
File.class,
Path.class,
params -> {
File root =
new File(TEMP_ROOT.fetchFrom(params), "config");
root.mkdirs();
Path root = TEMP_ROOT.fetchFrom(params).resolve("config");
try {
Files.createDirectories(root);
} catch (IOException ioe) {
return null;
}
return root;
},
(s, p) -> null
@ -277,12 +279,12 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
true : Boolean.valueOf(s)
);
static final StandardBundlerParam<File> RESOURCE_DIR =
static final StandardBundlerParam<Path> RESOURCE_DIR =
new StandardBundlerParam<>(
Arguments.CLIOptions.RESOURCE_DIR.getId(),
File.class,
Path.class,
params -> null,
(s, p) -> new File(s)
(s, p) -> Path.of(s)
);
static final BundlerParamInfo<String> INSTALL_DIR =
@ -293,12 +295,12 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(s, p) -> s
);
static final StandardBundlerParam<File> PREDEFINED_APP_IMAGE =
static final StandardBundlerParam<Path> PREDEFINED_APP_IMAGE =
new StandardBundlerParam<>(
Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
File.class,
Path.class,
params -> null,
(s, p) -> new File(s));
(s, p) -> Path.of(s));
@SuppressWarnings("unchecked")
static final StandardBundlerParam<List<Map<String, ? super Object>>> ADD_LAUNCHERS =
@ -346,16 +348,16 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
new StandardBundlerParam<>(
"fileAssociation.description",
String.class,
params -> APP_NAME.fetchFrom(params) + " File",
params -> APP_NAME.fetchFrom(params) + " Path",
null
);
static final StandardBundlerParam<File> FA_ICON =
static final StandardBundlerParam<Path> FA_ICON =
new StandardBundlerParam<>(
"fileAssociation.icon",
File.class,
Path.class,
ICON::fetchFrom,
(s, p) -> new File(s)
(s, p) -> Path.of(s)
);
@SuppressWarnings("unchecked")
@ -449,9 +451,9 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
return params.containsKey(PREDEFINED_RUNTIME_IMAGE.getID());
}
static File getPredefinedAppImage(Map<String, ? super Object> params) {
File applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
if (applicationImage != null && !applicationImage.exists()) {
static Path getPredefinedAppImage(Map<String, ? super Object> params) {
Path applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
if (applicationImage != null && !IOUtils.exists(applicationImage)) {
throw new RuntimeException(
MessageFormat.format(I18N.getString(
"message.app-image-dir-does-not-exist"),
@ -463,8 +465,8 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
static void copyPredefinedRuntimeImage(Map<String, ? super Object> params,
ApplicationLayout appLayout) throws IOException, ConfigException {
File topImage = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
if (!topImage.exists()) {
Path topImage = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
if (!IOUtils.exists(topImage)) {
throw new ConfigException(
MessageFormat.format(I18N.getString(
"message.runtime-image-dir-does-not-exist"),
@ -477,17 +479,17 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
if (Platform.isMac()) {
// On Mac topImage can be runtime root or runtime home.
Path runtimeHome = topImage.toPath().resolve("Contents/Home");
Path runtimeHome = topImage.resolve("Contents/Home");
if (Files.isDirectory(runtimeHome)) {
// topImage references runtime root, adjust it to pick data from
// runtime home
topImage = runtimeHome.toFile();
topImage = runtimeHome;
}
}
// copy whole runtime, need to skip jmods and src.zip
final List<String> excludes = Arrays.asList("jmods", "src.zip");
IOUtils.copyRecursive(topImage.toPath(),
IOUtils.copyRecursive(topImage,
appLayout.runtimeHomeDirectory(), excludes);
// if module-path given - copy modules to appDir/mods

View File

@ -108,7 +108,8 @@ final class ExecutableRebrander {
private void rebrandExecutable(Map<String, ? super Object> params,
Path target, UpdateResourceAction action) throws IOException {
try {
String tempDirectory = TEMP_ROOT.fetchFrom(params).getAbsolutePath();
String tempDirectory = TEMP_ROOT.fetchFrom(params)
.toAbsolutePath().toString();
if (WindowsDefender.isThereAPotentialWindowsDefenderIssue(
tempDirectory)) {
Log.verbose(MessageFormat.format(I18N.getString(

View File

@ -24,12 +24,10 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Map;
@ -39,16 +37,20 @@ public class WinExeBundler extends AbstractBundler {
System.loadLibrary("jpackage");
}
public static final BundlerParamInfo<File> EXE_IMAGE_DIR
public static final BundlerParamInfo<Path> EXE_IMAGE_DIR
= new StandardBundlerParam<>(
"win.exe.imageDir",
File.class,
Path.class,
params -> {
File imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!imagesRoot.exists()) {
imagesRoot.mkdirs();
Path imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!Files.exists(imagesRoot)) {
try {
Files.createDirectories(imagesRoot);
} catch (IOException ioe) {
return null;
}
}
return new File(imagesRoot, "win-exe.image");
return imagesRoot.resolve("win-exe.image");
},
(s, p) -> null);
@ -70,8 +72,8 @@ public class WinExeBundler extends AbstractBundler {
}
@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
return bundle(params, outputParentDir);
}
@ -91,22 +93,22 @@ public class WinExeBundler extends AbstractBundler {
return msiBundler.validate(params);
}
public File bundle(Map<String, ? super Object> params, File outdir)
public Path bundle(Map<String, ? super Object> params, Path outdir)
throws PackagerException {
IOUtils.writableOutputDir(outdir.toPath());
IOUtils.writableOutputDir(outdir);
File exeImageDir = EXE_IMAGE_DIR.fetchFrom(params);
Path exeImageDir = EXE_IMAGE_DIR.fetchFrom(params);
// Write msi to temporary directory.
File msi = msiBundler.execute(params, exeImageDir);
Path msi = msiBundler.execute(params, exeImageDir);
try {
new ScriptRunner()
.setDirectory(msi.toPath().getParent())
.setDirectory(msi.getParent())
.setResourceCategoryId("resource.post-msi-script")
.setScriptNameSuffix("post-msi")
.setEnvironmentVariable("JpMsiFile", msi.getAbsolutePath().toString())
.setEnvironmentVariable("JpMsiFile", msi.toAbsolutePath().toString())
.run(params);
return buildEXE(params, msi, outdir);
@ -116,35 +118,34 @@ public class WinExeBundler extends AbstractBundler {
}
}
private File buildEXE(Map<String, ? super Object> params, File msi,
File outdir) throws IOException {
private Path buildEXE(Map<String, ? super Object> params, Path msi,
Path outdir) throws IOException {
Log.verbose(MessageFormat.format(
I18N.getString("message.outputting-to-location"),
outdir.getAbsolutePath()));
outdir.toAbsolutePath().toString()));
// Copy template msi wrapper next to msi file
final Path exePath = IOUtils.replaceSuffix(msi.toPath(), ".exe");
final Path exePath = IOUtils.replaceSuffix(msi, ".exe");
try (InputStream is = OverridableResource.readDefault(EXE_WRAPPER_NAME)) {
Files.copy(is, exePath);
}
new ExecutableRebrander().addAction((resourceLock) -> {
// Embed msi in msi wrapper exe.
embedMSI(resourceLock, msi.getAbsolutePath());
embedMSI(resourceLock, msi.toAbsolutePath().toString());
}).rebrandInstaller(params, exePath);
Path dstExePath = Paths.get(outdir.getAbsolutePath(),
exePath.getFileName().toString());
Path dstExePath = outdir.toAbsolutePath().resolve(exePath.getFileName());
Files.deleteIfExists(dstExePath);
Files.copy(exePath, dstExePath);
Log.verbose(MessageFormat.format(
I18N.getString("message.output-location"),
outdir.getAbsolutePath()));
outdir.toAbsolutePath().toString()));
return dstExePath.toFile();
return dstExePath;
}
private final WinMsiBundler msiBundler = new WinMsiBundler();

View File

@ -25,8 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@ -101,21 +99,27 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.VERSION;
*/
public class WinMsiBundler extends AbstractBundler {
public static final BundlerParamInfo<File> MSI_IMAGE_DIR =
public static final BundlerParamInfo<Path> MSI_IMAGE_DIR =
new StandardBundlerParam<>(
"win.msi.imageDir",
File.class,
Path.class,
params -> {
File imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!imagesRoot.exists()) imagesRoot.mkdirs();
return new File(imagesRoot, "win-msi.image");
Path imagesRoot = IMAGES_ROOT.fetchFrom(params);
if (!Files.exists(imagesRoot)) {
try {
Files.createDirectories(imagesRoot);
} catch (IOException ioe) {
return null;
}
}
return imagesRoot.resolve("win-msi.image");
},
(s, p) -> null);
public static final BundlerParamInfo<File> WIN_APP_IMAGE =
public static final BundlerParamInfo<Path> WIN_APP_IMAGE =
new StandardBundlerParam<>(
"win.app.image",
File.class,
Path.class,
null,
(s, p) -> null);
@ -284,15 +288,14 @@ public class WinMsiBundler extends AbstractBundler {
private void prepareProto(Map<String, ? super Object> params)
throws PackagerException, IOException {
File appImage = StandardBundlerParam.getPredefinedAppImage(params);
File appDir = null;
Path appImage = StandardBundlerParam.getPredefinedAppImage(params);
Path appDir;
// we either have an application image or need to build one
if (appImage != null) {
appDir = new File(MSI_IMAGE_DIR.fetchFrom(params),
APP_NAME.fetchFrom(params));
appDir = MSI_IMAGE_DIR.fetchFrom(params).resolve(APP_NAME.fetchFrom(params));
// copy everything from appImage dir into appDir/name
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
IOUtils.copyRecursive(appImage, appDir);
} else {
appDir = appImageBundler.execute(params, MSI_IMAGE_DIR.fetchFrom(
params));
@ -305,12 +308,12 @@ public class WinMsiBundler extends AbstractBundler {
// Ignore custom icon if any as we don't want to copy anything in
// Java Runtime image.
installerIcon = ApplicationLayout.javaRuntime()
.resolveAt(appDir.toPath())
.resolveAt(appDir)
.runtimeDirectory()
.resolve(Path.of("bin", "java.exe"));
} else {
installerIcon = ApplicationLayout.windowsAppImage()
.resolveAt(appDir.toPath())
.resolveAt(appDir)
.launchersDirectory()
.resolve(APP_NAME.fetchFrom(params) + ".exe");
}
@ -322,31 +325,31 @@ public class WinMsiBundler extends AbstractBundler {
if (licenseFile != null) {
// need to copy license file to the working directory
// and convert to rtf if needed
File lfile = new File(licenseFile);
File destFile = new File(CONFIG_ROOT.fetchFrom(params),
lfile.getName());
Path lfile = Path.of(licenseFile);
Path destFile = CONFIG_ROOT.fetchFrom(params)
.resolve(lfile.getFileName());
IOUtils.copyFile(lfile, destFile);
destFile.setWritable(true);
destFile.toFile().setWritable(true);
ensureByMutationFileIsRTF(destFile);
}
}
@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
public Path execute(Map<String, ? super Object> params,
Path outputParentDir) throws PackagerException {
IOUtils.writableOutputDir(outputParentDir.toPath());
IOUtils.writableOutputDir(outputParentDir);
Path imageDir = MSI_IMAGE_DIR.fetchFrom(params).toPath();
Path imageDir = MSI_IMAGE_DIR.fetchFrom(params);
try {
Files.createDirectories(imageDir);
prepareProto(params);
wixSourcesBuilder
.initFromParams(WIN_APP_IMAGE.fetchFrom(params).toPath(), params)
.createMainFragment(CONFIG_ROOT.fetchFrom(params).toPath().resolve(
.initFromParams(WIN_APP_IMAGE.fetchFrom(params), params)
.createMainFragment(CONFIG_ROOT.fetchFrom(params).resolve(
"bundle.wxf"));
Map<String, String> wixVars = prepareMainProjectFile(params);
@ -389,7 +392,7 @@ public class WinMsiBundler extends AbstractBundler {
data.put("JpAppVersion", PRODUCT_VERSION.fetchFrom(params));
data.put("JpIcon", installerIcon.toString());
final Path configDir = CONFIG_ROOT.fetchFrom(params).toPath();
final Path configDir = CONFIG_ROOT.fetchFrom(params);
data.put("JpConfigDir", configDir.toAbsolutePath().toString());
@ -399,9 +402,9 @@ public class WinMsiBundler extends AbstractBundler {
String licenseFile = LICENSE_FILE.fetchFrom(params);
if (licenseFile != null) {
String lname = new File(licenseFile).getName();
File destFile = new File(CONFIG_ROOT.fetchFrom(params), lname);
data.put("JpLicenseRtf", destFile.getAbsolutePath());
String lname = Path.of(licenseFile).getFileName().toString();
Path destFile = CONFIG_ROOT.fetchFrom(params).resolve(lname);
data.put("JpLicenseRtf", destFile.toAbsolutePath().toString());
}
// Copy CA dll to include with installer
@ -409,9 +412,7 @@ public class WinMsiBundler extends AbstractBundler {
data.put("JpInstallDirChooser", "yes");
String fname = "wixhelper.dll";
try (InputStream is = OverridableResource.readDefault(fname)) {
Files.copy(is, Paths.get(
CONFIG_ROOT.fetchFrom(params).getAbsolutePath(),
fname));
Files.copy(is, CONFIG_ROOT.fetchFrom(params).resolve(fname));
}
}
@ -419,9 +420,7 @@ public class WinMsiBundler extends AbstractBundler {
for (String loc : Arrays.asList("en", "ja", "zh_CN")) {
String fname = "MsiInstallerStrings_" + loc + ".wxl";
try (InputStream is = OverridableResource.readDefault(fname)) {
Files.copy(is, Paths.get(
CONFIG_ROOT.fetchFrom(params).getAbsolutePath(),
fname));
Files.copy(is, CONFIG_ROOT.fetchFrom(params).resolve(fname));
}
}
@ -436,28 +435,28 @@ public class WinMsiBundler extends AbstractBundler {
return data;
}
private File buildMSI(Map<String, ? super Object> params,
Map<String, String> wixVars, File outdir)
private Path buildMSI(Map<String, ? super Object> params,
Map<String, String> wixVars, Path outdir)
throws IOException {
File msiOut = new File(
outdir, INSTALLER_FILE_NAME.fetchFrom(params) + ".msi");
Path msiOut = outdir.resolve(INSTALLER_FILE_NAME.fetchFrom(params) + ".msi");
Log.verbose(MessageFormat.format(I18N.getString(
"message.preparing-msi-config"), msiOut.getAbsolutePath()));
"message.preparing-msi-config"), msiOut.toAbsolutePath()
.toString()));
WixPipeline wixPipeline = new WixPipeline()
.setToolset(wixToolset.entrySet().stream().collect(
Collectors.toMap(
entry -> entry.getKey(),
entry -> entry.getValue().path)))
.setWixObjDir(TEMP_ROOT.fetchFrom(params).toPath().resolve("wixobj"))
.setWorkDir(WIN_APP_IMAGE.fetchFrom(params).toPath())
.addSource(CONFIG_ROOT.fetchFrom(params).toPath().resolve("main.wxs"), wixVars)
.addSource(CONFIG_ROOT.fetchFrom(params).toPath().resolve("bundle.wxf"), null);
.setWixObjDir(TEMP_ROOT.fetchFrom(params).resolve("wixobj"))
.setWorkDir(WIN_APP_IMAGE.fetchFrom(params))
.addSource(CONFIG_ROOT.fetchFrom(params).resolve("main.wxs"), wixVars)
.addSource(CONFIG_ROOT.fetchFrom(params).resolve("bundle.wxf"), null);
Log.verbose(MessageFormat.format(I18N.getString(
"message.generating-msi"), msiOut.getAbsolutePath()));
"message.generating-msi"), msiOut.toAbsolutePath().toString()));
boolean enableLicenseUI = (LICENSE_FILE.fetchFrom(params) != null);
boolean enableInstalldirUI = INSTALLDIR_CHOOSER.fetchFrom(params);
@ -472,26 +471,27 @@ public class WinMsiBundler extends AbstractBundler {
}
wixPipeline.addLightOptions("-loc",
CONFIG_ROOT.fetchFrom(params).toPath().resolve(I18N.getString(
CONFIG_ROOT.fetchFrom(params).resolve(I18N.getString(
"resource.wxl-file-name")).toAbsolutePath().toString());
// Only needed if we using CA dll, so Wix can find it
if (enableInstalldirUI) {
wixPipeline.addLightOptions("-b", CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
wixPipeline.addLightOptions("-b", CONFIG_ROOT.fetchFrom(params)
.toAbsolutePath().toString());
}
wixPipeline.buildMsi(msiOut.toPath().toAbsolutePath());
wixPipeline.buildMsi(msiOut.toAbsolutePath());
return msiOut;
}
private static void ensureByMutationFileIsRTF(File f) {
if (f == null || !f.isFile()) return;
private static void ensureByMutationFileIsRTF(Path f) {
if (f == null || !Files.isRegularFile(f)) return;
try {
boolean existingLicenseIsRTF = false;
try (FileInputStream fin = new FileInputStream(f)) {
try (InputStream fin = Files.newInputStream(f)) {
byte[] firstBits = new byte[7];
if (fin.read(firstBits) == firstBits.length) {
@ -501,9 +501,9 @@ public class WinMsiBundler extends AbstractBundler {
}
if (!existingLicenseIsRTF) {
List<String> oldLicense = Files.readAllLines(f.toPath());
List<String> oldLicense = Files.readAllLines(f);
try (Writer w = Files.newBufferedWriter(
f.toPath(), Charset.forName("Windows-1252"))) {
f, Charset.forName("Windows-1252"))) {
w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033"
+ "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n"
+ "\\viewkind4\\uc1\\pard\\sa200\\sl276"

View File

@ -25,7 +25,6 @@
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@ -45,20 +44,21 @@ public class WindowsAppImageBuilder extends AbstractAppImageBuilder {
private static final String TEMPLATE_APP_ICON ="java48.ico";
public static final BundlerParamInfo<File> ICON_ICO =
public static final BundlerParamInfo<Path> ICON_ICO =
new StandardBundlerParam<>(
"icon.ico",
File.class,
Path.class,
params -> {
File f = ICON.fetchFrom(params);
if (f != null && !f.getName().toLowerCase().endsWith(".ico")) {
Path f = ICON.fetchFrom(params);
if (f != null && f.getFileName() != null && !f.getFileName()
.toString().toLowerCase().endsWith(".ico")) {
Log.error(MessageFormat.format(
I18N.getString("message.icon-not-ico"), f));
return null;
}
return f;
},
(s, p) -> new File(s));
(s, p) -> Path.of(s));
public static final StandardBundlerParam<Boolean> CONSOLE_HINT =
new StandardBundlerParam<>(

View File

@ -28,6 +28,7 @@ package jdk.incubator.jpackage.internal;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
@ -160,7 +161,7 @@ class WixSourcesBuilder {
fa.launcherPath = addExeSuffixToPath(
installedAppImage.launchersDirectory().resolve(fa.launcherPath));
if (fa.iconPath != null && !fa.iconPath.toFile().exists()) {
if (fa.iconPath != null && !Files.exists(fa.iconPath)) {
fa.iconPath = null;
}

View File

@ -84,7 +84,7 @@ public enum WixTool {
for (var dir : findWixInstallDirs()) {
Path path = dir.resolve(toolFileName);
if (path.toFile().exists()) {
if (Files.exists(path)) {
reason = createToolValidator(path, version).get();
if (reason != null) {
throw reason;

View File

@ -22,7 +22,7 @@
*/
package jdk.incubator.jpackage.internal;
import java.io.File;
import java.nio.file.Path;
import java.io.IOException;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
@ -45,7 +45,7 @@ public class DeployParamsTest {
@Before
public void setUp() throws IOException {
testRoot = tempFolder.newFolder();
testRoot = tempFolder.newFolder().toPath();
}
@Test
@ -131,6 +131,6 @@ public class DeployParamsTest {
params.validate();
}
private File testRoot = null;
private Path testRoot = null;
private DeployParams params;
}