9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.oracle.tools.packager.mac; 27 28 import com.oracle.tools.packager.AbstractBundler; 29 import com.oracle.tools.packager.BundlerParamInfo; 30 import com.oracle.tools.packager.ConfigException; 31 import com.oracle.tools.packager.IOUtils; 32 import com.oracle.tools.packager.Log; 33 import com.oracle.tools.packager.RelativeFileSet; 34 import com.oracle.tools.packager.UnsupportedPlatformException; 35 import org.junit.After; 36 import org.junit.Assume; 37 import org.junit.Before; 38 import org.junit.BeforeClass; 39 import org.junit.Test; 40 41 import java.io.ByteArrayOutputStream; 42 import java.io.File; 43 import java.io.IOException; 44 import java.io.PrintStream; 45 import java.text.SimpleDateFormat; 46 import java.util.Arrays; 47 import java.util.Collection; 48 import java.util.Date; 49 import java.util.HashMap; 50 import java.util.HashSet; 51 import java.util.Map; 52 import java.util.Set; 53 import java.util.TreeMap; 54 import java.util.regex.Matcher; 55 import java.util.regex.Pattern; 56 57 import static com.oracle.tools.packager.StandardBundlerParam.*; 58 import static com.oracle.tools.packager.mac.MacAppBundler.*; 59 import static com.oracle.tools.packager.mac.MacAppStoreBundler.*; 60 import static org.junit.Assert.*; 61 62 public class MacAppStoreBundlerTest { 63 64 static final int MIN_SIZE = 0x100000; // 1MiB 168 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { 169 AbstractBundler bundler = new MacAppStoreBundler(); 170 171 assertNotNull(bundler.getName()); 172 assertNotNull(bundler.getID()); 173 assertNotNull(bundler.getDescription()); 174 175 Map<String, Object> bundleParams = new HashMap<>(); 176 177 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 178 179 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 180 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 181 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 182 bundleParams.put(MAIN_JAR.getID(), 183 new RelativeFileSet(fakeMainJar.getParentFile(), 184 new HashSet<>(Arrays.asList(fakeMainJar))) 185 ); 186 bundleParams.put(MAC_CF_BUNDLE_VERSION.getID(), "1.0." + new SimpleDateFormat("YYYYMMddHHmm").format(new Date())); 187 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 188 bundleParams.put(IDENTIFIER.getID(), "com.example.javapackager.hello.TestPackager"); 189 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 190 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 191 bundleParams.put(VERBOSE.getID(), true); 192 193 if (runtimeJdk != null) { 194 bundleParams.put(MAC_RUNTIME.getID(), runtimeJdk); 195 } 196 197 boolean valid = bundler.validate(bundleParams); 198 assertTrue(valid); 199 200 File result = bundler.execute(bundleParams, new File(workDir, "smoke")); 201 System.err.println("Bundle at - " + result); 202 203 checkFiles(result); 204 } 205 206 private void checkFiles(File result) throws IOException { 207 assertNotNull(result); 208 assertTrue(result.exists()); 209 assertTrue(result.length() > MIN_SIZE); 210 211 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 212 PrintStream printStream = new PrintStream(baos, true); 213 IOUtils.exec( 214 new ProcessBuilder("pkgutil", "--payload-files", result.getCanonicalPath()), 215 false, false, printStream); 216 217 String output = baos.toString(); 218 219 Pattern jreInfoPListPattern = Pattern.compile("/PlugIns/[^/]+/Contents/Info\\.plist"); 220 Matcher matcher = jreInfoPListPattern.matcher(output); 221 assertTrue("Insure that info.plist is packed in for embedded jre", matcher.find()); 222 223 assertFalse("Insure JFX Media isn't packed in", output.contains("/libjfxmedia_qtkit.dylib")); 224 } 225 226 @Test 227 public void configureEverything() throws Exception { 228 AbstractBundler bundler = new MacAppStoreBundler(); 229 Collection<BundlerParamInfo<?>> parameters = bundler.getBundleParameters(); 230 231 Map<String, Object> bundleParams = new HashMap<>(); 232 233 bundleParams.put(APP_NAME.getID(), "Everything App Name"); 234 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 235 bundleParams.put(ARGUMENTS.getID(), Arrays.asList("He Said", "She Said")); 236 bundleParams.put(BUNDLE_ID_SIGNING_PREFIX.getID(), "everything.signing.prefix."); 237 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 238 bundleParams.put(ICON_ICNS.getID(), hdpiIcon); 239 bundleParams.put(INSTALLER_SUFFIX.getID(), "-MAS-TEST"); 240 bundleParams.put(JVM_OPTIONS.getID(), "-Xms128M"); 241 bundleParams.put(JVM_PROPERTIES.getID(), "everything.jvm.property=everything.jvm.property.value"); 242 bundleParams.put(MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 243 bundleParams.put(MAC_CF_BUNDLE_IDENTIFIER.getID(), "com.example.everything.cf-bundle-identifier"); 274 275 // assert they resolve 276 for (BundlerParamInfo bi : parameters) { 277 bi.fetchFrom(bundleParams); 278 } 279 280 // now that we are done scoping out parameters add more esoteric values 281 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 282 bundleParams.put(VERBOSE.getID(), true); 283 284 // assert it validates 285 boolean valid = bundler.validate(bundleParams); 286 assertTrue(valid); 287 288 // only run the bundle with full tests 289 Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST"))); 290 291 File result = bundler.execute(bundleParams, new File(workDir, "everything")); 292 System.err.println("Bundle at - " + result); 293 294 checkFiles(result); 295 } 296 297 /** 298 * User a JRE instead of a JDK 299 */ 300 @Test 301 public void testJRE() throws IOException, ConfigException, UnsupportedPlatformException { 302 String jre = runtimeJre == null ? "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/" : runtimeJre; 303 Assume.assumeTrue(new File(jre).isDirectory()); 304 305 AbstractBundler bundler = new MacAppStoreBundler(); 306 307 assertNotNull(bundler.getName()); 308 assertNotNull(bundler.getID()); 309 assertNotNull(bundler.getDescription()); 310 311 Map<String, Object> bundleParams = new HashMap<>(); 312 313 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 314 315 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 316 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 317 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 318 bundleParams.put(MAIN_JAR.getID(), 319 new RelativeFileSet(fakeMainJar.getParentFile(), 320 new HashSet<>(Arrays.asList(fakeMainJar))) 321 ); 322 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 323 bundleParams.put(IDENTIFIER.getID(), "com.example.javapackager.hello.TestPackager"); 324 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 325 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 326 bundleParams.put(VERBOSE.getID(), true); 327 bundleParams.put(MAC_RUNTIME.getID(), jre); 328 329 boolean valid = bundler.validate(bundleParams); 330 assertTrue(valid); 331 332 File result = bundler.execute(bundleParams, new File(workDir, "jre")); 333 System.err.println("Bundle at - " + result); 334 335 checkFiles(result); 336 337 } 338 339 /** 340 * Request no signature, should be a validaiton error 341 */ 342 @Test(expected = ConfigException.class) 343 public void invalidDoNotSign() throws IOException, ConfigException, UnsupportedPlatformException { 344 AbstractBundler bundler = new MacAppStoreBundler(); 345 346 Map<String, Object> bundleParams = new HashMap<>(); 347 348 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 349 350 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 351 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 352 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 353 bundleParams.put(MAIN_JAR.getID(), 354 new RelativeFileSet(fakeMainJar.getParentFile(), 355 new HashSet<>(Arrays.asList(fakeMainJar))) 356 ); 357 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 358 bundleParams.put(IDENTIFIER.getID(), "com.example.javapackager.hello.TestPackager"); 359 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 360 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 361 bundleParams.put(VERBOSE.getID(), true); 362 363 if (runtimeJdk != null) { 364 bundleParams.put(MAC_RUNTIME.getID(), runtimeJdk); 365 } 366 367 bundleParams.put(SIGN_BUNDLE.getID(), false); 368 369 bundler.validate(bundleParams); 370 } 371 } | 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.oracle.tools.packager.mac; 27 28 import com.oracle.tools.packager.AbstractBundler; 29 import com.oracle.tools.packager.AbstractImageBundler; 30 import com.oracle.tools.packager.BundlerParamInfo; 31 import com.oracle.tools.packager.ConfigException; 32 import com.oracle.tools.packager.IOUtils; 33 import com.oracle.tools.packager.Log; 34 import com.oracle.tools.packager.RelativeFileSet; 35 import com.oracle.tools.packager.UnsupportedPlatformException; 36 import org.junit.After; 37 import org.junit.Assume; 38 import org.junit.Before; 39 import org.junit.BeforeClass; 40 import org.junit.Test; 41 42 import java.io.ByteArrayOutputStream; 43 import java.io.File; 44 import java.io.IOException; 45 import java.io.PrintStream; 46 import java.nio.file.Files; 47 import java.nio.file.Paths; 48 import java.text.SimpleDateFormat; 49 import java.util.Arrays; 50 import java.util.Collection; 51 import java.util.Date; 52 import java.util.HashMap; 53 import java.util.HashSet; 54 import java.util.Map; 55 import java.util.Set; 56 import java.util.TreeMap; 57 import java.util.regex.Matcher; 58 import java.util.regex.Pattern; 59 60 import static com.oracle.tools.packager.StandardBundlerParam.*; 61 import static com.oracle.tools.packager.mac.MacAppBundler.*; 62 import static com.oracle.tools.packager.mac.MacAppStoreBundler.*; 63 import static org.junit.Assert.*; 64 65 public class MacAppStoreBundlerTest { 66 67 static final int MIN_SIZE = 0x100000; // 1MiB 171 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { 172 AbstractBundler bundler = new MacAppStoreBundler(); 173 174 assertNotNull(bundler.getName()); 175 assertNotNull(bundler.getID()); 176 assertNotNull(bundler.getDescription()); 177 178 Map<String, Object> bundleParams = new HashMap<>(); 179 180 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 181 182 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 183 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 184 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 185 bundleParams.put(MAIN_JAR.getID(), 186 new RelativeFileSet(fakeMainJar.getParentFile(), 187 new HashSet<>(Arrays.asList(fakeMainJar))) 188 ); 189 bundleParams.put(MAC_CF_BUNDLE_VERSION.getID(), "1.0." + new SimpleDateFormat("YYYYMMddHHmm").format(new Date())); 190 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 191 bundleParams.put(IDENTIFIER.getID(), "com.example.javapacakger.hello.TestPackager"); 192 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 193 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 194 bundleParams.put(VERBOSE.getID(), true); 195 196 if (runtimeJdk != null) { 197 bundleParams.put(MAC_RUNTIME.getID(), runtimeJdk); 198 } 199 200 boolean valid = bundler.validate(bundleParams); 201 assertTrue(valid); 202 203 File result = bundler.execute(bundleParams, new File(workDir, "smoke")); 204 System.err.println("Bundle at - " + result); 205 206 checkFiles(result, runtimeJdk); 207 } 208 209 private void checkFiles(File result, String runtimeRoot) throws IOException { 210 assertNotNull(result); 211 assertTrue(result.exists()); 212 assertTrue(result.length() > MIN_SIZE); 213 214 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 215 PrintStream printStream = new PrintStream(baos, true); 216 IOUtils.exec( 217 new ProcessBuilder("pkgutil", "--payload-files", result.getCanonicalPath()), 218 false, false, printStream); 219 220 String output = baos.toString(); 221 222 Pattern jreInfoPListPattern = Pattern.compile("/PlugIns/[^/]+/Contents/Info\\.plist"); 223 Matcher matcher = jreInfoPListPattern.matcher(output); 224 assertTrue("Insure that info.plist is packed in for embedded jre", matcher.find()); 225 226 Map<String, Object> params = new HashMap<>(); 227 String version; 228 229 if (runtimeRoot == null) { 230 version = System.getProperty("java.runtime.version"); 231 } else { 232 byte[] infoPlistBytes = Files.readAllBytes(Paths.get(runtimeRoot).getParent().resolve("Info.plist")); 233 String infoPlist = new String(infoPlistBytes); 234 235 Pattern cfBundleVersionMatcher = Pattern.compile("<key>CFBundleVersion</key>\\s*<string>([^<]+)</string>"); 236 Matcher m = cfBundleVersionMatcher.matcher(infoPlist); 237 assertTrue("Packed Info.plist presents a java version", m.find()); 238 version = m.group(1); 239 } 240 AbstractImageBundler.extractFlagsFromVersion(params, "java version \"" + version + "\"\n"); 241 242 int majorVersion = Integer.parseInt(params.get(".runtime.version.major").toString()); 243 int updateVersion = Integer.parseInt(params.get(".runtime.version.update").toString()); 244 245 if (majorVersion == 8 && updateVersion >= 40) { 246 assertFalse("Insure JFX Media QuickTime Partition isn't packed in", output.contains("/libjfxmedia_qtkit.dylib")); 247 } else { 248 assertFalse("Insure JFX Media isn't packed in", output.contains("/libjfxmedia.dylib")); 249 } 250 251 if (majorVersion == 8 && updateVersion >= 60) { 252 assertFalse("Insure WebView library isn't packed in", output.contains("/libjfxwebkit.dylib")); 253 } 254 } 255 256 @Test 257 public void configureEverything() throws Exception { 258 AbstractBundler bundler = new MacAppStoreBundler(); 259 Collection<BundlerParamInfo<?>> parameters = bundler.getBundleParameters(); 260 261 Map<String, Object> bundleParams = new HashMap<>(); 262 263 bundleParams.put(APP_NAME.getID(), "Everything App Name"); 264 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 265 bundleParams.put(ARGUMENTS.getID(), Arrays.asList("He Said", "She Said")); 266 bundleParams.put(BUNDLE_ID_SIGNING_PREFIX.getID(), "everything.signing.prefix."); 267 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 268 bundleParams.put(ICON_ICNS.getID(), hdpiIcon); 269 bundleParams.put(INSTALLER_SUFFIX.getID(), "-MAS-TEST"); 270 bundleParams.put(JVM_OPTIONS.getID(), "-Xms128M"); 271 bundleParams.put(JVM_PROPERTIES.getID(), "everything.jvm.property=everything.jvm.property.value"); 272 bundleParams.put(MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 273 bundleParams.put(MAC_CF_BUNDLE_IDENTIFIER.getID(), "com.example.everything.cf-bundle-identifier"); 304 305 // assert they resolve 306 for (BundlerParamInfo bi : parameters) { 307 bi.fetchFrom(bundleParams); 308 } 309 310 // now that we are done scoping out parameters add more esoteric values 311 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 312 bundleParams.put(VERBOSE.getID(), true); 313 314 // assert it validates 315 boolean valid = bundler.validate(bundleParams); 316 assertTrue(valid); 317 318 // only run the bundle with full tests 319 Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST"))); 320 321 File result = bundler.execute(bundleParams, new File(workDir, "everything")); 322 System.err.println("Bundle at - " + result); 323 324 checkFiles(result, runtimeJdk); 325 } 326 327 /** 328 * User a JRE instead of a JDK 329 */ 330 @Test 331 public void testJRE() throws IOException, ConfigException, UnsupportedPlatformException { 332 String jre = runtimeJre == null ? "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/" : runtimeJre; 333 Assume.assumeTrue(new File(jre).isDirectory()); 334 335 AbstractBundler bundler = new MacAppStoreBundler(); 336 337 assertNotNull(bundler.getName()); 338 assertNotNull(bundler.getID()); 339 assertNotNull(bundler.getDescription()); 340 341 Map<String, Object> bundleParams = new HashMap<>(); 342 343 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 344 345 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 346 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 347 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 348 bundleParams.put(MAIN_JAR.getID(), 349 new RelativeFileSet(fakeMainJar.getParentFile(), 350 new HashSet<>(Arrays.asList(fakeMainJar))) 351 ); 352 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 353 bundleParams.put(IDENTIFIER.getID(), "com.example.javapacakger.hello.TestPackager"); 354 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 355 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 356 bundleParams.put(VERBOSE.getID(), true); 357 bundleParams.put(MAC_RUNTIME.getID(), jre); 358 359 boolean valid = bundler.validate(bundleParams); 360 assertTrue(valid); 361 362 File result = bundler.execute(bundleParams, new File(workDir, "jre")); 363 System.err.println("Bundle at - " + result); 364 365 checkFiles(result, runtimeJre); 366 367 } 368 369 /** 370 * Request no signature, should be a validaiton error 371 */ 372 @Test(expected = ConfigException.class) 373 public void invalidDoNotSign() throws IOException, ConfigException, UnsupportedPlatformException { 374 AbstractBundler bundler = new MacAppStoreBundler(); 375 376 Map<String, Object> bundleParams = new HashMap<>(); 377 378 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 379 380 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 381 bundleParams.put(MAIN_CLASS.getID(), "hello.HelloRectangle"); 382 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 383 bundleParams.put(MAIN_JAR.getID(), 384 new RelativeFileSet(fakeMainJar.getParentFile(), 385 new HashSet<>(Arrays.asList(fakeMainJar))) 386 ); 387 bundleParams.put(CLASSPATH.getID(), "mainApp.jar"); 388 bundleParams.put(IDENTIFIER.getID(), "com.example.javapacakger.hello.TestPackager"); 389 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 390 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 391 bundleParams.put(VERBOSE.getID(), true); 392 393 if (runtimeJdk != null) { 394 bundleParams.put(MAC_RUNTIME.getID(), runtimeJdk); 395 } 396 397 bundleParams.put(SIGN_BUNDLE.getID(), false); 398 399 bundler.validate(bundleParams); 400 } 401 } |