--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -429,19 +429,19 @@
if (!StandardBundlerParam.isRuntimeInstaller(params)) {
// prepare desktop shortcut
- Writer w = new BufferedWriter(new FileWriter(
+ try (Writer w = Files.newBufferedWriter(
getConfig_DesktopShortcutFile(
- rootDir, addLauncher)));
- String content = preprocessTextResource(
- getConfig_DesktopShortcutFile(rootDir,
- addLauncher).getName(),
- I18N.getString("resource.menu-shortcut-descriptor"),
- DEFAULT_DESKTOP_FILE_TEMPLATE,
- addLauncherData,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ rootDir, addLauncher).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_DesktopShortcutFile(rootDir,
+ addLauncher).getName(),
+ I18N.getString("resource.menu-shortcut-descriptor"),
+ DEFAULT_DESKTOP_FILE_TEMPLATE,
+ addLauncherData,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
}
// prepare installer icon
@@ -618,10 +618,10 @@
mimeInfo.append("</mime-info>");
if (addedEntry) {
- Writer w = new BufferedWriter(new FileWriter(
- new File(rootDir, mimeInfoFile)));
- w.write(mimeInfo.toString());
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ new File(rootDir, mimeInfoFile).toPath())) {
+ w.write(mimeInfo.toString());
+ }
data.put("FILE_ASSOCIATION_INSTALL", registrations.toString());
data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString());
data.put("DESKTOP_MIMES", desktopMimes.toString());
@@ -630,92 +630,95 @@
if (!StandardBundlerParam.isRuntimeInstaller(params)) {
//prepare desktop shortcut
- Writer w = new BufferedWriter(new FileWriter(
- getConfig_DesktopShortcutFile(rootDir, params)));
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_DesktopShortcutFile(rootDir, params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_DesktopShortcutFile(
+ rootDir, params).getName(),
+ I18N.getString("resource.menu-shortcut-descriptor"),
+ DEFAULT_DESKTOP_FILE_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
+ }
+ // prepare control file
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_ControlFile(params).toPath())) {
String content = preprocessTextResource(
- getConfig_DesktopShortcutFile(
- rootDir, params).getName(),
- I18N.getString("resource.menu-shortcut-descriptor"),
- DEFAULT_DESKTOP_FILE_TEMPLATE,
+ getConfig_ControlFile(params).getName(),
+ I18N.getString("resource.deb-control-file"),
+ DEFAULT_CONTROL_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
+
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_PreinstallFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_PreinstallFile(params).getName(),
+ I18N.getString("resource.deb-preinstall-script"),
+ DEFAULT_PREINSTALL_TEMPLATE,
data,
VERBOSE.fetchFrom(params),
RESOURCE_DIR.fetchFrom(params));
w.write(content);
- w.close();
}
- // prepare control file
- Writer w = new BufferedWriter(new FileWriter(
- getConfig_ControlFile(params)));
- String content = preprocessTextResource(
- getConfig_ControlFile(params).getName(),
- I18N.getString("resource.deb-control-file"),
- DEFAULT_CONTROL_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
-
- w = new BufferedWriter(new FileWriter(
- getConfig_PreinstallFile(params)));
- content = preprocessTextResource(
- getConfig_PreinstallFile(params).getName(),
- I18N.getString("resource.deb-preinstall-script"),
- DEFAULT_PREINSTALL_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
setPermissions(getConfig_PreinstallFile(params), "rwxr-xr-x");
- w = new BufferedWriter(new FileWriter(getConfig_PrermFile(params)));
- content = preprocessTextResource(
- getConfig_PrermFile(params).getName(),
- I18N.getString("resource.deb-prerm-script"),
- DEFAULT_PRERM_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_PrermFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_PrermFile(params).getName(),
+ I18N.getString("resource.deb-prerm-script"),
+ DEFAULT_PRERM_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
setPermissions(getConfig_PrermFile(params), "rwxr-xr-x");
- w = new BufferedWriter(new FileWriter(
- getConfig_PostinstallFile(params)));
- content = preprocessTextResource(
- getConfig_PostinstallFile(params).getName(),
- I18N.getString("resource.deb-postinstall-script"),
- DEFAULT_POSTINSTALL_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_PostinstallFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_PostinstallFile(params).getName(),
+ I18N.getString("resource.deb-postinstall-script"),
+ DEFAULT_POSTINSTALL_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
setPermissions(getConfig_PostinstallFile(params), "rwxr-xr-x");
- w = new BufferedWriter(new FileWriter(getConfig_PostrmFile(params)));
- content = preprocessTextResource(
- getConfig_PostrmFile(params).getName(),
- I18N.getString("resource.deb-postrm-script"),
- DEFAULT_POSTRM_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_PostrmFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_PostrmFile(params).getName(),
+ I18N.getString("resource.deb-postrm-script"),
+ DEFAULT_POSTRM_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
setPermissions(getConfig_PostrmFile(params), "rwxr-xr-x");
- w = new BufferedWriter(new FileWriter(getConfig_CopyrightFile(params)));
- content = preprocessTextResource(
- getConfig_CopyrightFile(params).getName(),
- I18N.getString("resource.deb-copyright-file"),
- DEFAULT_COPYRIGHT_TEMPLATE,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_CopyrightFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_CopyrightFile(params).getName(),
+ I18N.getString("resource.deb-copyright-file"),
+ DEFAULT_COPYRIGHT_TEMPLATE,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
return true;
}
--- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -343,17 +343,18 @@
addLauncherData.put("DESKTOP_MIMES", "");
// prepare desktop shortcut
- Writer w = new BufferedWriter(new FileWriter(
- getConfig_DesktopShortcutFile(rootDir, addLauncher)));
- String content = preprocessTextResource(
+ try (Writer w = Files.newBufferedWriter(
getConfig_DesktopShortcutFile(rootDir,
- addLauncher).getName(),
- I18N.getString("resource.menu-shortcut-descriptor"),
- DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ addLauncher).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_DesktopShortcutFile(rootDir,
+ addLauncher).getName(),
+ I18N.getString("resource.menu-shortcut-descriptor"),
+ DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
// prepare installer icon
iconTarget = getConfig_IconFile(rootDir, addLauncher);
@@ -532,10 +533,10 @@
mimeInfo.append("</mime-info>");
if (addedEntry) {
- Writer w = new BufferedWriter(new FileWriter(
- new File(rootDir, mimeInfoFile)));
- w.write(mimeInfo.toString());
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ new File(rootDir, mimeInfoFile).toPath())) {
+ w.write(mimeInfo.toString());
+ }
data.put("FILE_ASSOCIATION_INSTALL", registrations.toString());
data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString());
data.put("DESKTOP_MIMES", desktopMimes.toString());
@@ -544,30 +545,31 @@
if (!StandardBundlerParam.isRuntimeInstaller(params)) {
//prepare desktop shortcut
- Writer w = new BufferedWriter(new FileWriter(
- getConfig_DesktopShortcutFile(rootDir, params)));
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_DesktopShortcutFile(rootDir, params).toPath())) {
+ String content = preprocessTextResource(
+ getConfig_DesktopShortcutFile(rootDir,
+ params).getName(),
+ I18N.getString("resource.menu-shortcut-descriptor"),
+ DEFAULT_DESKTOP_FILE_TEMPLATE, data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
+ }
+
+ // prepare spec file
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_SpecFile(params).toPath())) {
String content = preprocessTextResource(
- getConfig_DesktopShortcutFile(rootDir, params).getName(),
- I18N.getString("resource.menu-shortcut-descriptor"),
- DEFAULT_DESKTOP_FILE_TEMPLATE, data,
+ getConfig_SpecFile(params).getName(),
+ I18N.getString("resource.rpm-spec-file"),
+ DEFAULT_SPEC_TEMPLATE, data,
VERBOSE.fetchFrom(params),
RESOURCE_DIR.fetchFrom(params));
w.write(content);
- w.close();
}
- // prepare spec file
- Writer w = new BufferedWriter(
- new FileWriter(getConfig_SpecFile(params)));
- String content = preprocessTextResource(
- getConfig_SpecFile(params).getName(),
- I18N.getString("resource.rpm-spec-file"),
- DEFAULT_SPEC_TEMPLATE, data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
-
return true;
}
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppImageBuilder.java Thu Jun 06 19:10:12 2019 -0400
@@ -476,14 +476,14 @@
data.put("CF_BUNDLE_VERSION", VERSION.fetchFrom(params));
data.put("CF_BUNDLE_SHORT_VERSION_STRING", VERSION.fetchFrom(params));
- Writer w = new BufferedWriter(new FileWriter(file));
- w.write(preprocessTextResource("Runtime-Info.plist",
- I18N.getString("resource.runtime-info-plist"),
- TEMPLATE_RUNTIME_INFO_PLIST,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params)));
- w.close();
+ try (Writer w = Files.newBufferedWriter(file.toPath())) {
+ w.write(preprocessTextResource("Runtime-Info.plist",
+ I18N.getString("resource.runtime-info-plist"),
+ TEMPLATE_RUNTIME_INFO_PLIST,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params)));
+ }
}
private void writeInfoPlist(File file) throws IOException {
@@ -690,22 +690,22 @@
data.put("DEPLOY_FILE_ASSOCIATIONS", associationData);
- Writer w = new BufferedWriter(new FileWriter(file));
- w.write(preprocessTextResource(
- // getConfig_InfoPlist(params).getName(),
- "Info.plist",
- I18N.getString("resource.app-info-plist"),
- TEMPLATE_INFO_PLIST_LITE,
- data, VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params)));
- w.close();
+ try (Writer w = Files.newBufferedWriter(file.toPath())) {
+ w.write(preprocessTextResource(
+ // getConfig_InfoPlist(params).getName(),
+ "Info.plist",
+ I18N.getString("resource.app-info-plist"),
+ TEMPLATE_INFO_PLIST_LITE,
+ data, VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params)));
+ }
}
private void writePkgInfo(File file) throws IOException {
//hardcoded as it does not seem we need to change it ever
String signature = "????";
- try (Writer out = new BufferedWriter(new FileWriter(file))) {
+ try (Writer out = Files.newBufferedWriter(file.toPath())) {
out.write(OS_TYPE_CODE + signature);
out.flush();
}
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacCertificate.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacCertificate.java Thu Jun 06 19:10:12 2019 -0400
@@ -34,6 +34,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.Files;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -78,19 +80,10 @@
IOUtils.exec(security, verbose, false, ps);
File output = File.createTempFile("tempfile", ".tmp");
- PrintStream p = new PrintStream(
- new BufferedOutputStream(
- new FileOutputStream(output, true)));
- BufferedReader bfReader = new BufferedReader(
- new InputStreamReader(
- new ByteArrayInputStream(baos.toByteArray())));
- String line = null;
- while((line = bfReader.readLine()) != null){
- p.println(line);
- }
+ Files.copy(new ByteArrayInputStream(baos.toByteArray()),
+ output.toPath(), StandardCopyOption.REPLACE_EXISTING);
- p.close();
result = output;
}
catch (IOException ignored) {}
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -105,12 +105,12 @@
data.put("DEPLOY_INSTALL_LOCATION", "(path to desktop folder)");
data.put("DEPLOY_INSTALL_NAME", "Desktop");
- Writer w = new BufferedWriter(new FileWriter(dmgSetup));
- w.write(preprocessTextResource(dmgSetup.getName(),
- I18N.getString("resource.dmg-setup-script"),
- DEFAULT_DMG_SETUP_SCRIPT, data, VERBOSE.fetchFrom(p),
- RESOURCE_DIR.fetchFrom(p)));
- w.close();
+ try (Writer w = Files.newBufferedWriter(dmgSetup.toPath())) {
+ w.write(preprocessTextResource(dmgSetup.getName(),
+ I18N.getString("resource.dmg-setup-script"),
+ DEFAULT_DMG_SETUP_SCRIPT, data, VERBOSE.fetchFrom(p),
+ RESOURCE_DIR.fetchFrom(p)));
+ }
}
private File getConfig_VolumeScript(Map<String, ? super Object> params) {
@@ -149,14 +149,14 @@
Map<String, String> data = new HashMap<>();
data.put("APPLICATION_LICENSE_TEXT", licenseInBase64);
- Writer w = new BufferedWriter(
- new FileWriter(getConfig_LicenseFile(params)));
- w.write(preprocessTextResource(
- getConfig_LicenseFile(params).getName(),
- I18N.getString("resource.license-setup"),
- DEFAULT_LICENSE_PLIST, data, VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params)));
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_LicenseFile(params).toPath())) {
+ w.write(preprocessTextResource(
+ getConfig_LicenseFile(params).getName(),
+ I18N.getString("resource.license-setup"),
+ DEFAULT_LICENSE_PLIST, data, VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params)));
+ }
} catch (IOException ex) {
Log.verbose(ex);
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -214,30 +214,30 @@
data.put("INSTALL_LOCATION", MAC_INSTALL_DIR.fetchFrom(params));
- Writer w = new BufferedWriter(
- new FileWriter(getScripts_PreinstallFile(params)));
- String content = preprocessTextResource(
- getScripts_PreinstallFile(params).getName(),
- I18N.getString("resource.pkg-preinstall-script"),
- TEMPLATE_PREINSTALL_SCRIPT,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getScripts_PreinstallFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getScripts_PreinstallFile(params).getName(),
+ I18N.getString("resource.pkg-preinstall-script"),
+ TEMPLATE_PREINSTALL_SCRIPT,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
getScripts_PreinstallFile(params).setExecutable(true, false);
- w = new BufferedWriter(
- new FileWriter(getScripts_PostinstallFile(params)));
- content = preprocessTextResource(
- getScripts_PostinstallFile(params).getName(),
- I18N.getString("resource.pkg-postinstall-script"),
- TEMPLATE_POSTINSTALL_SCRIPT,
- data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = Files.newBufferedWriter(
+ getScripts_PostinstallFile(params).toPath())) {
+ String content = preprocessTextResource(
+ getScripts_PostinstallFile(params).getName(),
+ I18N.getString("resource.pkg-postinstall-script"),
+ TEMPLATE_POSTINSTALL_SCRIPT,
+ data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
getScripts_PostinstallFile(params).setExecutable(true, false);
}
@@ -248,57 +248,58 @@
Log.verbose(MessageFormat.format(I18N.getString(
"message.preparing-distribution-dist"), f.getAbsolutePath()));
- PrintStream out = new PrintStream(f);
+ try (PrintStream out = new PrintStream(f)) {
- out.println(
+ out.println(
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
- out.println("<installer-gui-script minSpecVersion=\"1\">");
+ out.println("<installer-gui-script minSpecVersion=\"1\">");
- out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
- out.println("<background" + " file=\""
- + getConfig_BackgroundImage(params).getName()
- + "\""
- + " mime-type=\"image/png\""
- + " alignment=\"bottomleft\" "
- + " scaling=\"none\""
- + "/>");
+ out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
+ out.println("<background" + " file=\""
+ + getConfig_BackgroundImage(params).getName()
+ + "\""
+ + " mime-type=\"image/png\""
+ + " alignment=\"bottomleft\" "
+ + " scaling=\"none\""
+ + "/>");
- String licFileStr = LICENSE_FILE.fetchFrom(params);
- if (licFileStr != null) {
- File licFile = new File(licFileStr);
- out.println("<license"
- + " file=\"" + licFile.getAbsolutePath() + "\""
- + " mime-type=\"text/rtf\""
- + "/>");
- }
+ String licFileStr = LICENSE_FILE.fetchFrom(params);
+ if (licFileStr != null) {
+ File licFile = new File(licFileStr);
+ out.println("<license"
+ + " file=\"" + licFile.getAbsolutePath() + "\""
+ + " mime-type=\"text/rtf\""
+ + "/>");
+ }
- /*
- * Note that the content of the distribution file
- * below is generated by productbuild --synthesize
- */
+ /*
+ * Note that the content of the distribution file
+ * below is generated by productbuild --synthesize
+ */
- String appId = getAppIdentifier(params);
-
- out.println("<pkg-ref id=\"" + appId + "\"/>");
+ String appId = getAppIdentifier(params);
- out.println("<options customize=\"never\" require-scripts=\"false\"/>");
- out.println("<choices-outline>");
- out.println(" <line choice=\"default\">");
- out.println(" <line choice=\"" + appId + "\"/>");
- out.println(" </line>");
- out.println("</choices-outline>");
- out.println("<choice id=\"default\"/>");
- out.println("<choice id=\"" + appId + "\" visible=\"false\">");
- out.println(" <pkg-ref id=\"" + appId + "\"/>");
- out.println("</choice>");
- out.println("<pkg-ref id=\"" + appId + "\" version=\""
- + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
- + URLEncoder.encode(getPackages_AppPackage(params).getName(),
- "UTF-8") + "</pkg-ref>");
+ out.println("<pkg-ref id=\"" + appId + "\"/>");
+ out.println(
+ "<options customize=\"never\" require-scripts=\"false\"/>");
+ out.println("<choices-outline>");
+ out.println(" <line choice=\"default\">");
+ out.println(" <line choice=\"" + appId + "\"/>");
+ out.println(" </line>");
+ out.println("</choices-outline>");
+ out.println("<choice id=\"default\"/>");
+ out.println("<choice id=\"" + appId + "\" visible=\"false\">");
+ out.println(" <pkg-ref id=\"" + appId + "\"/>");
+ out.println("</choice>");
+ out.println("<pkg-ref id=\"" + appId + "\" version=\""
+ + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
+ + URLEncoder.encode(
+ getPackages_AppPackage(params).getName(),
+ "UTF-8") + "</pkg-ref>");
- out.println("</installer-gui-script>");
+ out.println("</installer-gui-script>");
- out.close();
+ }
}
private boolean prepareConfigFiles(Map<String, ? super Object> params)
@@ -332,8 +333,8 @@
private void patchCPLFile(File cpl) throws IOException {
String cplData = Files.readString(cpl.toPath());
String[] lines = cplData.split("\n");
- try (PrintWriter out = new PrintWriter(new BufferedWriter(
- new FileWriter(cpl)))) {
+ try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(
+ cpl.toPath()))) {
boolean skip = false; // Used to skip Java.runtime bundle, since
// pkgbuild with --root will find two bundles app and Java runtime.
// We cannot generate component proprty list when using
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java Thu Jun 06 19:10:12 2019 -0400
@@ -192,72 +192,70 @@
String mainModule = StandardBundlerParam.MODULE.fetchFrom(params);
- PrintStream out = new PrintStream(cfgFileName);
+ try (PrintStream out = new PrintStream(cfgFileName)) {
+
+ out.println("[Application]");
+ out.println("app.name=" + APP_NAME.fetchFrom(params));
+ out.println("app.version=" + VERSION.fetchFrom(params));
+ out.println("app.runtime=" + runtimeLocation);
+ out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
+ out.println("app.classpath=" + String.join(File.pathSeparator,
+ CLASSPATH.fetchFrom(params).split("[ :;]")));
- out.println("[Application]");
- out.println("app.name=" + APP_NAME.fetchFrom(params));
- out.println("app.version=" + VERSION.fetchFrom(params));
- out.println("app.runtime=" + runtimeLocation);
- out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
- out.println("app.classpath=" + String.join(File.pathSeparator,
- CLASSPATH.fetchFrom(params).split("[ :;]")));
+ // The main app is required to be a jar, modular or unnamed.
+ if (mainModule != null &&
+ (mainJarType == ModFile.ModType.Unknown ||
+ mainJarType == ModFile.ModType.ModularJar)) {
+ out.println("app.mainmodule=" + mainModule);
+ } else {
+ String mainClass = JLinkBundlerHelper.getMainClass(params);
+ // If the app is contained in an unnamed jar then launch it the
+ // legacy way and the main class string must be
+ // of the format com/foo/Main
+ if (mainJar != null) {
+ out.println("app.mainjar="
+ + mainJar.toPath().getFileName().toString());
+ }
+ if (mainClass != null) {
+ out.println("app.mainclass="
+ + mainClass.replaceAll("\\.", "/"));
+ }
+ }
- // The main app is required to be a jar, modular or unnamed.
- if (mainModule != null &&
- (mainJarType == ModFile.ModType.Unknown ||
- mainJarType == ModFile.ModType.ModularJar)) {
- out.println("app.mainmodule=" + mainModule);
- } else {
- String mainClass = JLinkBundlerHelper.getMainClass(params);
- // If the app is contained in an unnamed jar then launch it the
- // legacy way and the main class string must be
- // of the format com/foo/Main
- if (mainJar != null) {
- out.println("app.mainjar="
- + mainJar.toPath().getFileName().toString());
+ Integer port = JLinkBundlerHelper.DEBUG.fetchFrom(params);
+
+ if (port != null) {
+ out.println(
+ "app.debug=-agentlib:jdwp=transport=dt_socket,"
+ + "server=y,suspend=y,address=localhost:"
+ + port);
+ }
+
+ out.println();
+ out.println("[JavaOptions]");
+ List<String> jvmargs = JAVA_OPTIONS.fetchFrom(params);
+ for (String arg : jvmargs) {
+ out.println(arg);
}
- if (mainClass != null) {
- out.println("app.mainclass="
- + mainClass.replaceAll("\\.", "/"));
+ Path modsDir = getAppModsDir();
+ if (modsDir != null && modsDir.toFile().exists()) {
+ out.println("--module-path");
+ out.println(getAppDir().relativize(modsDir));
+ }
+
+ out.println();
+ out.println("[ArgOptions]");
+ List<String> args = ARGUMENTS.fetchFrom(params);
+ for (String arg : args) {
+ if (arg.endsWith("=") &&
+ (arg.indexOf("=") == arg.lastIndexOf("="))) {
+ out.print(arg.substring(0, arg.length() - 1));
+ out.println("\\=");
+ } else {
+ out.println(arg);
+ }
}
}
-
- Integer port = JLinkBundlerHelper.DEBUG.fetchFrom(params);
-
- if (port != null) {
- out.println(
- "app.debug=-agentlib:jdwp=transport=dt_socket,"
- + "server=y,suspend=y,address=localhost:"
- + port);
- }
-
- out.println();
- out.println("[JavaOptions]");
- List<String> jvmargs = JAVA_OPTIONS.fetchFrom(params);
- for (String arg : jvmargs) {
- out.println(arg);
- }
- Path modsDir = getAppModsDir();
- if (modsDir != null && modsDir.toFile().exists()) {
- out.println("--module-path");
- out.println(getAppDir().relativize(modsDir));
- }
-
- out.println();
- out.println("[ArgOptions]");
- List<String> args = ARGUMENTS.fetchFrom(params);
- for (String arg : args) {
- if (arg.endsWith("=") &&
- (arg.indexOf("=") == arg.lastIndexOf("="))) {
- out.print(arg.substring(0, arg.length() - 1));
- out.println("\\=");
- } else {
- out.println(arg);
- }
- }
-
-
- out.close();
}
}
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -67,22 +67,19 @@
String defaultName, File result, boolean verbose, File publicRoot)
throws IOException {
- InputStream is = streamResource(publicName, category,
- defaultName, verbose, publicRoot);
- if (is != null) {
- try {
+ try (InputStream is = streamResource(publicName, category,
+ defaultName, verbose, publicRoot)) {
+ if (is != null) {
Files.copy(is, result.toPath(),
StandardCopyOption.REPLACE_EXISTING);
- } finally {
- is.close();
- }
- } else {
- if (verbose) {
- Log.verbose(MessageFormat.format(I18N.getString(
- "message.no-default-resource"),
- defaultName == null ? "" : defaultName,
- category == null ? "" : "[" + category + "] ",
- publicName));
+ } else {
+ if (verbose) {
+ Log.verbose(MessageFormat.format(I18N.getString(
+ "message.no-default-resource"),
+ defaultName == null ? "" : defaultName,
+ category == null ? "" : "[" + category + "] ",
+ publicName));
+ }
}
}
}
@@ -91,21 +88,18 @@
File defaultFile, File result, boolean verbose, File publicRoot)
throws IOException {
- InputStream is = streamResource(publicName, category,
- null, verbose, publicRoot);
- if (is != null) {
- try {
+ try (InputStream is = streamResource(publicName, category,
+ null, verbose, publicRoot)) {
+ if (is != null) {
Files.copy(is, result.toPath());
- } finally {
- is.close();
- }
- } else {
- IOUtils.copyFile(defaultFile, result);
- if (verbose) {
- Log.verbose(MessageFormat.format(I18N.getString(
- "message.using-custom-resource-from-file"),
- category == null ? "" : "[" + category + "] ",
- defaultFile.getAbsoluteFile()));
+ } else {
+ IOUtils.copyFile(defaultFile, result);
+ if (verbose) {
+ Log.verbose(MessageFormat.format(I18N.getString(
+ "message.using-custom-resource-from-file"),
+ category == null ? "" : "[" + category + "] ",
+ defaultFile.getAbsoluteFile()));
+ }
}
}
}
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java Thu Jun 06 19:10:12 2019 -0400
@@ -133,15 +133,15 @@
if (file.exists() && !append) {
file.delete();
}
- InputStream in = location.openStream();
- FileOutputStream out = new FileOutputStream(file, append);
- byte[] buffer = new byte[1024];
- int len;
- while ((len = in.read(buffer)) != -1) {
- out.write(buffer, 0, len);
+ try (InputStream in = location.openStream();
+ FileOutputStream out = new FileOutputStream(file, append)) {
+
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
}
- out.close();
- in.close();
file.setReadOnly();
file.setReadable(true, false);
}
@@ -154,18 +154,13 @@
destFile.delete();
destFile.createNewFile();
- FileChannel source = null;
- FileChannel destination = null;
- source = new FileInputStream(sourceFile).getChannel();
- destination = new FileOutputStream(destFile).getChannel();
- if (destination != null && source != null) {
- destination.transferFrom(source, 0, source.size());
- }
- if (source != null) {
- source.close();
- }
- if (destination != null) {
- destination.close();
+ try (FileChannel source = new FileInputStream(sourceFile).getChannel();
+ FileChannel destination =
+ new FileOutputStream(destFile).getChannel()) {
+
+ if (destination != null && source != null) {
+ destination.transferFrom(source, 0, source.size());
+ }
}
//preserve executable bit!
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModFile.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModFile.java Thu Jun 06 19:10:12 2019 -0400
@@ -97,24 +97,18 @@
private static JarType isModularJar(String FileName) {
JarType result = JarType.All;
- try {
- ZipInputStream zip =
- new ZipInputStream(new FileInputStream(FileName));
+ try (ZipInputStream zip =
+ new ZipInputStream(new FileInputStream(FileName))) {
result = JarType.UnnamedJar;
- try {
- for (ZipEntry entry = zip.getNextEntry(); entry != null;
- entry = zip.getNextEntry()) {
- if (entry.getName().matches("module-info.class")) {
- result = JarType.ModularJar;
- break;
- }
+ for (ZipEntry entry = zip.getNextEntry(); entry != null;
+ entry = zip.getNextEntry()) {
+ if (entry.getName().matches("module-info.class")) {
+ result = JarType.ModularJar;
+ break;
}
-
- zip.close();
- } catch (IOException ex) {
}
- } catch (FileNotFoundException e) {
+ } catch (IOException ex) {
}
return result;
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -703,16 +703,16 @@
String iss = StandardBundlerParam.isRuntimeInstaller(p) ?
DEFAULT_JRE_EXE_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
- Writer w = new BufferedWriter(new FileWriter(
- getConfig_ExeProjectFile(p)));
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_ExeProjectFile(p).toPath())) {
- String content = preprocessTextResource(
- getConfig_ExeProjectFile(p).getName(),
- getString("resource.inno-setup-project-file"),
- iss, data, VERBOSE.fetchFrom(p),
- RESOURCE_DIR.fetchFrom(p));
- w.write(content);
- w.close();
+ String content = preprocessTextResource(
+ getConfig_ExeProjectFile(p).getName(),
+ getString("resource.inno-setup-project-file"),
+ iss, data, VERBOSE.fetchFrom(p),
+ RESOURCE_DIR.fetchFrom(p));
+ w.write(content);
+ }
return true;
}
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java Thu Jun 06 19:07:18 2019 -0400
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java Thu Jun 06 19:10:12 2019 -0400
@@ -605,16 +605,16 @@
String wxs = StandardBundlerParam.isRuntimeInstaller(params) ?
MSI_PROJECT_TEMPLATE_SERVER_JRE : MSI_PROJECT_TEMPLATE;
- Writer w = new BufferedWriter(
- new FileWriter(getConfig_ProjectFile(params)));
+ try (Writer w = Files.newBufferedWriter(
+ getConfig_ProjectFile(params).toPath())) {
- String content = preprocessTextResource(
- getConfig_ProjectFile(params).getName(),
- I18N.getString("resource.wix-config-file"),
- wxs, data, VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ String content = preprocessTextResource(
+ getConfig_ProjectFile(params).getName(),
+ I18N.getString("resource.wix-config-file"),
+ wxs, data, VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
return true;
}
private int id;
@@ -948,87 +948,89 @@
throws FileNotFoundException {
File f = new File(
CONFIG_ROOT.fetchFrom(params), MSI_PROJECT_CONTENT_FILE);
- PrintStream out = new PrintStream(f);
+
+ try (PrintStream out = new PrintStream(f)) {
- // opening
- out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
- out.println("<Include>");
+ // opening
+ out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ out.println("<Include>");
- out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
- if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
- // install to programfiles
- out.println(" <Directory Id=\"ProgramFiles64Folder\" "
- + "Name=\"PFiles\">");
- } else {
- // install to user folder
- out.println(
+ out.println(" <Directory Id=\"TARGETDIR\" Name=\"SourceDir\">");
+ if (MSI_SYSTEM_WIDE.fetchFrom(params)) {
+ // install to programfiles
+ out.println(" <Directory Id=\"ProgramFiles64Folder\" "
+ + "Name=\"PFiles\">");
+ } else {
+ // install to user folder
+ out.println(
" <Directory Name=\"AppData\" Id=\"LocalAppDataFolder\">");
- }
+ }
- // We should get valid folder or subfolders
- String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params);
- String [] installDirs = installDir.split(Pattern.quote("\\"));
- for (int i = 0; i < (installDirs.length - 1); i++) {
- out.println(" <Directory Id=\"SUBDIR" + i + "\" Name=\""
- + installDirs[i] + "\">");
- }
+ // We should get valid folder or subfolders
+ String installDir = WINDOWS_INSTALL_DIR.fetchFrom(params);
+ String [] installDirs = installDir.split(Pattern.quote("\\"));
+ for (int i = 0; i < (installDirs.length - 1); i++) {
+ out.println(" <Directory Id=\"SUBDIR" + i + "\" Name=\""
+ + installDirs[i] + "\">");
+ }
- out.println(" <Directory Id=\"APPLICATIONFOLDER\" Name=\""
- + installDirs[installDirs.length - 1] + "\">");
+ out.println(" <Directory Id=\"APPLICATIONFOLDER\" Name=\""
+ + installDirs[installDirs.length - 1] + "\">");
- // dynamic part
- id = 0;
- compId = 0; // reset counters
- walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, " ");
+ // dynamic part
+ id = 0;
+ compId = 0; // reset counters
+ walkFileTree(params, WIN_APP_IMAGE.fetchFrom(params), out, " ");
- // closing
- for (int i = 0; i < installDirs.length; i++) {
- out.println(" </Directory>");
- }
- out.println(" </Directory>");
+ // closing
+ for (int i = 0; i < installDirs.length; i++) {
+ out.println(" </Directory>");
+ }
+ out.println(" </Directory>");
- // for shortcuts
- if (SHORTCUT_HINT.fetchFrom(params)) {
- out.println(" <Directory Id=\"DesktopFolder\" />");
- }
- if (MENU_HINT.fetchFrom(params)) {
- out.println(" <Directory Id=\"ProgramMenuFolder\">");
- out.println(" <Directory Id=\"ProgramMenuDir\" Name=\""
- + MENU_GROUP.fetchFrom(params) + "\">");
- out.println(" <Component Id=\"comp" + (compId++) + "\""
- + " Guid=\"" + UUID.randomUUID().toString() + "\""
- + " Win64=\"yes\""
- + ">");
- out.println(" <RemoveFolder Id=\"ProgramMenuDir\" "
- + "On=\"uninstall\" />");
- // This has to be under HKCU to make WiX happy.
- // There are numberous discussions on this amoung WiX users
- // (if user A installs and user B uninstalls key is left behind)
- // there are suggested workarounds but none of them are appealing.
- // Leave it for now
+ // for shortcuts
+ if (SHORTCUT_HINT.fetchFrom(params)) {
+ out.println(" <Directory Id=\"DesktopFolder\" />");
+ }
+ if (MENU_HINT.fetchFrom(params)) {
+ out.println(" <Directory Id=\"ProgramMenuFolder\">");
+ out.println(" <Directory Id=\"ProgramMenuDir\" Name=\""
+ + MENU_GROUP.fetchFrom(params) + "\">");
+ out.println(" <Component Id=\"comp" + (compId++) + "\""
+ + " Guid=\"" + UUID.randomUUID().toString() + "\""
+ + " Win64=\"yes\""
+ + ">");
+ out.println(" <RemoveFolder Id=\"ProgramMenuDir\" "
+ + "On=\"uninstall\" />");
+ // This has to be under HKCU to make WiX happy.
+ // There are numberous discussions on this amoung WiX users
+ // (if user A installs and user B uninstalls key is left behind)
+ // there are suggested workarounds but none are appealing.
+ // Leave it for now
+ out.println(
+ " <RegistryValue Root=\"HKCU\" Key=\"Software\\"
+ + VENDOR.fetchFrom(params) + "\\"
+ + APP_NAME.fetchFrom(params)
+ + "\" Type=\"string\" Value=\"\" />");
+ out.println(" </Component>");
+ out.println(" </Directory>");
+ out.println(" </Directory>");
+ }
+
+ out.println(" </Directory>");
+
+ out.println(" <Feature Id=\"DefaultFeature\" "
+ + "Title=\"Main Feature\" Level=\"1\">");
+ for (int j = 0; j < compId; j++) {
+ out.println(" <ComponentRef Id=\"comp" + j + "\" />");
+ }
+ // component is defined in the template.wsx
out.println(
- " <RegistryValue Root=\"HKCU\" Key=\"Software\\"
- + VENDOR.fetchFrom(params) + "\\"
- + APP_NAME.fetchFrom(params)
- + "\" Type=\"string\" Value=\"\" />");
- out.println(" </Component>");
- out.println(" </Directory>");
- out.println(" </Directory>");
- }
-
- out.println(" </Directory>");
+ " <ComponentRef Id=\"CleanupMainApplicationFolder\" />");
+ out.println(" </Feature>");
+ out.println("</Include>");
- out.println(" <Feature Id=\"DefaultFeature\" "
- + "Title=\"Main Feature\" Level=\"1\">");
- for (int j = 0; j < compId; j++) {
- out.println(" <ComponentRef Id=\"comp" + j + "\" />");
}
- // component is defined in the template.wsx
- out.println(" <ComponentRef Id=\"CleanupMainApplicationFolder\" />");
- out.println(" </Feature>");
- out.println("</Include>");
-
- out.close();
return true;
}