42 * 43 * It contains methods and parameters common to all Image Bundlers. 44 * 45 * Application Image Bundlers are created in "create-image" mode, 46 * or as an intermeadiate step in "create-installer" mode. 47 * 48 * The concrete implementations are in the platform specific Bundlers. 49 */ 50 public abstract class AbstractImageBundler extends AbstractBundler { 51 52 private final static String JAVA_VERSION_SPEC = 53 "java version \"((\\d+).(\\d+).(\\d+).(\\d+))(-(.*))?(\\+[^\"]*)?\""; 54 55 private static final ResourceBundle I18N = ResourceBundle.getBundle( 56 "jdk.jpackage.internal.resources.MainResources"); 57 58 public void imageBundleValidation(Map<String, ? super Object> p) 59 throws ConfigException { 60 StandardBundlerParam.validateMainClassInfoFromAppResources(p); 61 62 boolean hasMainJar = MAIN_JAR.fetchFrom(p) != null; 63 boolean hasMainModule = 64 StandardBundlerParam.MODULE.fetchFrom(p) != null; 65 boolean hasMainClass = MAIN_CLASS.fetchFrom(p) != null; 66 boolean runtime = RUNTIME_INSTALLER.fetchFrom(p); 67 68 if (!hasMainJar && !hasMainModule && !hasMainClass && !runtime) { 69 throw new ConfigException( 70 I18N.getString("error.no-application-class"), 71 I18N.getString("error.no-application-class.advice")); 72 } 73 } 74 75 public static void extractFlagsFromVersion( 76 Map<String, ? super Object> params, String versionOutput) { 77 Pattern bitArchPattern = Pattern.compile("(\\d*)[- ]?[bB]it"); 78 Matcher matcher = bitArchPattern.matcher(versionOutput); 79 if (matcher.find()) { 80 params.put(".runtime.bit-arch", matcher.group(1)); 81 } else { 82 // presume 32 bit on no match 83 params.put(".runtime.bit-arch", "32"); 84 } 85 86 Pattern oldVersionMatcher = Pattern.compile( 87 "java version \"((\\d+.(\\d+).\\d+)(_(\\d+)))?(-(.*))?\""); 88 matcher = oldVersionMatcher.matcher(versionOutput); 89 if (matcher.find()) { 90 params.put(".runtime.version", matcher.group(1)); 91 params.put(".runtime.version.release", matcher.group(2)); 92 params.put(".runtime.version.major", matcher.group(3)); 104 params.put(".runtime.version.major", matcher.group(2)); 105 params.put(".runtime.version.update", matcher.group(3)); 106 params.put(".runtime.version.minor", matcher.group(3)); 107 params.put(".runtime.version.security", matcher.group(4)); 108 params.put(".runtime.version.patch", matcher.group(5)); 109 params.put(".runtime.version.modifiers", matcher.group(7)); 110 } else { 111 params.put(".runtime.version", ""); 112 params.put(".runtime.version.release", ""); 113 params.put(".runtime.version.major", ""); 114 params.put(".runtime.version.update", ""); 115 params.put(".runtime.version.minor", ""); 116 params.put(".runtime.version.security", ""); 117 params.put(".runtime.version.patch", ""); 118 params.put(".runtime.version.modifiers", ""); 119 } 120 } 121 } 122 123 protected File createRoot(Map<String, ? super Object> p, 124 File outputDirectory, boolean dependentTask, 125 String name, String jlinkKey) throws PackagerException { 126 if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) { 127 throw new RuntimeException(MessageFormat.format( 128 I18N.getString("error.cannot-create-output-dir"), 129 outputDirectory.getAbsolutePath())); 130 } 131 if (!outputDirectory.canWrite()) { 132 throw new RuntimeException(MessageFormat.format( 133 I18N.getString("error.cannot-write-to-output-dir"), 134 outputDirectory.getAbsolutePath())); 135 } 136 if (!dependentTask) { 137 Log.verbose(MessageFormat.format( 138 I18N.getString("message.creating-app-bundle"), 139 name, outputDirectory.getAbsolutePath())); 140 } 141 142 // Create directory structure 143 File rootDirectory = new File(outputDirectory, name); 144 145 if (rootDirectory.exists()) { 146 if (!(OVERWRITE.fetchFrom(p))) { 147 throw new PackagerException("error.root-exists-without-overwrite", 148 rootDirectory.getAbsolutePath()); 149 } 150 try { 151 IOUtils.deleteRecursive(rootDirectory); 152 } catch (IOException ioe) { 153 throw new PackagerException(ioe); 154 } 155 } 156 rootDirectory.mkdirs(); 157 158 return rootDirectory; 159 } 160 161 } | 42 * 43 * It contains methods and parameters common to all Image Bundlers. 44 * 45 * Application Image Bundlers are created in "create-image" mode, 46 * or as an intermeadiate step in "create-installer" mode. 47 * 48 * The concrete implementations are in the platform specific Bundlers. 49 */ 50 public abstract class AbstractImageBundler extends AbstractBundler { 51 52 private final static String JAVA_VERSION_SPEC = 53 "java version \"((\\d+).(\\d+).(\\d+).(\\d+))(-(.*))?(\\+[^\"]*)?\""; 54 55 private static final ResourceBundle I18N = ResourceBundle.getBundle( 56 "jdk.jpackage.internal.resources.MainResources"); 57 58 public void imageBundleValidation(Map<String, ? super Object> p) 59 throws ConfigException { 60 StandardBundlerParam.validateMainClassInfoFromAppResources(p); 61 62 } 63 64 public static void extractFlagsFromVersion( 65 Map<String, ? super Object> params, String versionOutput) { 66 Pattern bitArchPattern = Pattern.compile("(\\d*)[- ]?[bB]it"); 67 Matcher matcher = bitArchPattern.matcher(versionOutput); 68 if (matcher.find()) { 69 params.put(".runtime.bit-arch", matcher.group(1)); 70 } else { 71 // presume 32 bit on no match 72 params.put(".runtime.bit-arch", "32"); 73 } 74 75 Pattern oldVersionMatcher = Pattern.compile( 76 "java version \"((\\d+.(\\d+).\\d+)(_(\\d+)))?(-(.*))?\""); 77 matcher = oldVersionMatcher.matcher(versionOutput); 78 if (matcher.find()) { 79 params.put(".runtime.version", matcher.group(1)); 80 params.put(".runtime.version.release", matcher.group(2)); 81 params.put(".runtime.version.major", matcher.group(3)); 93 params.put(".runtime.version.major", matcher.group(2)); 94 params.put(".runtime.version.update", matcher.group(3)); 95 params.put(".runtime.version.minor", matcher.group(3)); 96 params.put(".runtime.version.security", matcher.group(4)); 97 params.put(".runtime.version.patch", matcher.group(5)); 98 params.put(".runtime.version.modifiers", matcher.group(7)); 99 } else { 100 params.put(".runtime.version", ""); 101 params.put(".runtime.version.release", ""); 102 params.put(".runtime.version.major", ""); 103 params.put(".runtime.version.update", ""); 104 params.put(".runtime.version.minor", ""); 105 params.put(".runtime.version.security", ""); 106 params.put(".runtime.version.patch", ""); 107 params.put(".runtime.version.modifiers", ""); 108 } 109 } 110 } 111 112 protected File createRoot(Map<String, ? super Object> p, 113 File outputDirectory, boolean dependentTask, String name) 114 throws PackagerException { 115 if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) { 116 throw new RuntimeException(MessageFormat.format( 117 I18N.getString("error.cannot-create-output-dir"), 118 outputDirectory.getAbsolutePath())); 119 } 120 if (!outputDirectory.canWrite()) { 121 throw new RuntimeException(MessageFormat.format( 122 I18N.getString("error.cannot-write-to-output-dir"), 123 outputDirectory.getAbsolutePath())); 124 } 125 if (!dependentTask) { 126 Log.verbose(MessageFormat.format( 127 I18N.getString("message.creating-app-bundle"), 128 name, outputDirectory.getAbsolutePath())); 129 } 130 131 // Create directory structure 132 File rootDirectory = new File(outputDirectory, name); 133 134 if (rootDirectory.exists()) { 135 throw new PackagerException("error.root-exists", 136 rootDirectory.getAbsolutePath()); 137 } 138 139 rootDirectory.mkdirs(); 140 141 return rootDirectory; 142 } 143 144 } |