Skip to content
Permalink
Browse files

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

…s APIs

Reviewed-by: herrick, asemenyuk
  • Loading branch information
Alexander Matveev committed Jul 7, 2020
1 parent c782d0e commit ed05d5760306a8af0d783d1016959d5359afe6a7
Showing with 537 additions and 514 deletions.
  1. +2 −2 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java
  2. +6 −6 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxAppImageBuilder.java
  3. +21 −22 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxDebBundler.java
  4. +13 −14 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java
  5. +5 −6 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxRpmBundler.java
  6. +32 −37 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacAppImageBuilder.java
  7. +15 −14 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacAppStoreBundler.java
  8. +15 −13 ...dk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacBaseInstallerBundler.java
  9. +8 −8 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacCertificate.java
  10. +90 −88 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java
  11. +82 −76 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacPkgBundler.java
  12. +3 −4 ...jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AbstractAppImageBuilder.java
  13. +6 −6 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AbstractBundler.java
  14. +3 −3 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AddLauncherArguments.java
  15. +3 −4 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageBundler.java
  16. +2 −2 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java
  17. +15 −15 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Arguments.java
  18. +0 −1 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/BundleParams.java
  19. +4 −4 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Bundler.java
  20. +37 −27 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/DeployParams.java
  21. +6 −6 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Executor.java
  22. +2 −3 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/FileAssociation.java
  23. +28 −18 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java
  24. +2 −2 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/LauncherData.java
  25. +4 −5 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/PathGroup.java
  26. +1 −1 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/ScriptRunner.java
  27. +38 −36 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/StandardBundlerParam.java
  28. +2 −1 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/ExecutableRebrander.java
  29. +26 −25 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinExeBundler.java
  30. +54 −54 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java
  31. +6 −6 ...dk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WindowsAppImageBuilder.java
  32. +2 −1 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WixSourcesBuilder.java
  33. +1 −1 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WixTool.java
  34. +3 −3 test/jdk/tools/jpackage/junit/jdk/incubator/jpackage/internal/DeployParamsTest.java
@@ -435,8 +435,8 @@ private void addFileAssociationIconFiles(ShellCommands shellCommands)
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);
@@ -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 @@

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";

@@ -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 void doValidate(Map<String, ? super Object> params)
}

@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 @@ protected void initLibProvidersLookup(
*
* 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 static boolean isDebian() {
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 FileVisitResult visitFile(Path file,
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 @@ void create(Map<String, String> data, Map<String, ? super Object> params)
.setSubstitutionData(data)
.saveToFile(dstFilePath);
if (permissions != null) {
setPermissions(dstFilePath.toFile(), permissions);
setPermissions(dstFilePath, permissions);
}
}

@@ -415,7 +414,7 @@ private void prepareProjectConfig(Map<String, String> data,

if (!StandardBundlerParam.isRuntimeInstaller(params)) {
debianFiles.add(new DebianFile(
getConfig_CopyrightFile(params).toPath(),
getConfig_CopyrightFile(params),
"resource.copyright-file"));
}

@@ -440,7 +439,7 @@ private void prepareProjectConfig(Map<String, String> data,
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 @@ private File getConfig_CopyrightFile(Map<String, ? super Object> params) {
}

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 @@ private File buildDeb(Map<String, ? super Object> params,
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;
}
@@ -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,29 +103,29 @@ final public String getBundleType() {
}

@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) {
initAppImageLayout.apply(appImage).copy(
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 @@ final public File execute(Map<String, ? super Object> params,
// 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 @@ final public File execute(Map<String, ? super Object> params,

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 protected void doValidate(Map<String, ? super Object> params)
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 @@ public String name() {

@Override
public Path sourceRoot() {
return IMAGES_ROOT.fetchFrom(params).toPath().toAbsolutePath();
return IMAGES_ROOT.fetchFrom(params).toAbsolutePath();
}

@Override
@@ -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 @@ private static ToolValidator createRpmbuildToolValidator() {
}

@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 @@ protected File buildPackageBundle(
.setSubstitutionData(replacementData)
.saveToFile(specFile);

return buildRPM(params, outputParentDir.toPath()).toFile();
return buildRPM(params, outputParentDir);
}

@Override
@@ -275,7 +274,7 @@ private String rpmArch() throws IOException {
}

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 @@ private Path buildRPM(Map<String, ? super Object> params,
"--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();

0 comments on commit ed05d57

Please sign in to comment.