From fea5f2b1458cdd53f437e59caaffaa6e22fb59a7 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Tue, 19 Nov 2024 13:54:57 +0000 Subject: [PATCH] 8344415: Restruct jpackage utility classes Reviewed-by: almatvee --- .../jpackage/internal/DesktopIntegration.java | 10 +- .../internal/LinuxAppImageBuilder.java | 5 +- .../internal/LinuxPackageBundler.java | 5 +- .../internal/MacBaseInstallerBundler.java | 11 +- .../jdk/jpackage/internal/MacDmgBundler.java | 11 +- .../internal/MacLaunchersAsServices.java | 5 +- .../jdk/jpackage/internal/MacPkgBundler.java | 8 +- .../internal/AbstractAppImageBuilder.java | 10 +- .../jpackage/internal/AbstractBundler.java | 5 +- .../jdk/jpackage/internal/AppImageFile.java | 5 +- .../jdk/jpackage/internal/IOUtils.java | 294 +----------------- .../jdk/jpackage/internal/PathGroup.java | 5 +- .../internal/StandardBundlerParam.java | 5 +- .../jdk/jpackage/internal/util/FileUtils.java | 155 +++++++++ .../jdk/jpackage/internal/util/PathUtils.java | 54 ++++ .../internal/util/PrettyPrintHandler.java | 89 ++++++ .../internal/util/SkipDocumentHandler.java | 48 +++ .../jpackage/internal/util/XmlConsumer.java | 34 ++ .../jdk/jpackage/internal/util/XmlUtils.java | 103 ++++++ .../internal/util/function/ExceptionBox.java | 50 +++ .../util/function/ThrowingBiConsumer.java | 42 +++ .../util/function/ThrowingBiFunction.java | 43 +++ .../util/function/ThrowingConsumer.java | 42 +++ .../util/function/ThrowingFunction.java | 42 +++ .../util/function/ThrowingRunnable.java | 40 +++ .../util/function/ThrowingSupplier.java | 42 +++ .../util/function/ThrowingUnaryOperator.java | 43 +++ .../jdk/jpackage/internal/WinExeBundler.java | 5 +- .../jdk/jpackage/internal/WinMsiBundler.java | 5 +- .../internal/WixAppImageFragmentBuilder.java | 11 +- .../jpackage/internal/WixFragmentBuilder.java | 5 +- .../internal/WixLauncherAsService.java | 7 +- .../jdk/jpackage/internal/WixPipeline.java | 3 +- .../jpackage/internal/WixSourceConverter.java | 3 +- .../jdk/jpackage/internal/WixTool.java | 3 +- .../internal/WixUiFragmentBuilder.java | 4 +- test/jdk/tools/jpackage/TEST.properties | 2 + .../jdk/jpackage/test/AnnotationsTest.java | 2 +- .../jdk/jpackage/test/TKitTest.java | 6 +- .../jdk/jpackage/test/AdditionalLauncher.java | 45 +-- .../helpers/jdk/jpackage/test/Executor.java | 4 +- .../jdk/jpackage/test/FileAssociations.java | 10 +- .../helpers/jdk/jpackage/test/Functional.java | 102 ------ .../helpers/jdk/jpackage/test/HelloApp.java | 6 +- .../jdk/jpackage/test/JPackageCommand.java | 12 +- .../test/LauncherAsServiceVerifier.java | 12 +- .../jpackage/test/LauncherIconVerifier.java | 9 +- .../jdk/jpackage/test/LinuxHelper.java | 6 +- .../helpers/jdk/jpackage/test/MacHelper.java | 8 +- .../helpers/jdk/jpackage/test/MethodCall.java | 2 +- .../jdk/jpackage/test/PackageTest.java | 14 +- .../jdk/jpackage/test/PackageType.java | 17 +- .../helpers/jdk/jpackage/test/TKit.java | 8 +- .../jdk/jpackage/test/TestBuilder.java | 6 +- .../jdk/jpackage/test/TestInstance.java | 9 +- .../jdk/jpackage/test/TestMethodSupplier.java | 4 +- .../jdk/jpackage/test/WindowsHelper.java | 2 +- .../tools/jpackage/linux/AppAboutUrlTest.java | 2 +- .../tools/jpackage/share/AppContentTest.java | 8 +- test/jdk/tools/jpackage/share/BasicTest.java | 2 +- test/jdk/tools/jpackage/share/IconTest.java | 8 +- .../tools/jpackage/share/InOutPathTest.java | 2 +- .../tools/jpackage/share/MainClassTest.java | 2 +- .../tools/jpackage/share/PerUserCfgTest.java | 2 +- .../share/RuntimeImageSymbolicLinksTest.java | 9 - .../jpackage/windows/WinLongVersionTest.java | 7 +- .../tools/jpackage/windows/WinScriptTest.java | 5 +- 67 files changed, 1014 insertions(+), 571 deletions(-) create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/FileUtils.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PathUtils.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PrettyPrintHandler.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/SkipDocumentHandler.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlConsumer.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlUtils.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ExceptionBox.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiConsumer.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiFunction.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingConsumer.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingFunction.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingRunnable.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingSupplier.java create mode 100644 src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingUnaryOperator.java diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/DesktopIntegration.java b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/DesktopIntegration.java index 6a5b200f8f3..a9cf2682cd7 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/DesktopIntegration.java +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/DesktopIntegration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -54,6 +54,8 @@ import static jdk.jpackage.internal.StandardBundlerParam.FILE_ASSOCIATIONS; import static jdk.jpackage.internal.StandardBundlerParam.ICON; import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.SHORTCUT_HINT; +import jdk.jpackage.internal.util.PathUtils; +import jdk.jpackage.internal.util.XmlUtils; /** * Helper to create files for desktop integration. @@ -119,7 +121,7 @@ final class DesktopIntegration extends ShellCustomAction { if (withDesktopFile) { desktopFile = new DesktopFile(desktopFileName); iconFile = new DesktopFile(escapedAppFileName - + IOUtils.getSuffix(Path.of(DEFAULT_ICON))); + + PathUtils.getSuffix(Path.of(DEFAULT_ICON))); if (curIconResource == null) { // Create default icon. @@ -420,7 +422,7 @@ final class DesktopIntegration extends ShellCustomAction { } private void createFileAssociationsMimeInfoFile() throws IOException { - IOUtils.createXml(mimeInfoFile.srcPath(), xml -> { + XmlUtils.createXml(mimeInfoFile.srcPath(), xml -> { xml.writeStartElement("mime-info"); xml.writeDefaultNamespace( "http://www.freedesktop.org/standards/shared-mime-info"); @@ -451,7 +453,7 @@ final class DesktopIntegration extends ShellCustomAction { // Create icon name for mime type from mime type. DesktopFile faIconFile = new DesktopFile(mimeType.replace( - File.separatorChar, '-') + IOUtils.getSuffix( + File.separatorChar, '-') + PathUtils.getSuffix( assoc.data.iconPath)); IOUtils.copyFile(assoc.data.iconPath, diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java index 7291d56218a..ab97e327003 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -35,6 +35,7 @@ import java.util.Map; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.ICON; import static jdk.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS; +import jdk.jpackage.internal.util.PathUtils; public class LinuxAppImageBuilder extends AbstractAppImageBuilder { @@ -127,7 +128,7 @@ public class LinuxAppImageBuilder extends AbstractAppImageBuilder { mainParams); if (iconResource != null) { Path iconTarget = appLayout.destktopIntegrationDirectory().resolve( - APP_NAME.fetchFrom(params) + IOUtils.getSuffix(Path.of( + APP_NAME.fetchFrom(params) + PathUtils.getSuffix(Path.of( DEFAULT_ICON))); iconResource.saveToFile(iconTarget); } diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java index b510ed41411..5d160d4128c 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -44,6 +44,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.VENDOR; import static jdk.jpackage.internal.StandardBundlerParam.DESCRIPTION; import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; +import jdk.jpackage.internal.util.FileUtils; abstract class LinuxPackageBundler extends AbstractBundler { @@ -144,7 +145,7 @@ abstract class LinuxPackageBundler extends AbstractBundler { // Application image is a newly created directory tree. // Move it. srcAppLayout.move(thePackage.sourceApplicationLayout()); - IOUtils.deleteRecursive(srcAppImageRoot); + FileUtils.deleteRecursive(srcAppImageRoot); } } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java index 8d9db0a0077..69ecce068e7 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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,25 +25,20 @@ package jdk.jpackage.internal; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME; import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; +import jdk.jpackage.internal.util.FileUtils; public abstract class MacBaseInstallerBundler extends AbstractBundler { @@ -187,7 +182,7 @@ public abstract class MacBaseInstallerBundler extends AbstractBundler { StandardBundlerParam.getPredefinedAppImage(params); if (predefinedImage != null) { appDir = appImageRoot.resolve(APP_NAME.fetchFrom(params) + ".app"); - IOUtils.copyRecursive(predefinedImage, appDir, + FileUtils.copyRecursive(predefinedImage, appDir, LinkOption.NOFOLLOW_LINKS); // Create PackageFile if predefined app image is not signed diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java index 7d100832dba..3de8ef5ee2b 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -48,6 +48,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE; import static jdk.jpackage.internal.StandardBundlerParam.TEMP_ROOT; import static jdk.jpackage.internal.StandardBundlerParam.VERBOSE; import static jdk.jpackage.internal.StandardBundlerParam.DMG_CONTENT; +import jdk.jpackage.internal.util.FileUtils; public class MacDmgBundler extends MacBaseInstallerBundler { @@ -294,7 +295,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler { MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params)); Path dest = root.resolve("Contents/Home"); - IOUtils.copyRecursive(source, dest); + FileUtils.copyRecursive(source, dest); srcFolder = newRoot; } @@ -319,7 +320,7 @@ public class MacDmgBundler extends MacBaseInstallerBundler { List dmgContent = DMG_CONTENT.fetchFrom(params); for (String content : dmgContent) { Path path = Path.of(content); - IOUtils.copyRecursive(path, srcFolder.resolve(path.getFileName())); + FileUtils.copyRecursive(path, srcFolder.resolve(path.getFileName())); } // create temp image ProcessBuilder pb = new ProcessBuilder( @@ -381,9 +382,9 @@ public class MacDmgBundler extends MacBaseInstallerBundler { Path destPath = mountedRoot .resolve(srcFolder.getFileName()); Files.createDirectory(destPath); - IOUtils.copyRecursive(srcFolder, destPath); + FileUtils.copyRecursive(srcFolder, destPath); } else { - IOUtils.copyRecursive(srcFolder, mountedRoot); + FileUtils.copyRecursive(srcFolder, mountedRoot); } } diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacLaunchersAsServices.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacLaunchersAsServices.java index b0ee96e2ee3..4f069921f45 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacLaunchersAsServices.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacLaunchersAsServices.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,6 +33,7 @@ import java.util.function.Predicate; import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER; import static jdk.jpackage.internal.OverridableResource.createResource; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; +import jdk.jpackage.internal.util.PathUtils; /** * Helper to install launchers as services using "launchd". @@ -95,7 +96,7 @@ public final class MacLaunchersAsServices extends UnixLaunchersAsServices { // It is recommended to set value of "label" property in launchd // .plist file equal to the name of this .plist file without the suffix. - String label = IOUtils.replaceSuffix(plistFilename.getFileName(), "").toString(); + String label = PathUtils.replaceSuffix(plistFilename.getFileName(), "").toString(); getResource() .setPublicName(plistFilename) diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java index 6ac84975451..a4345ecf764 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -62,6 +62,8 @@ import static jdk.jpackage.internal.StandardBundlerParam.APP_STORE; import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER; import static jdk.jpackage.internal.OverridableResource.createResource; import static jdk.jpackage.internal.StandardBundlerParam.RESOURCE_DIR; +import jdk.jpackage.internal.util.FileUtils; +import jdk.jpackage.internal.util.XmlUtils; public class MacPkgBundler extends MacBaseInstallerBundler { @@ -267,7 +269,7 @@ public class MacPkgBundler extends MacBaseInstallerBundler { Log.verbose(MessageFormat.format(I18N.getString( "message.preparing-distribution-dist"), f.toAbsolutePath().toString())); - IOUtils.createXml(f, xml -> { + XmlUtils.createXml(f, xml -> { xml.writeStartElement("installer-gui-script"); xml.writeAttribute("minSpecVersion", "1"); @@ -452,7 +454,7 @@ public class MacPkgBundler extends MacBaseInstallerBundler { source = appLocation; dest = newRoot.resolve(appLocation.getFileName()); } - IOUtils.copyRecursive(source, dest); + FileUtils.copyRecursive(source, dest); return newRoot.toString(); } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java index b507cc955bd..b523e43f5aa 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java @@ -32,8 +32,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Map; import java.util.List; -import java.util.Objects; -import java.util.stream.Stream; import static jdk.jpackage.internal.OverridableResource.createResource; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.ICON; @@ -42,6 +40,8 @@ import static jdk.jpackage.internal.StandardBundlerParam.APP_CONTENT; import static jdk.jpackage.internal.StandardBundlerParam.OUTPUT_DIR; import static jdk.jpackage.internal.StandardBundlerParam.TEMP_ROOT; import jdk.jpackage.internal.resources.ResourceLocator; +import jdk.jpackage.internal.util.FileUtils; +import jdk.jpackage.internal.util.PathUtils; /* * AbstractAppImageBuilder @@ -92,7 +92,7 @@ public abstract class AbstractAppImageBuilder { } } - IOUtils.copyRecursive(inputPath, + FileUtils.copyRecursive(inputPath, appLayout.appDirectory().toAbsolutePath(), excludes); } @@ -100,7 +100,7 @@ public abstract class AbstractAppImageBuilder { List items = APP_CONTENT.fetchFrom(params); for (String item : items) { - IOUtils.copyRecursive(Path.of(item), + FileUtils.copyRecursive(Path.of(item), appLayout.contentDirectory().resolve(Path.of(item).getFileName())); } } @@ -115,7 +115,7 @@ public abstract class AbstractAppImageBuilder { } final String resourcePublicName = APP_NAME.fetchFrom(params) - + IOUtils.getSuffix(Path.of(defaultIconName)); + + PathUtils.getSuffix(Path.of(defaultIconName)); IconType iconType = getLauncherIconType(params); if (iconType == IconType.NoIcon) { diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java index b615176fd15..e28a444a045 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -28,6 +28,7 @@ package jdk.jpackage.internal; import java.io.IOException; import java.nio.file.Path; import java.util.Map; +import jdk.jpackage.internal.util.FileUtils; /** @@ -55,7 +56,7 @@ abstract class AbstractBundler implements Bundler { @Override public void cleanup(Map params) { try { - IOUtils.deleteRecursive( + FileUtils.deleteRecursive( StandardBundlerParam.TEMP_ROOT.fetchFrom(params)); } catch (IOException e) { Log.verbose(e.getMessage()); diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java index 31228a8f5a3..256d292350a 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -59,6 +59,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.SHORTCUT_HINT; import static jdk.jpackage.internal.StandardBundlerParam.MENU_HINT; import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE; import static jdk.jpackage.internal.StandardBundlerParam.APP_STORE; +import jdk.jpackage.internal.util.XmlUtils; public final class AppImageFile { @@ -247,7 +248,7 @@ public final class AppImageFile { addLauncherInfoSave = appImage.getAddLaunchers(); } - IOUtils.createXml(getPathInAppImage(appImageDir), xml -> { + XmlUtils.createXml(getPathInAppImage(appImageDir), xml -> { xml.writeStartElement("jpackage-state"); xml.writeAttribute("version", getVersion()); xml.writeAttribute("platform", getPlatform()); diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java index 573109a004b..534786ada13 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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,41 +25,15 @@ package jdk.jpackage.internal; -import jdk.internal.util.OperatingSystem; - import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintStream; -import java.io.Writer; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.nio.file.FileVisitResult; import java.nio.file.Files; -import java.nio.file.CopyOption; import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.stax.StAXResult; /** * IOUtils @@ -68,107 +42,6 @@ import javax.xml.transform.stax.StAXResult; */ public class IOUtils { - public static void deleteRecursive(Path directory) throws IOException { - final AtomicReference exception = new AtomicReference<>(); - - if (!Files.exists(directory)) { - return; - } - - Files.walkFileTree(directory, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, - BasicFileAttributes attr) throws IOException { - if (OperatingSystem.isWindows()) { - Files.setAttribute(file, "dos:readonly", false); - } - try { - Files.delete(file); - } catch (IOException ex) { - exception.compareAndSet(null, ex); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, - BasicFileAttributes attr) throws IOException { - if (OperatingSystem.isWindows()) { - Files.setAttribute(dir, "dos:readonly", false); - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException e) - throws IOException { - try { - Files.delete(dir); - } catch (IOException ex) { - exception.compareAndSet(null, ex); - } - return FileVisitResult.CONTINUE; - } - }); - if (exception.get() != null) { - throw exception.get(); - } - } - - public static void copyRecursive(Path src, Path dest, CopyOption... options) - throws IOException { - copyRecursive(src, dest, List.of(), options); - } - - public static void copyRecursive(Path src, Path dest, - final List excludes, CopyOption... options) - throws IOException { - - List copyActions = new ArrayList<>(); - - Files.walkFileTree(src, new SimpleFileVisitor() { - @Override - public FileVisitResult preVisitDirectory(final Path dir, - final BasicFileAttributes attrs) { - if (isPathMatch(dir, excludes)) { - return FileVisitResult.SKIP_SUBTREE; - } else { - copyActions.add(new CopyAction(null, dest.resolve(src. - relativize(dir)))); - return FileVisitResult.CONTINUE; - } - } - - @Override - public FileVisitResult visitFile(final Path file, - final BasicFileAttributes attrs) { - if (!isPathMatch(file, excludes)) { - copyActions.add(new CopyAction(file, dest.resolve(src. - relativize(file)))); - } - return FileVisitResult.CONTINUE; - } - }); - - for (var copyAction : copyActions) { - copyAction.apply(options); - } - } - - private static record CopyAction(Path src, Path dest) { - void apply(CopyOption... options) throws IOException { - if (src == null) { - Files.createDirectories(dest); - } else { - Files.copy(src, dest, options); - } - } - } - - private static boolean isPathMatch(Path what, List paths) { - return paths.stream().anyMatch(what::endsWith); - } - public static void copyFile(Path sourceFile, Path destFile) throws IOException { Files.createDirectories(getParent(destFile)); @@ -314,90 +187,6 @@ public class IOUtils { } } - public static Path replaceSuffix(Path path, String suffix) { - Path parent = path.getParent(); - String filename = getFileName(path).toString().replaceAll("\\.[^.]*$", "") - + Optional.ofNullable(suffix).orElse(""); - return parent != null ? parent.resolve(filename) : Path.of(filename); - } - - public static Path addSuffix(Path path, String suffix) { - Path parent = path.getParent(); - String filename = getFileName(path).toString() + suffix; - return parent != null ? parent.resolve(filename) : Path.of(filename); - } - - public static String getSuffix(Path path) { - String filename = replaceSuffix(getFileName(path), null).toString(); - return getFileName(path).toString().substring(filename.length()); - } - - @FunctionalInterface - public static interface XmlConsumer { - void accept(XMLStreamWriter xml) throws IOException, XMLStreamException; - } - - public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws - IOException { - XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); - Files.createDirectories(getParent(dstFile)); - try (Writer w = Files.newBufferedWriter(dstFile)) { - // Wrap with pretty print proxy - XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance( - XMLStreamWriter.class.getClassLoader(), new Class[]{ - XMLStreamWriter.class}, new PrettyPrintHandler( - xmlFactory.createXMLStreamWriter(w))); - - xml.writeStartDocument(); - xmlConsumer.accept(xml); - xml.writeEndDocument(); - xml.flush(); - xml.close(); - } catch (XMLStreamException ex) { - throw new IOException(ex); - } catch (IOException ex) { - throw ex; - } - } - - public static void mergeXmls(XMLStreamWriter xml, Collection sources) - throws XMLStreamException, IOException { - xml = (XMLStreamWriter) Proxy.newProxyInstance( - XMLStreamWriter.class.getClassLoader(), new Class[]{ - XMLStreamWriter.class}, new SkipDocumentHandler(xml)); - - try { - TransformerFactory tf = TransformerFactory.newInstance(); - Result result = new StAXResult(xml); - for (var src : sources) { - tf.newTransformer().transform(src, result); - } - } catch (TransformerException ex) { - // Should never happen - throw new RuntimeException(ex); - } - } - - public static DocumentBuilderFactory initDocumentBuilderFactory() { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance(); - try { - dbf.setFeature( - "http://apache.org/xml/features/nonvalidating/load-external-dtd", - false); - } catch (ParserConfigurationException ex) { - throw new IllegalStateException(ex); - } - return dbf; - } - - public static DocumentBuilder initDocumentBuilder() { - try { - return initDocumentBuilderFactory().newDocumentBuilder(); - } catch (ParserConfigurationException ex) { - throw new IllegalStateException(ex); - } - } - public static Path getParent(Path p) { Path parent = p.getParent(); if (parent == null) { @@ -430,85 +219,4 @@ public class IOUtils { return -1; } } - - private static class PrettyPrintHandler implements InvocationHandler { - - PrettyPrintHandler(XMLStreamWriter target) { - this.target = target; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws - Throwable { - switch (method.getName()) { - case "writeStartElement": - // update state of parent node - if (depth > 0) { - hasChildElement.put(depth - 1, true); - } - // reset state of current node - hasChildElement.put(depth, false); - // indent for current depth - target.writeCharacters(EOL); - target.writeCharacters(repeat(depth, INDENT)); - depth++; - break; - case "writeEndElement": - depth--; - if (hasChildElement.get(depth) == true) { - target.writeCharacters(EOL); - target.writeCharacters(repeat(depth, INDENT)); - } - break; - case "writeProcessingInstruction": - case "writeEmptyElement": - // update state of parent node - if (depth > 0) { - hasChildElement.put(depth - 1, true); - } - // indent for current depth - target.writeCharacters(EOL); - target.writeCharacters(repeat(depth, INDENT)); - break; - default: - break; - } - method.invoke(target, args); - return null; - } - - private static String repeat(int d, String s) { - StringBuilder sb = new StringBuilder(); - while (d-- > 0) { - sb.append(s); - } - return sb.toString(); - } - - private final XMLStreamWriter target; - private int depth = 0; - private final Map hasChildElement = new HashMap<>(); - private static final String INDENT = " "; - private static final String EOL = "\n"; - } - - private static class SkipDocumentHandler implements InvocationHandler { - - SkipDocumentHandler(XMLStreamWriter target) { - this.target = target; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws - Throwable { - switch (method.getName()) { - case "writeStartDocument", "writeEndDocument" -> { - } - default -> method.invoke(target, args); - } - return null; - } - - private final XMLStreamWriter target; - } } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java index 24fb394e100..296164551a1 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -35,6 +35,7 @@ import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Collectors; import java.util.stream.Stream; +import jdk.jpackage.internal.util.FileUtils; /** @@ -232,7 +233,7 @@ final class PathGroup { for (var entry: entries) { Path srcFile = entry.getKey(); if (Files.isDirectory(srcFile)) { - IOUtils.deleteRecursive(srcFile); + FileUtils.deleteRecursive(srcFile); } } } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java index 718f186c954..0209eea584a 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java @@ -44,6 +44,7 @@ import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; import java.util.stream.Stream; +import jdk.jpackage.internal.util.FileUtils; /** * StandardBundlerParam @@ -604,7 +605,7 @@ class StandardBundlerParam extends BundlerParamInfo { // copy whole runtime, need to skip jmods and src.zip final List excludes = Arrays.asList(Path.of("jmods"), Path.of("src.zip")); - IOUtils.copyRecursive(topImage, appLayout.runtimeHomeDirectory(), + FileUtils.copyRecursive(topImage, appLayout.runtimeHomeDirectory(), excludes, LinkOption.NOFOLLOW_LINKS); // if module-path given - copy modules to appDir/mods @@ -616,7 +617,7 @@ class StandardBundlerParam extends BundlerParamInfo { for (Path mp : modulePath) { if (!defaultModulePath.contains(mp)) { Files.createDirectories(dest); - IOUtils.copyRecursive(mp, dest); + FileUtils.copyRecursive(mp, dest); } } } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/FileUtils.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/FileUtils.java new file mode 100644 index 00000000000..71b8c3d6ddc --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/FileUtils.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.io.IOException; +import java.nio.file.CopyOption; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import jdk.internal.util.OperatingSystem; +import jdk.jpackage.internal.util.function.ExceptionBox; +import jdk.jpackage.internal.util.function.ThrowingConsumer; + +public final class FileUtils { + + public static void deleteRecursive(Path directory) throws IOException { + if (!Files.exists(directory)) { + return; + } + + var callback = new RecursiveDeleter(); + + Files.walkFileTree(directory, callback); + + if (callback.ex != null) { + throw callback.ex; + } + } + + public static void copyRecursive(Path src, Path dest, CopyOption... options) + throws IOException { + copyRecursive(src, dest, List.of(), options); + } + + public static void copyRecursive(Path src, Path dest, + final List excludes, CopyOption... options) + throws IOException { + + List copyActions = new ArrayList<>(); + + Files.walkFileTree(src, new SimpleFileVisitor() { + @Override + public FileVisitResult preVisitDirectory(final Path dir, + final BasicFileAttributes attrs) { + if (isPathMatch(dir, excludes)) { + return FileVisitResult.SKIP_SUBTREE; + } else { + copyActions.add(new CopyAction(null, dest.resolve(src. + relativize(dir)))); + return FileVisitResult.CONTINUE; + } + } + + @Override + public FileVisitResult visitFile(final Path file, + final BasicFileAttributes attrs) { + if (!isPathMatch(file, excludes)) { + copyActions.add(new CopyAction(file, dest.resolve(src. + relativize(file)))); + } + return FileVisitResult.CONTINUE; + } + }); + + for (var copyAction : copyActions) { + copyAction.apply(options); + } + } + + private static boolean isPathMatch(Path what, List paths) { + return paths.stream().anyMatch(what::endsWith); + } + + private static record CopyAction(Path src, Path dest) { + + void apply(CopyOption... options) throws IOException { + if (src == null) { + Files.createDirectories(dest); + } else { + Files.copy(src, dest, options); + } + } + } + + private static class RecursiveDeleter extends SimpleFileVisitor { + + @Override + public FileVisitResult visitFile(Path file, + BasicFileAttributes attr) throws IOException { + adjustAttributes(file); + runActionOnPath(Files::delete, file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, + BasicFileAttributes attr) throws IOException { + adjustAttributes(dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException e) + throws IOException { + runActionOnPath(Files::delete, dir); + return FileVisitResult.CONTINUE; + } + + private static void adjustAttributes(Path path) throws IOException { + if (OperatingSystem.isWindows()) { + Files.setAttribute(path, "dos:readonly", false); + } + } + + private void runActionOnPath(ThrowingConsumer action, Path path) { + try { + action.accept(path); + } catch (IOException ex) { + if (this.ex == null) { + this.ex = ex; + } + } catch (Throwable t) { + throw ExceptionBox.rethrowUnchecked(t); + } + } + + private IOException ex; + } +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PathUtils.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PathUtils.java new file mode 100644 index 00000000000..267062a2031 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PathUtils.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.nio.file.Path; +import java.util.Optional; +import jdk.jpackage.internal.IOUtils; + +public final class PathUtils { + + public static String getSuffix(Path path) { + String filename = replaceSuffix(IOUtils.getFileName(path), null).toString(); + return IOUtils.getFileName(path).toString().substring(filename.length()); + } + + public static Path addSuffix(Path path, String suffix) { + Path parent = path.getParent(); + String filename = IOUtils.getFileName(path).toString() + suffix; + return parent != null ? parent.resolve(filename) : Path.of(filename); + } + + public static Path replaceSuffix(Path path, String suffix) { + Path parent = path.getParent(); + String filename = IOUtils.getFileName(path).toString().replaceAll("\\.[^.]*$", + "") + Optional.ofNullable(suffix).orElse(""); + return parent != null ? parent.resolve(filename) : Path.of(filename); + } + + public static Path resolveNullablePath(Path base, Path path) { + return Optional.ofNullable(path).map(base::resolve).orElse(null); + } +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PrettyPrintHandler.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PrettyPrintHandler.java new file mode 100644 index 00000000000..ffd5b764103 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PrettyPrintHandler.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import javax.xml.stream.XMLStreamWriter; + +final class PrettyPrintHandler implements InvocationHandler { + + public PrettyPrintHandler(XMLStreamWriter target) { + this.target = target; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + switch (method.getName()) { + case "writeStartElement": + // update state of parent node + if (depth > 0) { + hasChildElement.put(depth - 1, true); + } + // reset state of current node + hasChildElement.put(depth, false); + // indent for current depth + target.writeCharacters(EOL); + target.writeCharacters(repeat(depth, INDENT)); + depth++; + break; + case "writeEndElement": + depth--; + if (hasChildElement.get(depth) == true) { + target.writeCharacters(EOL); + target.writeCharacters(repeat(depth, INDENT)); + } + break; + case "writeProcessingInstruction": + case "writeEmptyElement": + // update state of parent node + if (depth > 0) { + hasChildElement.put(depth - 1, true); + } + // indent for current depth + target.writeCharacters(EOL); + target.writeCharacters(repeat(depth, INDENT)); + break; + default: + break; + } + method.invoke(target, args); + return null; + } + + private static String repeat(int d, String s) { + StringBuilder sb = new StringBuilder(); + while (d-- > 0) { + sb.append(s); + } + return sb.toString(); + } + + private final XMLStreamWriter target; + private int depth = 0; + private final Map hasChildElement = new HashMap<>(); + private static final String INDENT = " "; + private static final String EOL = "\n"; +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/SkipDocumentHandler.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/SkipDocumentHandler.java new file mode 100644 index 00000000000..283dac451a2 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/SkipDocumentHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import javax.xml.stream.XMLStreamWriter; + +final class SkipDocumentHandler implements InvocationHandler { + + public SkipDocumentHandler(XMLStreamWriter target) { + this.target = target; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + switch (method.getName()) { + case "writeStartDocument", "writeEndDocument" -> { + } + default -> method.invoke(target, args); + } + return null; + } + + private final XMLStreamWriter target; +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlConsumer.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlConsumer.java new file mode 100644 index 00000000000..429be6aba05 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlConsumer.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.io.IOException; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +@FunctionalInterface +public interface XmlConsumer { + + void accept(XMLStreamWriter xml) throws IOException, XMLStreamException; + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlUtils.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlUtils.java new file mode 100644 index 00000000000..8012384b679 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlUtils.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util; + +import java.io.IOException; +import java.io.Writer; +import java.lang.reflect.Proxy; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collection; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stax.StAXResult; +import jdk.jpackage.internal.IOUtils; + + +public final class XmlUtils { + + public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws + IOException { + XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); + Files.createDirectories(IOUtils.getParent(dstFile)); + try (Writer w = Files.newBufferedWriter(dstFile)) { + // Wrap with pretty print proxy + XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance(XMLStreamWriter.class.getClassLoader(), + new Class[]{XMLStreamWriter.class}, + new PrettyPrintHandler(xmlFactory.createXMLStreamWriter(w))); + xml.writeStartDocument(); + xmlConsumer.accept(xml); + xml.writeEndDocument(); + xml.flush(); + xml.close(); + } catch (XMLStreamException ex) { + throw new IOException(ex); + } catch (IOException ex) { + throw ex; + } + } + + public static void mergeXmls(XMLStreamWriter xml, Collection sources) + throws XMLStreamException, IOException { + xml = (XMLStreamWriter) Proxy.newProxyInstance(XMLStreamWriter.class.getClassLoader(), + new Class[]{XMLStreamWriter.class}, + new SkipDocumentHandler(xml)); + try { + TransformerFactory tf = TransformerFactory.newInstance(); + Result result = new StAXResult(xml); + for (Source src : sources) { + tf.newTransformer().transform(src, result); + } + } catch (TransformerException ex) { + // Should never happen + throw new RuntimeException(ex); + } + } + + public static DocumentBuilder initDocumentBuilder() { + try { + return initDocumentBuilderFactory().newDocumentBuilder(); + } catch (ParserConfigurationException ex) { + throw new IllegalStateException(ex); + } + } + + public static DocumentBuilderFactory initDocumentBuilderFactory() { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance(); + try { + dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", + false); + } catch (ParserConfigurationException ex) { + throw new IllegalStateException(ex); + } + return dbf; + } +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ExceptionBox.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ExceptionBox.java new file mode 100644 index 00000000000..55f2964445f --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ExceptionBox.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.lang.reflect.InvocationTargetException; + +public class ExceptionBox extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public static RuntimeException rethrowUnchecked(Throwable throwable) { + if (throwable instanceof RuntimeException err) { + throw err; + } + + if (throwable instanceof Error err) { + throw err; + } + + if (throwable instanceof InvocationTargetException err) { + throw rethrowUnchecked(err.getCause()); + } + + throw new ExceptionBox(throwable); + } + + private ExceptionBox(Throwable throwable) { + super(throwable); + } +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiConsumer.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiConsumer.java new file mode 100644 index 00000000000..e5b7704a92e --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiConsumer.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.BiConsumer; + +@FunctionalInterface +public interface ThrowingBiConsumer { + + void accept(T t, U u) throws Throwable; + + public static BiConsumer toBiConsumer( + ThrowingBiConsumer v) { + return (t, u) -> { + try { + v.accept(t, u); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiFunction.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiFunction.java new file mode 100644 index 00000000000..a8119f25bdb --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingBiFunction.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.BiFunction; + +@FunctionalInterface +public interface ThrowingBiFunction { + + R apply(T t, U u) throws Throwable; + + public static BiFunction toBiFunction( + ThrowingBiFunction v) { + return (t, u) -> { + try { + return v.apply(t, u); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingConsumer.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingConsumer.java new file mode 100644 index 00000000000..5ca33c22d92 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingConsumer.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.Consumer; + +@FunctionalInterface +public interface ThrowingConsumer { + + void accept(T t) throws Throwable; + + public static Consumer toConsumer(ThrowingConsumer v) { + return o -> { + try { + v.accept(o); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingFunction.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingFunction.java new file mode 100644 index 00000000000..db6b1d26005 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingFunction.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.Function; + +@FunctionalInterface +public interface ThrowingFunction { + + R apply(T t) throws Throwable; + + public static Function toFunction(ThrowingFunction v) { + return t -> { + try { + return v.apply(t); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingRunnable.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingRunnable.java new file mode 100644 index 00000000000..7f3fcda536c --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingRunnable.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +@FunctionalInterface +public interface ThrowingRunnable { + + void run() throws Throwable; + + public static Runnable toRunnable(ThrowingRunnable v) { + return () -> { + try { + v.run(); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingSupplier.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingSupplier.java new file mode 100644 index 00000000000..2f5ef135875 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingSupplier.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.Supplier; + +@FunctionalInterface +public interface ThrowingSupplier { + + T get() throws Throwable; + + public static Supplier toSupplier(ThrowingSupplier v) { + return () -> { + try { + return v.get(); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingUnaryOperator.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingUnaryOperator.java new file mode 100644 index 00000000000..27a3e2f30f5 --- /dev/null +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/function/ThrowingUnaryOperator.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.jpackage.internal.util.function; + +import java.util.function.UnaryOperator; + +@FunctionalInterface +public interface ThrowingUnaryOperator { + + T apply(T t) throws Throwable; + + public static UnaryOperator toUnaryOperator( + ThrowingUnaryOperator v) { + return t -> { + try { + return v.apply(t); + } catch (Throwable ex) { + throw ExceptionBox.rethrowUnchecked(ex); + } + }; + } + +} diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java index fa81b4278b0..cc2e9298e99 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, 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 @@ -30,6 +30,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.text.MessageFormat; import java.util.Map; +import jdk.jpackage.internal.util.PathUtils; @SuppressWarnings("restricted") public class WinExeBundler extends AbstractBundler { @@ -127,7 +128,7 @@ public class WinExeBundler extends AbstractBundler { outdir.toAbsolutePath().toString())); // Copy template msi wrapper next to msi file - final Path exePath = IOUtils.replaceSuffix(msi, ".exe"); + final Path exePath = PathUtils.replaceSuffix(msi, ".exe"); try (InputStream is = OverridableResource.readDefault(EXE_WRAPPER_NAME)) { Files.copy(is, exePath); } diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java index c0ae65b3b0b..f6b0fb4be20 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java @@ -36,7 +36,6 @@ import java.nio.file.Path; import java.nio.file.PathMatcher; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -67,7 +66,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.RESOURCE_DIR; import static jdk.jpackage.internal.StandardBundlerParam.TEMP_ROOT; import static jdk.jpackage.internal.StandardBundlerParam.VENDOR; import static jdk.jpackage.internal.StandardBundlerParam.VERSION; -import jdk.jpackage.internal.WixToolset.WixToolsetType; +import jdk.jpackage.internal.util.FileUtils; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; @@ -367,7 +366,7 @@ public class WinMsiBundler extends AbstractBundler { if (appImage != null) { appDir = MSI_IMAGE_DIR.fetchFrom(params).resolve(appName); // copy everything from appImage dir into appDir/name - IOUtils.copyRecursive(appImage, appDir); + FileUtils.copyRecursive(appImage, appDir); } else { appDir = appImageBundler.execute(params, MSI_IMAGE_DIR.fetchFrom( params)); diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixAppImageFragmentBuilder.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixAppImageFragmentBuilder.java index 5bc20c1413c..a5d9a5de141 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixAppImageFragmentBuilder.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixAppImageFragmentBuilder.java @@ -42,7 +42,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import jdk.jpackage.internal.AppImageFile.LauncherInfo; -import jdk.jpackage.internal.IOUtils.XmlConsumer; +import jdk.jpackage.internal.util.XmlConsumer; import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR; import static jdk.jpackage.internal.StandardBundlerParam.VENDOR; @@ -65,6 +64,8 @@ import static jdk.jpackage.internal.WinMsiBundler.MSI_SYSTEM_WIDE; import static jdk.jpackage.internal.WinMsiBundler.SERVICE_INSTALLER; import static jdk.jpackage.internal.WinMsiBundler.WIN_APP_IMAGE; import jdk.jpackage.internal.WixToolset.WixToolsetType; +import jdk.jpackage.internal.util.PathUtils; +import jdk.jpackage.internal.util.XmlUtils; import org.w3c.dom.NodeList; /** @@ -202,7 +203,7 @@ class WixAppImageFragmentBuilder extends WixFragmentBuilder { } private static Path addExeSuffixToPath(Path path) { - return IOUtils.addSuffix(path, ".exe"); + return PathUtils.addSuffix(path, ".exe"); } private Path getInstalledFaIcoPath(FileAssociation fa) { @@ -524,7 +525,7 @@ class WixAppImageFragmentBuilder extends WixFragmentBuilder { throw throwInvalidPathException(launcherPath); } - String launcherBasename = IOUtils.replaceSuffix( + String launcherBasename = PathUtils.replaceSuffix( IOUtils.getFileName(launcherPath), "").toString(); Path shortcutPath = folder.getPath(this).resolve(launcherBasename); @@ -774,7 +775,7 @@ class WixAppImageFragmentBuilder extends WixFragmentBuilder { } try { - var buffer = new DOMResult(IOUtils.initDocumentBuilder().newDocument()); + var buffer = new DOMResult(XmlUtils.initDocumentBuilder().newDocument()); var bufferWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( buffer); diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixFragmentBuilder.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixFragmentBuilder.java index 0276cc96e65..f0a5840eb6f 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixFragmentBuilder.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixFragmentBuilder.java @@ -37,13 +37,14 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.stream.XMLStreamWriter; -import jdk.jpackage.internal.IOUtils.XmlConsumer; +import jdk.jpackage.internal.util.XmlConsumer; import jdk.jpackage.internal.OverridableResource.Source; import static jdk.jpackage.internal.StandardBundlerParam.CONFIG_ROOT; import jdk.internal.util.Architecture; import static jdk.jpackage.internal.OverridableResource.createResource; import jdk.jpackage.internal.WixSourceConverter.ResourceGroup; import jdk.jpackage.internal.WixToolset.WixToolsetType; +import jdk.jpackage.internal.util.XmlUtils; /** * Creates WiX fragment. @@ -159,7 +160,7 @@ abstract class WixFragmentBuilder { } private void createWixSource(Path file, XmlConsumer xmlConsumer) throws IOException { - IOUtils.createXml(file, xml -> { + XmlUtils.createXml(file, xml -> { xml.writeStartElement("Wix"); for (var ns : getWixNamespaces().entrySet()) { switch (ns.getKey()) { diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixLauncherAsService.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixLauncherAsService.java index 9b737c8e1a4..ffd5e35b15c 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixLauncherAsService.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixLauncherAsService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024, 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 @@ -39,6 +39,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import static jdk.jpackage.internal.OverridableResource.createResource; +import jdk.jpackage.internal.util.XmlUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -95,7 +96,7 @@ class WixLauncherAsService extends LauncherAsService { resource.saveToStream(buffer); try { - Document doc = IOUtils.initDocumentBuilder().parse( + Document doc = XmlUtils.initDocumentBuilder().parse( new ByteArrayInputStream(buffer.toByteArray())); XPath xPath = XPathFactory.newInstance().newXPath(); @@ -109,7 +110,7 @@ class WixLauncherAsService extends LauncherAsService { sources.add(new DOMSource(n)); } - IOUtils.mergeXmls(xml, sources); + XmlUtils.mergeXmls(xml, sources); } catch (SAXException ex) { throw new IOException(ex); diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixPipeline.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixPipeline.java index 835247ed1de..5b626c8a565 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixPipeline.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixPipeline.java @@ -36,6 +36,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import jdk.jpackage.internal.util.PathUtils; /** * WiX pipeline. Compiles and links WiX sources. @@ -180,7 +181,7 @@ public class WixPipeline { } private Path compileWix3(WixSource wixSource) throws IOException { - Path wixObj = wixObjDir.toAbsolutePath().resolve(IOUtils.replaceSuffix( + Path wixObj = wixObjDir.toAbsolutePath().resolve(PathUtils.replaceSuffix( IOUtils.getFileName(wixSource.source), ".wixobj")); List cmdline = new ArrayList<>(List.of( diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixSourceConverter.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixSourceConverter.java index 7786d64a786..86ef70442dc 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixSourceConverter.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixSourceConverter.java @@ -52,6 +52,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stax.StAXResult; import javax.xml.transform.stream.StreamSource; import jdk.jpackage.internal.WixToolset.WixToolsetType; +import jdk.jpackage.internal.util.XmlUtils; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -98,7 +99,7 @@ final class WixSourceConverter { Document inputXmlDom; try { - inputXmlDom = IOUtils.initDocumentBuilder().parse(new ByteArrayInputStream(buf)); + inputXmlDom = XmlUtils.initDocumentBuilder().parse(new ByteArrayInputStream(buf)); } catch (SAXException ex) { // Malformed XML, don't run converter, save as is. resource.saveToFile(resourceSaveAsFile); diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixTool.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixTool.java index f16b28edf24..ee98327b032 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixTool.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixTool.java @@ -41,6 +41,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.jpackage.internal.WixToolset.WixToolsetType; +import jdk.jpackage.internal.util.PathUtils; /** * WiX tool. @@ -51,7 +52,7 @@ public enum WixTool { Wix4("wix", DottedVersion.lazy("4.0.4")); WixTool(String commandName, DottedVersion minimalVersion) { - this.toolFileName = IOUtils.addSuffix(Path.of(commandName), ".exe"); + this.toolFileName = PathUtils.addSuffix(Path.of(commandName), ".exe"); this.minimalVersion = minimalVersion; } diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixUiFragmentBuilder.java b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixUiFragmentBuilder.java index 4f39a65e3b6..5eb23fc58c4 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixUiFragmentBuilder.java +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WixUiFragmentBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024, 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 @@ -39,7 +39,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import jdk.jpackage.internal.IOUtils.XmlConsumer; +import jdk.jpackage.internal.util.XmlConsumer; import static jdk.jpackage.internal.OverridableResource.createResource; import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE; import jdk.jpackage.internal.WixAppImageFragmentBuilder.ShortcutsFolder; diff --git a/test/jdk/tools/jpackage/TEST.properties b/test/jdk/tools/jpackage/TEST.properties index e01036f0ed3..a34532d6695 100644 --- a/test/jdk/tools/jpackage/TEST.properties +++ b/test/jdk/tools/jpackage/TEST.properties @@ -12,4 +12,6 @@ maxOutputSize=2000000 exclusiveAccess.dirs=share windows modules=jdk.jpackage/jdk.jpackage.internal:+open \ + jdk.jpackage/jdk.jpackage.internal.util \ + jdk.jpackage/jdk.jpackage.internal.util.function \ java.base/jdk.internal.util diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/AnnotationsTest.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/AnnotationsTest.java index 2d23f49cdd7..230b14fd1ea 100644 --- a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/AnnotationsTest.java +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/AnnotationsTest.java @@ -40,7 +40,7 @@ import jdk.jpackage.test.Annotations.Parameter; import jdk.jpackage.test.Annotations.ParameterSupplier; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; -import static jdk.jpackage.test.Functional.ThrowingSupplier.toSupplier; +import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; /* * @test diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java index 3f55c3c50ae..98a7d873190 100644 --- a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java @@ -37,9 +37,9 @@ import java.util.Objects; import java.util.stream.Stream; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Functional.ThrowingRunnable; -import static jdk.jpackage.test.Functional.ThrowingRunnable.toRunnable; -import static jdk.jpackage.test.Functional.ThrowingSupplier.toSupplier; +import jdk.jpackage.internal.util.function.ThrowingRunnable; +import static jdk.jpackage.internal.util.function.ThrowingRunnable.toRunnable; +import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; public class TKitTest { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java index 6c388ac77ff..70b0e160d24 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -37,8 +37,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.test.Functional.ThrowingBiConsumer; -import static jdk.jpackage.test.Functional.ThrowingFunction.toFunction; +import static jdk.jpackage.internal.util.function.ExceptionBox.rethrowUnchecked; +import jdk.jpackage.internal.util.function.ThrowingBiConsumer; +import static jdk.jpackage.internal.util.function.ThrowingFunction.toFunction; public class AdditionalLauncher { @@ -48,12 +49,12 @@ public class AdditionalLauncher { setPersistenceHandler(null); } - final public AdditionalLauncher setDefaultArguments(String... v) { + public final AdditionalLauncher setDefaultArguments(String... v) { defaultArguments = new ArrayList<>(List.of(v)); return this; } - final public AdditionalLauncher addDefaultArguments(String... v) { + public final AdditionalLauncher addDefaultArguments(String... v) { if (defaultArguments == null) { return setDefaultArguments(v); } @@ -62,12 +63,12 @@ public class AdditionalLauncher { return this; } - final public AdditionalLauncher setJavaOptions(String... v) { + public final AdditionalLauncher setJavaOptions(String... v) { javaOptions = new ArrayList<>(List.of(v)); return this; } - final public AdditionalLauncher addJavaOptions(String... v) { + public final AdditionalLauncher addJavaOptions(String... v) { if (javaOptions == null) { return setJavaOptions(v); } @@ -76,27 +77,27 @@ public class AdditionalLauncher { return this; } - final public AdditionalLauncher setVerifyUninstalled(boolean value) { + public final AdditionalLauncher setVerifyUninstalled(boolean value) { verifyUninstalled = value; return this; } - final public AdditionalLauncher setLauncherAsService() { + public final AdditionalLauncher setLauncherAsService() { return addRawProperties(LAUNCHER_AS_SERVICE); } - final public AdditionalLauncher addRawProperties( + public final AdditionalLauncher addRawProperties( Map.Entry... v) { return addRawProperties(List.of(v)); } - final public AdditionalLauncher addRawProperties( + public final AdditionalLauncher addRawProperties( Collection> v) { rawProperties.addAll(v); return this; } - final public String getRawPropertyValue( + public final String getRawPropertyValue( String key, Supplier getDefault) { return rawProperties.stream() .filter(item -> item.getKey().equals(key)) @@ -108,13 +109,13 @@ public class AdditionalLauncher { "--description", unused -> cmd.name())); } - final public AdditionalLauncher setShortcuts(boolean menu, boolean shortcut) { + public final AdditionalLauncher setShortcuts(boolean menu, boolean shortcut) { withMenuShortcut = menu; withShortcut = shortcut; return this; } - final public AdditionalLauncher setIcon(Path iconPath) { + public final AdditionalLauncher setIcon(Path iconPath) { if (iconPath == NO_ICON) { throw new IllegalArgumentException(); } @@ -123,12 +124,12 @@ public class AdditionalLauncher { return this; } - final public AdditionalLauncher setNoIcon() { + public final AdditionalLauncher setNoIcon() { icon = NO_ICON; return this; } - final public AdditionalLauncher setPersistenceHandler( + public final AdditionalLauncher setPersistenceHandler( ThrowingBiConsumer>> handler) { if (handler != null) { createFileHandler = ThrowingBiConsumer.toBiConsumer(handler); @@ -138,12 +139,12 @@ public class AdditionalLauncher { return this; } - final public void applyTo(JPackageCommand cmd) { + public final void applyTo(JPackageCommand cmd) { cmd.addPrerequisiteAction(this::initialize); cmd.addVerifyAction(this::verify); } - final public void applyTo(PackageTest test) { + public final void applyTo(PackageTest test) { test.addInitializer(this::initialize); test.addInstallVerifier(this::verify); if (verifyUninstalled) { @@ -151,7 +152,7 @@ public class AdditionalLauncher { } } - final public void verifyRemovedInUpgrade(PackageTest test) { + public final void verifyRemovedInUpgrade(PackageTest test) { test.addInstallVerifier(this::verifyUninstalled); } @@ -189,7 +190,7 @@ public class AdditionalLauncher { propsFile = TKit.createTempFile(propsFile); TKit.deleteIfExists(propsFile); } catch (IOException ex) { - Functional.rethrowUnchecked(ex); + rethrowUnchecked(ex); } } @@ -446,7 +447,7 @@ public class AdditionalLauncher { private Boolean withMenuShortcut; private Boolean withShortcut; - private final static Path NO_ICON = Path.of(""); - private final static Map.Entry LAUNCHER_AS_SERVICE = Map.entry( + private static final Path NO_ICON = Path.of(""); + private static final Map.Entry LAUNCHER_AS_SERVICE = Map.entry( "launcher-as-service", "true"); } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java index 72ebb64a142..f182f4f7f7d 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -42,7 +42,7 @@ import java.util.regex.Pattern; import java.util.spi.ToolProvider; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.test.Functional.ThrowingSupplier; +import jdk.jpackage.internal.util.function.ThrowingSupplier; public final class Executor extends CommandArguments { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/FileAssociations.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/FileAssociations.java index 49085197828..091a2206b17 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/FileAssociations.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/FileAssociations.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -32,10 +32,10 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import jdk.jpackage.internal.IOUtils; +import jdk.jpackage.internal.util.PathUtils; -final public class FileAssociations { +public final class FileAssociations { public FileAssociations(String faSuffixName) { suffixName = faSuffixName; setFilename("fa"); @@ -79,7 +79,7 @@ final public class FileAssociations { if (icon == null) { return null; } - return Path.of(getMime().replace('/', '-') + IOUtils.getSuffix(icon)); + return Path.of(getMime().replace('/', '-') + PathUtils.getSuffix(icon)); } Path getPropertiesFile() { @@ -243,7 +243,7 @@ final public class FileAssociations { } private Path file; - final private String suffixName; + private final String suffixName; private String description; private Path icon; private Collection testRuns; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java index a57caa92cb2..a974670b8e4 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java @@ -31,84 +31,6 @@ import java.util.function.Supplier; public class Functional { - @FunctionalInterface - public interface ThrowingConsumer { - void accept(T t) throws Throwable; - - public static Consumer toConsumer(ThrowingConsumer v) { - return o -> { - try { - v.accept(o); - } catch (Throwable ex) { - rethrowUnchecked(ex); - } - }; - } - } - - @FunctionalInterface - public interface ThrowingBiConsumer { - void accept(T t, U u) throws Throwable; - - public static BiConsumer toBiConsumer(ThrowingBiConsumer v) { - return (t, u) -> { - try { - v.accept(t, u); - } catch (Throwable ex) { - rethrowUnchecked(ex); - } - }; - } - } - - @FunctionalInterface - public interface ThrowingSupplier { - T get() throws Throwable; - - public static Supplier toSupplier(ThrowingSupplier v) { - return () -> { - try { - return v.get(); - } catch (Throwable ex) { - rethrowUnchecked(ex); - } - // Unreachable - return null; - }; - } - } - - @FunctionalInterface - public interface ThrowingFunction { - R apply(T t) throws Throwable; - - public static Function toFunction(ThrowingFunction v) { - return (t) -> { - try { - return v.apply(t); - } catch (Throwable ex) { - rethrowUnchecked(ex); - } - // Unreachable - return null; - }; - } - } - - @FunctionalInterface - public interface ThrowingRunnable { - void run() throws Throwable; - - public static Runnable toRunnable(ThrowingRunnable v) { - return () -> { - try { - v.run(); - } catch (Throwable ex) { - rethrowUnchecked(ex); - } - }; - } - } public static Supplier identity(Supplier v) { return v; @@ -141,28 +63,4 @@ public class Functional { public static Predicate identityPredicate(Predicate v) { return v; } - - public static class ExceptionBox extends RuntimeException { - public ExceptionBox(Throwable throwable) { - super(throwable); - } - } - - @SuppressWarnings("unchecked") - public static RuntimeException rethrowUnchecked(Throwable throwable) throws - ExceptionBox { - if (throwable instanceof RuntimeException err) { - throw err; - } - - if (throwable instanceof Error err) { - throw err; - } - - if (throwable instanceof InvocationTargetException err) { - throw rethrowUnchecked(err.getCause()); - } - - throw new ExceptionBox(throwable); - } } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java index bc722e7acd9..bc35912bcbb 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java @@ -40,9 +40,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingFunction; -import jdk.jpackage.test.Functional.ThrowingSupplier; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingFunction; +import jdk.jpackage.internal.util.function.ThrowingSupplier; public final class HelloApp { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java index 49eeb25a00e..4239d8a87c8 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java @@ -45,15 +45,15 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.internal.IOUtils; import jdk.jpackage.internal.AppImageFile; import jdk.jpackage.internal.ApplicationLayout; import jdk.jpackage.internal.PackageFile; +import jdk.jpackage.internal.util.XmlUtils; import static jdk.jpackage.test.AdditionalLauncher.forEachAdditionalLauncher; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingFunction; -import jdk.jpackage.test.Functional.ThrowingRunnable; -import jdk.jpackage.test.Functional.ThrowingSupplier; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingFunction; +import jdk.jpackage.internal.util.function.ThrowingRunnable; +import jdk.jpackage.internal.util.function.ThrowingSupplier; /** * jpackage command line with prerequisite actions. Prerequisite actions can be @@ -315,7 +315,7 @@ public final class JPackageCommand extends CommandArguments { "Error: --app-image expected"); })); - IOUtils.createXml(jpackageXMLFile, xml -> { + XmlUtils.createXml(jpackageXMLFile, xml -> { xml.writeStartElement("jpackage-state"); xml.writeAttribute("version", AppImageFile.getVersion()); xml.writeAttribute("platform", AppImageFile.getPlatform()); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherAsServiceVerifier.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherAsServiceVerifier.java index 026da0df0eb..d73029ab153 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherAsServiceVerifier.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherAsServiceVerifier.java @@ -35,8 +35,10 @@ import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.internal.IOUtils; -import static jdk.jpackage.test.Functional.ThrowingConsumer.toConsumer; +import jdk.jpackage.internal.util.PathUtils; +import jdk.jpackage.internal.util.function.ThrowingBiConsumer; +import static jdk.jpackage.internal.util.function.ThrowingConsumer.toConsumer; +import jdk.jpackage.internal.util.function.ThrowingRunnable; import static jdk.jpackage.test.PackageType.LINUX; import static jdk.jpackage.test.PackageType.MAC_PKG; import static jdk.jpackage.test.PackageType.WINDOWS; @@ -187,7 +189,7 @@ public final class LauncherAsServiceVerifier { } AdditionalLauncher.forEachAdditionalLauncher(cmd, - Functional.ThrowingBiConsumer.toBiConsumer( + ThrowingBiConsumer.toBiConsumer( (launcherName, propFilePath) -> { if (Files.readAllLines(propFilePath).stream().anyMatch( line -> { @@ -335,14 +337,14 @@ public final class LauncherAsServiceVerifier { TKit.assertEquals(installedLauncherPath.toString(), args.get(0), "Check path to launcher in 'ProgramArguments' property in the property file"); - var expectedLabel = IOUtils.replaceSuffix(servicePlistFile.getFileName(), "").toString(); + var expectedLabel = PathUtils.replaceSuffix(servicePlistFile.getFileName(), "").toString(); TKit.assertEquals(expectedLabel, servicePlist.queryValue("Label"), "Check value of 'Label' property in the property file"); } private static void delayInstallVerify() { // Sleep a bit to let system launch the service - Functional.ThrowingRunnable.toRunnable(() -> Thread.sleep(5 * 1000)).run(); + ThrowingRunnable.toRunnable(() -> Thread.sleep(5 * 1000)).run(); } private Path appOutputFilePathInitialize() { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java index 2de2e002a94..39e483f1fee 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LauncherIconVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -31,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; import javax.imageio.ImageIO; +import static jdk.jpackage.internal.util.function.ExceptionBox.rethrowUnchecked; public final class LauncherIconVerifier { public LauncherIconVerifier() { @@ -176,7 +177,7 @@ public final class LauncherIconVerifier { iconSwapWrapper.setAccessible(true); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException ex) { - throw Functional.rethrowUnchecked(ex); + throw rethrowUnchecked(ex); } } @@ -254,14 +255,14 @@ public final class LauncherIconVerifier { } } } catch (IllegalAccessException | InvocationTargetException ex) { - throw Functional.rethrowUnchecked(ex); + throw rethrowUnchecked(ex); } } finally { launcherPath.toFile().setWritable(false, true); } } - final static WinIconVerifier instance = new WinIconVerifier(); + static final WinIconVerifier instance = new WinIconVerifier(); private final Class executableRebranderClass; private final Method lockResource; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java index a96bab49355..35baff3d5db 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java @@ -41,8 +41,8 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.jpackage.internal.ApplicationLayout; -import jdk.jpackage.internal.IOUtils; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.PathUtils; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import jdk.jpackage.test.PackageTest.PackageHandlers; @@ -578,7 +578,7 @@ public final class LinuxHelper { private static void verifyIconInScriptlet(Scriptlet scriptletType, List scriptletBody, Path iconPathInPackage) { - final String dashMime = IOUtils.replaceSuffix( + final String dashMime = PathUtils.replaceSuffix( iconPathInPackage.getFileName(), null).toString(); final String xdgCmdName = "xdg-icon-resource"; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java index 63afb6cf9f7..9cadd419ca1 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java @@ -43,11 +43,11 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; -import jdk.jpackage.internal.IOUtils; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingSupplier; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingSupplier; import jdk.jpackage.test.PackageTest.PackageHandlers; import jdk.jpackage.internal.RetryExecutor; +import jdk.jpackage.internal.util.PathUtils; import org.xml.sax.SAXException; import org.w3c.dom.NodeList; @@ -212,7 +212,7 @@ public final class MacHelper { // Unpack all ".pkg" files from $dataDir folder in $unpackDir folder try (var dataListing = Files.list(dataDir)) { dataListing.filter(file -> { - return ".pkg".equals(IOUtils.getSuffix(file.getFileName())); + return ".pkg".equals(PathUtils.getSuffix(file.getFileName())); }).forEach(ThrowingConsumer.toConsumer(pkgDir -> { // Installation root of the package is stored in // /pkg-info@install-location attribute in $pkgDir/PackageInfo xml file diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MethodCall.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MethodCall.java index d5b8bd702c8..51a8ade8a1d 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MethodCall.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MethodCall.java @@ -37,7 +37,7 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.IntStream; import java.util.stream.Stream; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import jdk.jpackage.test.TestInstance.TestDesc; class MethodCall implements ThrowingConsumer { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java index 6f486425e73..7c6aab29fee 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java @@ -46,13 +46,13 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; import jdk.jpackage.internal.ApplicationLayout; -import jdk.jpackage.test.Functional.ThrowingBiConsumer; -import static jdk.jpackage.test.Functional.ThrowingBiConsumer.toBiConsumer; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import static jdk.jpackage.test.Functional.ThrowingConsumer.toConsumer; -import jdk.jpackage.test.Functional.ThrowingRunnable; -import static jdk.jpackage.test.Functional.ThrowingSupplier.toSupplier; -import static jdk.jpackage.test.Functional.rethrowUnchecked; +import jdk.jpackage.internal.util.function.ThrowingBiConsumer; +import static jdk.jpackage.internal.util.function.ThrowingBiConsumer.toBiConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import static jdk.jpackage.internal.util.function.ThrowingConsumer.toConsumer; +import jdk.jpackage.internal.util.function.ThrowingRunnable; +import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; +import static jdk.jpackage.internal.util.function.ExceptionBox.rethrowUnchecked; import static jdk.jpackage.test.PackageType.LINUX; import static jdk.jpackage.test.PackageType.LINUX_DEB; import static jdk.jpackage.test.PackageType.LINUX_RPM; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java index 71637ef7134..8aa7d005adb 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageType.java @@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.jpackage.internal.Log; +import static jdk.jpackage.internal.util.function.ExceptionBox.rethrowUnchecked; /** * jpackage type traits. @@ -103,7 +104,7 @@ public enum PackageType { } catch (ClassNotFoundException | IllegalAccessException ex) { } catch (InstantiationException | NoSuchMethodException | InvocationTargetException ex) { - Functional.rethrowUnchecked(ex); + rethrowUnchecked(ex); } return false; } @@ -127,7 +128,7 @@ public enum PackageType { thread.run(); thread.join(); } catch (InterruptedException ex) { - Functional.rethrowUnchecked(ex); + rethrowUnchecked(ex); } return reply.get(); } @@ -136,15 +137,15 @@ public enum PackageType { private final String suffix; private final boolean supported; - public final static Set LINUX = Set.of(LINUX_DEB, LINUX_RPM); - public final static Set WINDOWS = Set.of(WIN_EXE, WIN_MSI); - public final static Set MAC = Set.of(MAC_PKG, MAC_DMG); - public final static Set NATIVE = Stream.concat( + public static final Set LINUX = Set.of(LINUX_DEB, LINUX_RPM); + public static final Set WINDOWS = Set.of(WIN_EXE, WIN_MSI); + public static final Set MAC = Set.of(MAC_PKG, MAC_DMG); + public static final Set NATIVE = Stream.concat( Stream.concat(LINUX.stream(), WINDOWS.stream()), MAC.stream()).collect(Collectors.toUnmodifiableSet()); - private final static class Inner { - private final static Set DISABLED_PACKAGERS = Optional.ofNullable( + private static final class Inner { + private static final Set DISABLED_PACKAGERS = Optional.ofNullable( TKit.tokenizeConfigProperty("disabledPackagers")).orElse( TKit.isLinuxAPT() ? Set.of("rpm") : Collections.emptySet()); } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java index 8f91d581ef1..b5859564568 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java @@ -61,10 +61,10 @@ import java.util.stream.Collectors; import static java.util.stream.Collectors.toSet; import java.util.stream.Stream; import jdk.internal.util.OperatingSystem; -import jdk.jpackage.test.Functional.ExceptionBox; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingRunnable; -import jdk.jpackage.test.Functional.ThrowingSupplier; +import jdk.jpackage.internal.util.function.ExceptionBox; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingRunnable; +import jdk.jpackage.internal.util.function.ThrowingSupplier; public final class TKit { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java index c2fc1789a25..23fd5dd52a5 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestBuilder.java @@ -40,9 +40,9 @@ import java.util.stream.Stream; import jdk.jpackage.test.Annotations.AfterEach; import jdk.jpackage.test.Annotations.BeforeEach; import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import static jdk.jpackage.test.Functional.ThrowingConsumer.toConsumer; -import jdk.jpackage.test.Functional.ThrowingFunction; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import static jdk.jpackage.internal.util.function.ThrowingConsumer.toConsumer; +import jdk.jpackage.internal.util.function.ThrowingFunction; import jdk.jpackage.test.TestMethodSupplier.InvalidAnnotationException; import static jdk.jpackage.test.TestMethodSupplier.MethodQuery.fromQualifiedMethodName; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestInstance.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestInstance.java index f619c9e222e..871ddc24277 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestInstance.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestInstance.java @@ -40,9 +40,10 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingFunction; -import jdk.jpackage.test.Functional.ThrowingRunnable; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingFunction; +import jdk.jpackage.internal.util.function.ThrowingRunnable; +import jdk.jpackage.internal.util.function.ThrowingSupplier; final class TestInstance implements ThrowingRunnable { @@ -258,7 +259,7 @@ final class TestInstance implements ThrowingRunnable { StackTraceElement st[] = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : st) { if ("main".equals(ste.getMethodName())) { - return Functional.ThrowingSupplier.toSupplier(() -> Class.forName( + return ThrowingSupplier.toSupplier(() -> Class.forName( ste.getClassName())).get(); } } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestMethodSupplier.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestMethodSupplier.java index 83b1c19bd95..0d701d0ec6f 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestMethodSupplier.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TestMethodSupplier.java @@ -49,8 +49,8 @@ import jdk.jpackage.test.Annotations.ParameterSupplier; import jdk.jpackage.test.Annotations.ParameterSupplierGroup; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; -import static jdk.jpackage.test.Functional.ThrowingFunction.toFunction; -import static jdk.jpackage.test.Functional.ThrowingSupplier.toSupplier; +import static jdk.jpackage.internal.util.function.ThrowingFunction.toFunction; +import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; import static jdk.jpackage.test.MethodCall.mapArgs; final class TestMethodSupplier { diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java index 1976a5cf72c..42ea9e3e9a7 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java @@ -36,7 +36,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.jpackage.test.Functional.ThrowingRunnable; +import jdk.jpackage.internal.util.function.ThrowingRunnable; import jdk.jpackage.test.PackageTest.PackageHandlers; public class WindowsHelper { diff --git a/test/jdk/tools/jpackage/linux/AppAboutUrlTest.java b/test/jdk/tools/jpackage/linux/AppAboutUrlTest.java index 0d8f0ec4805..aef46e29725 100644 --- a/test/jdk/tools/jpackage/linux/AppAboutUrlTest.java +++ b/test/jdk/tools/jpackage/linux/AppAboutUrlTest.java @@ -22,7 +22,7 @@ */ import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.PackageType; diff --git a/test/jdk/tools/jpackage/share/AppContentTest.java b/test/jdk/tools/jpackage/share/AppContentTest.java index e056070a5fc..d33960092ee 100644 --- a/test/jdk/tools/jpackage/share/AppContentTest.java +++ b/test/jdk/tools/jpackage/share/AppContentTest.java @@ -33,8 +33,8 @@ import java.util.Collection; import java.util.List; import static java.util.stream.Collectors.joining; import java.util.stream.Stream; -import jdk.jpackage.internal.IOUtils; -import jdk.jpackage.test.Functional.ThrowingFunction; +import jdk.jpackage.internal.util.FileUtils; +import jdk.jpackage.internal.util.function.ThrowingFunction; import jdk.jpackage.test.JPackageCommand; @@ -65,7 +65,7 @@ public class AppContentTest { // In particular, random files should be placed in "Contents/Resources" folder // otherwise "codesign" will fail to sign. // Need to prepare arguments for `--app-content` accordingly. - private final static boolean copyInResources = TKit.isOSX(); + private static final boolean copyInResources = TKit.isOSX(); private final List testPathArgs; @@ -148,7 +148,7 @@ public class AppContentTest { var srcPath = TKit.TEST_SRC_ROOT.resolve(appContentPath); var dstPath = appContentArg.resolve(srcPath.getFileName()); Files.createDirectories(dstPath.getParent()); - IOUtils.copyRecursive(srcPath, dstPath); + FileUtils.copyRecursive(srcPath, dstPath); return appContentArg; } diff --git a/test/jdk/tools/jpackage/share/BasicTest.java b/test/jdk/tools/jpackage/share/BasicTest.java index 61668b9e878..c6e4e930155 100644 --- a/test/jdk/tools/jpackage/share/BasicTest.java +++ b/test/jdk/tools/jpackage/share/BasicTest.java @@ -41,7 +41,7 @@ import jdk.jpackage.test.Executor; import jdk.jpackage.test.JavaTool; import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.Annotations.Parameter; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import static jdk.jpackage.test.RunnablePackageTest.Action.CREATE_AND_UNPACK; /* diff --git a/test/jdk/tools/jpackage/share/IconTest.java b/test/jdk/tools/jpackage/share/IconTest.java index 2d6469f5f2e..d5edbc93245 100644 --- a/test/jdk/tools/jpackage/share/IconTest.java +++ b/test/jdk/tools/jpackage/share/IconTest.java @@ -41,8 +41,8 @@ import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.Executor; import jdk.jpackage.test.LinuxHelper; import jdk.jpackage.test.AdditionalLauncher; -import jdk.jpackage.test.Functional.ThrowingConsumer; -import jdk.jpackage.test.Functional.ThrowingBiConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingBiConsumer; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; @@ -428,7 +428,7 @@ public class IconTest { private final Path cmdlineIcon; private final Path resourceDirIcon; - private final static Set PRIMARY = Set.of(Main, Additional); + private static final Set PRIMARY = Set.of(Main, Additional); } private final boolean appImage; @@ -440,7 +440,7 @@ public class IconTest { + TKit.ICON_SUFFIX)); } - private final static Path[] ICONS = Stream.of("icon", "icon2", "icon3", + private static final Path[] ICONS = Stream.of("icon", "icon2", "icon3", "icon4") .map(IconTest::iconPath) .collect(Collectors.toList()).toArray(Path[]::new); diff --git a/test/jdk/tools/jpackage/share/InOutPathTest.java b/test/jdk/tools/jpackage/share/InOutPathTest.java index 15d96283ef4..b2579133148 100644 --- a/test/jdk/tools/jpackage/share/InOutPathTest.java +++ b/test/jdk/tools/jpackage/share/InOutPathTest.java @@ -36,7 +36,7 @@ import jdk.jpackage.internal.ApplicationLayout; import jdk.jpackage.internal.PackageFile; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.JPackageCommand.AppLayoutAssert; import jdk.jpackage.test.PackageTest; diff --git a/test/jdk/tools/jpackage/share/MainClassTest.java b/test/jdk/tools/jpackage/share/MainClassTest.java index d9188e8f18f..a031bbc2788 100644 --- a/test/jdk/tools/jpackage/share/MainClassTest.java +++ b/test/jdk/tools/jpackage/share/MainClassTest.java @@ -44,7 +44,7 @@ import jdk.jpackage.test.JavaTool; import jdk.jpackage.test.Annotations.Parameters; import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.CfgFile; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; diff --git a/test/jdk/tools/jpackage/share/PerUserCfgTest.java b/test/jdk/tools/jpackage/share/PerUserCfgTest.java index 0fff7eb3a2d..2e62aa5c5d6 100644 --- a/test/jdk/tools/jpackage/share/PerUserCfgTest.java +++ b/test/jdk/tools/jpackage/share/PerUserCfgTest.java @@ -29,7 +29,7 @@ import java.util.Optional; import jdk.jpackage.test.AdditionalLauncher; import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Functional.ThrowingConsumer; +import jdk.jpackage.internal.util.function.ThrowingConsumer; import jdk.jpackage.test.HelloApp; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.LinuxHelper; diff --git a/test/jdk/tools/jpackage/share/RuntimeImageSymbolicLinksTest.java b/test/jdk/tools/jpackage/share/RuntimeImageSymbolicLinksTest.java index 0e48df630af..649ac0a3695 100644 --- a/test/jdk/tools/jpackage/share/RuntimeImageSymbolicLinksTest.java +++ b/test/jdk/tools/jpackage/share/RuntimeImageSymbolicLinksTest.java @@ -21,20 +21,11 @@ * questions. */ -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; import jdk.jpackage.internal.ApplicationLayout; import jdk.jpackage.test.TKit; -import jdk.jpackage.test.PackageTest; -import jdk.jpackage.test.PackageType; -import jdk.jpackage.test.Functional; import jdk.jpackage.test.Annotations.Test; -import jdk.jpackage.test.Annotations.Parameter; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.JavaTool; import jdk.jpackage.test.Executor; diff --git a/test/jdk/tools/jpackage/windows/WinLongVersionTest.java b/test/jdk/tools/jpackage/windows/WinLongVersionTest.java index 0d52da65630..7a915b5c123 100644 --- a/test/jdk/tools/jpackage/windows/WinLongVersionTest.java +++ b/test/jdk/tools/jpackage/windows/WinLongVersionTest.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Set; import java.util.UUID; import java.util.function.Supplier; import javax.xml.transform.Result; @@ -36,7 +35,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; -import jdk.jpackage.internal.IOUtils; +import jdk.jpackage.internal.util.XmlUtils; import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.Executor; import jdk.jpackage.test.PackageTest; @@ -148,7 +147,7 @@ public class WinLongVersionTest { Path scriptPath = resourceDir.resolve(String.format( "%s-post-msi.wsf", cmd.name())); - IOUtils.createXml(scriptPath, xml -> { + XmlUtils.createXml(scriptPath, xml -> { xml.writeStartElement("job"); xml.writeAttribute("id", "main"); xml.writeStartElement("script"); @@ -194,7 +193,7 @@ public class WinLongVersionTest { cmd.setFakeRuntime(); // Create package without Upgrade table - Document doc = IOUtils.initDocumentBuilder().parse( + Document doc = XmlUtils.initDocumentBuilder().parse( Files.newInputStream(TKit.SRC_ROOT.resolve( "windows/classes/jdk/jpackage/internal/resources/main.wxs"))); XPath xPath = XPathFactory.newInstance().newXPath(); diff --git a/test/jdk/tools/jpackage/windows/WinScriptTest.java b/test/jdk/tools/jpackage/windows/WinScriptTest.java index 296da482bb0..98b4922826d 100644 --- a/test/jdk/tools/jpackage/windows/WinScriptTest.java +++ b/test/jdk/tools/jpackage/windows/WinScriptTest.java @@ -24,8 +24,7 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; -import java.util.ArrayList; -import jdk.jpackage.internal.IOUtils; +import jdk.jpackage.internal.util.XmlUtils; import jdk.jpackage.test.TKit; import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.PackageType; @@ -147,7 +146,7 @@ public class WinScriptTest { } void createScript(JPackageCommand cmd) throws IOException { - IOUtils.createXml(Path.of(cmd.getArgumentValue("--resource-dir"), + XmlUtils.createXml(Path.of(cmd.getArgumentValue("--resource-dir"), String.format("%s-%s.wsf", cmd.name(), scriptSuffixName)), xml -> { xml.writeStartElement("job"); xml.writeAttribute("id", "main");