< prev index next >

modules/fxpackager/src/main/java/com/oracle/tools/packager/mac/MacAppBundler.java

Print this page




 480             File pkgInfoFile = new File(contentsDirectory, "PkgInfo");
 481             pkgInfoFile.createNewFile();
 482             writePkgInfo(pkgInfoFile);
 483 
 484             // Copy executable to MacOS folder
 485             File executableFile = new File(macOSDirectory, getLauncherName(p));
 486             IOUtils.copyFromURL(
 487                     RAW_EXECUTABLE_URL.fetchFrom(p),
 488                     executableFile);
 489 
 490             // Copy library to the MacOS folder
 491             IOUtils.copyFromURL(
 492                     MacResources.class.getResource(LIBRARY_NAME),
 493                     new File(macOSDirectory, LIBRARY_NAME));
 494 
 495             // maybe generate launcher config
 496             if (!MAC_CONFIGURE_LAUNCHER_IN_PLIST.fetchFrom(p)) {
 497                 if (LAUNCHER_CFG_FORMAT.fetchFrom(p).equals(CFG_FORMAT_PROPERTIES)) {
 498                     writeCfgFile(p, rootDirectory);
 499                 } else {
 500                     writeCfgFile(p, new File(rootDirectory, getLauncherCfgName(p)), "$APPDIR/PlugIns/Java.runtime");
 501                 }
 502             }
 503 
 504             executableFile.setExecutable(true, false);
 505 
 506             // Copy runtime to PlugIns folder
 507             copyRuntime(plugInsDirectory, p);
 508 
 509             // Copy class path entries to Java folder
 510             copyClassPathEntries(javaDirectory, p);
 511 
 512             //TODO: Need to support adding native libraries.
 513             // Copy library path entries to MacOS folder
 514             //copyLibraryPathEntries(macOSDirectory);
 515 
 516             /*********** Take care of "config" files *******/
 517             // Copy icon to Resources folder
 518             IOUtils.copyFile(getConfig_Icon(p),
 519                     new File(resourcesDirectory, getConfig_Icon(p).getName()));
 520 


 645 
 646     private String getBundleName(Map<String, ? super Object> params) {
 647         //TODO: Check to see what rules/limits are in place for CFBundleName
 648         if (MAC_CF_BUNDLE_NAME.fetchFrom(params) != null) {
 649             String bn = MAC_CF_BUNDLE_NAME.fetchFrom(params);
 650             if (bn.length() > 16) {
 651                 Log.info(MessageFormat.format(I18N.getString("message.bundle-name-too-long-warning"), MAC_CF_BUNDLE_NAME.getID(), bn));
 652             }
 653             return MAC_CF_BUNDLE_NAME.fetchFrom(params);
 654         } else if (APP_NAME.fetchFrom(params) != null) {
 655             return APP_NAME.fetchFrom(params);
 656         } else {
 657             String nm = MAIN_CLASS.fetchFrom(params);
 658             if (nm.length() > 16) {
 659                 nm = nm.substring(0, 16);
 660             }
 661             return nm;
 662         }
 663     }
 664 








 665     private void writeInfoPlist(File file, Map<String, ? super Object> params) throws IOException {
 666         Log.verbose(MessageFormat.format(I18N.getString("message.preparing-info-plist"), file.getAbsolutePath()));
 667 
 668         //prepare config for exe
 669         //Note: do not need CFBundleDisplayName if we do not support localization
 670         Map<String, String> data = new HashMap<>();
 671         data.put("DEPLOY_ICON_FILE", getConfig_Icon(params).getName());
 672         data.put("DEPLOY_BUNDLE_IDENTIFIER",
 673                 MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params));
 674         data.put("DEPLOY_BUNDLE_NAME",
 675                 getBundleName(params));
 676         data.put("DEPLOY_BUNDLE_COPYRIGHT",
 677                 COPYRIGHT.fetchFrom(params) != null ? COPYRIGHT.fetchFrom(params) : "Unknown");
 678         data.put("DEPLOY_LAUNCHER_NAME", getLauncherName(params));
 679         if (MAC_RUNTIME.fetchFrom(params) != null) {
 680             data.put("DEPLOY_JAVA_RUNTIME_NAME", "$APPDIR/PlugIns/Java.runtime");
 681         } else {
 682             data.put("DEPLOY_JAVA_RUNTIME_NAME", "");
 683         }
 684         data.put("DEPLOY_BUNDLE_SHORT_VERSION",


1107 
1108         // Copy executable root folder
1109         File executableFile = new File(rootDirectory, "Contents/MacOS/" + getLauncherName(p));
1110         IOUtils.copyFromURL(
1111                 RAW_EXECUTABLE_URL.fetchFrom(p),
1112                 executableFile);
1113         executableFile.setExecutable(true, false);
1114 
1115     }
1116 
1117     public static String getLauncherCfgName(Map<String, ? super Object> p) {
1118         return "Contents/Java/" + APP_NAME.fetchFrom(p) +".cfg";
1119     }
1120 
1121     private void writeCfgFile(Map<String, ? super Object> params, File rootDir) throws FileNotFoundException {
1122         File pkgInfoFile = new File(rootDir, getLauncherCfgName(params));
1123 
1124         pkgInfoFile.delete();
1125 
1126         PrintStream out = new PrintStream(pkgInfoFile);
1127         if (MAC_RUNTIME.fetchFrom(params) == null) {
1128             out.println("app.runtime=");
1129         } else {
1130             out.println("app.runtime=$APPDIR/PlugIns/Java.runtime");
1131         }
1132         out.println("app.mainjar=" + MAIN_JAR.fetchFrom(params).getIncludedFiles().iterator().next());
1133         out.println("app.version=" + VERSION.fetchFrom(params));
1134         //for future AU support (to be able to find app in the registry)
1135         out.println("app.id=" + IDENTIFIER.fetchFrom(params));
1136         out.println("app.preferences.id=" + PREFERENCES_ID.fetchFrom(params));
1137         out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
1138 
1139         out.println("app.mainclass=" +
1140                 MAIN_CLASS.fetchFrom(params).replaceAll("\\.", "/"));
1141         out.println("app.classpath=" + CLASSPATH.fetchFrom(params));
1142 
1143         List<String> jvmargs = JVM_OPTIONS.fetchFrom(params);
1144         int idx = 1;
1145         for (String a : jvmargs) {
1146             out.println("jvmarg."+idx+"="+a);
1147             idx++;
1148         }
1149         Map<String, String> jvmProps = JVM_PROPERTIES.fetchFrom(params);
1150         for (Map.Entry<String, String> entry : jvmProps.entrySet()) {
1151             out.println("jvmarg."+idx+"=-D"+entry.getKey()+"="+entry.getValue());




 480             File pkgInfoFile = new File(contentsDirectory, "PkgInfo");
 481             pkgInfoFile.createNewFile();
 482             writePkgInfo(pkgInfoFile);
 483 
 484             // Copy executable to MacOS folder
 485             File executableFile = new File(macOSDirectory, getLauncherName(p));
 486             IOUtils.copyFromURL(
 487                     RAW_EXECUTABLE_URL.fetchFrom(p),
 488                     executableFile);
 489 
 490             // Copy library to the MacOS folder
 491             IOUtils.copyFromURL(
 492                     MacResources.class.getResource(LIBRARY_NAME),
 493                     new File(macOSDirectory, LIBRARY_NAME));
 494 
 495             // maybe generate launcher config
 496             if (!MAC_CONFIGURE_LAUNCHER_IN_PLIST.fetchFrom(p)) {
 497                 if (LAUNCHER_CFG_FORMAT.fetchFrom(p).equals(CFG_FORMAT_PROPERTIES)) {
 498                     writeCfgFile(p, rootDirectory);
 499                 } else {
 500                     writeCfgFile(p, new File(rootDirectory, getLauncherCfgName(p)), getRuntimeLocation(p));
 501                 }
 502             }
 503 
 504             executableFile.setExecutable(true, false);
 505 
 506             // Copy runtime to PlugIns folder
 507             copyRuntime(plugInsDirectory, p);
 508 
 509             // Copy class path entries to Java folder
 510             copyClassPathEntries(javaDirectory, p);
 511 
 512             //TODO: Need to support adding native libraries.
 513             // Copy library path entries to MacOS folder
 514             //copyLibraryPathEntries(macOSDirectory);
 515 
 516             /*********** Take care of "config" files *******/
 517             // Copy icon to Resources folder
 518             IOUtils.copyFile(getConfig_Icon(p),
 519                     new File(resourcesDirectory, getConfig_Icon(p).getName()));
 520 


 645 
 646     private String getBundleName(Map<String, ? super Object> params) {
 647         //TODO: Check to see what rules/limits are in place for CFBundleName
 648         if (MAC_CF_BUNDLE_NAME.fetchFrom(params) != null) {
 649             String bn = MAC_CF_BUNDLE_NAME.fetchFrom(params);
 650             if (bn.length() > 16) {
 651                 Log.info(MessageFormat.format(I18N.getString("message.bundle-name-too-long-warning"), MAC_CF_BUNDLE_NAME.getID(), bn));
 652             }
 653             return MAC_CF_BUNDLE_NAME.fetchFrom(params);
 654         } else if (APP_NAME.fetchFrom(params) != null) {
 655             return APP_NAME.fetchFrom(params);
 656         } else {
 657             String nm = MAIN_CLASS.fetchFrom(params);
 658             if (nm.length() > 16) {
 659                 nm = nm.substring(0, 16);
 660             }
 661             return nm;
 662         }
 663     }
 664 
 665     private String getRuntimeLocation(Map<String, ? super Object> params) {
 666         if (MAC_RUNTIME.fetchFrom(params) == null) {
 667             return "";
 668         } else {
 669             return "$APPDIR/PlugIns/Java.runtime";
 670         }
 671     }
 672 
 673     private void writeInfoPlist(File file, Map<String, ? super Object> params) throws IOException {
 674         Log.verbose(MessageFormat.format(I18N.getString("message.preparing-info-plist"), file.getAbsolutePath()));
 675 
 676         //prepare config for exe
 677         //Note: do not need CFBundleDisplayName if we do not support localization
 678         Map<String, String> data = new HashMap<>();
 679         data.put("DEPLOY_ICON_FILE", getConfig_Icon(params).getName());
 680         data.put("DEPLOY_BUNDLE_IDENTIFIER",
 681                 MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params));
 682         data.put("DEPLOY_BUNDLE_NAME",
 683                 getBundleName(params));
 684         data.put("DEPLOY_BUNDLE_COPYRIGHT",
 685                 COPYRIGHT.fetchFrom(params) != null ? COPYRIGHT.fetchFrom(params) : "Unknown");
 686         data.put("DEPLOY_LAUNCHER_NAME", getLauncherName(params));
 687         if (MAC_RUNTIME.fetchFrom(params) != null) {
 688             data.put("DEPLOY_JAVA_RUNTIME_NAME", "$APPDIR/PlugIns/Java.runtime");
 689         } else {
 690             data.put("DEPLOY_JAVA_RUNTIME_NAME", "");
 691         }
 692         data.put("DEPLOY_BUNDLE_SHORT_VERSION",


1115 
1116         // Copy executable root folder
1117         File executableFile = new File(rootDirectory, "Contents/MacOS/" + getLauncherName(p));
1118         IOUtils.copyFromURL(
1119                 RAW_EXECUTABLE_URL.fetchFrom(p),
1120                 executableFile);
1121         executableFile.setExecutable(true, false);
1122 
1123     }
1124 
1125     public static String getLauncherCfgName(Map<String, ? super Object> p) {
1126         return "Contents/Java/" + APP_NAME.fetchFrom(p) +".cfg";
1127     }
1128 
1129     private void writeCfgFile(Map<String, ? super Object> params, File rootDir) throws FileNotFoundException {
1130         File pkgInfoFile = new File(rootDir, getLauncherCfgName(params));
1131 
1132         pkgInfoFile.delete();
1133 
1134         PrintStream out = new PrintStream(pkgInfoFile);
1135         out.println("app.runtime=" + getRuntimeLocation(params));




1136         out.println("app.mainjar=" + MAIN_JAR.fetchFrom(params).getIncludedFiles().iterator().next());
1137         out.println("app.version=" + VERSION.fetchFrom(params));
1138         //for future AU support (to be able to find app in the registry)
1139         out.println("app.id=" + IDENTIFIER.fetchFrom(params));
1140         out.println("app.preferences.id=" + PREFERENCES_ID.fetchFrom(params));
1141         out.println("app.identifier=" + IDENTIFIER.fetchFrom(params));
1142 
1143         out.println("app.mainclass=" +
1144                 MAIN_CLASS.fetchFrom(params).replaceAll("\\.", "/"));
1145         out.println("app.classpath=" + CLASSPATH.fetchFrom(params));
1146 
1147         List<String> jvmargs = JVM_OPTIONS.fetchFrom(params);
1148         int idx = 1;
1149         for (String a : jvmargs) {
1150             out.println("jvmarg."+idx+"="+a);
1151             idx++;
1152         }
1153         Map<String, String> jvmProps = JVM_PROPERTIES.fetchFrom(params);
1154         for (Map.Entry<String, String> entry : jvmProps.entrySet()) {
1155             out.println("jvmarg."+idx+"=-D"+entry.getKey()+"="+entry.getValue());


< prev index next >