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.util.Arrays; 46 import java.util.Collection; 47 import java.util.HashMap; 48 import java.util.HashSet; 49 import java.util.Map; 50 import java.util.Set; 51 import java.util.TreeMap; 52 53 import static com.oracle.tools.packager.StandardBundlerParam.*; 54 import static com.oracle.tools.packager.mac.MacAppBundler.*; 55 import static com.oracle.tools.packager.mac.MacAppStoreBundler.*; 56 import static org.junit.Assert.*; 57 58 public class MacAppStoreBundlerTest { 59 60 static final int MIN_SIZE=0x100000; // 1MiB 61 62 static File tmpBase; 63 static File workDir; 64 static File appResourcesDir; 65 static File fakeMainJar; 66 static File hdpiIcon; 67 static Set<File> appResources; 68 static boolean retain = false; 69 70 @BeforeClass 71 public static void prepareApp() throws IOException { 167 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 168 169 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 170 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); 171 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 172 bundleParams.put(MAIN_JAR.getID(), 173 new RelativeFileSet(fakeMainJar.getParentFile(), 174 new HashSet<>(Arrays.asList(fakeMainJar))) 175 ); 176 bundleParams.put(CLASSPATH.getID(), fakeMainJar.toString()); 177 bundleParams.put(IDENTIFIER.getID(), "com.example.javapacakger.hello.TestPackager"); 178 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 179 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 180 bundleParams.put(VERBOSE.getID(), true); 181 182 boolean valid = bundler.validate(bundleParams); 183 assertTrue(valid); 184 185 File result = bundler.execute(bundleParams, new File(workDir, "smoke")); 186 System.err.println("Bundle at - " + result); 187 assertNotNull(result); 188 assertTrue(result.exists()); 189 assertTrue(result.length() > MIN_SIZE); 190 } 191 192 @Test 193 public void configureEverything() throws Exception { 194 AbstractBundler bundler = new MacAppStoreBundler(); 195 Collection<BundlerParamInfo<?>> parameters = bundler.getBundleParameters(); 196 197 Map<String, Object> bundleParams = new HashMap<>(); 198 199 bundleParams.put(APP_NAME.getID(), "Everything App Name"); 200 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 201 bundleParams.put(BUNDLE_ID_SIGNING_PREFIX.getID(), "everything.signing.prefix."); 202 bundleParams.put(ICON_ICNS.getID(), hdpiIcon); 203 bundleParams.put(JVM_OPTIONS.getID(), "-Xms128M"); 204 bundleParams.put(JVM_PROPERTIES.getID(), "everything.jvm.property=everything.jvm.property.value"); 205 bundleParams.put(MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 206 bundleParams.put(MAC_CF_BUNDLE_IDENTIFIER.getID(), "com.example.everything.cf-bundle-identifier"); 207 bundleParams.put(MAC_CF_BUNDLE_NAME.getID(), "Everything CF Bundle Name"); 208 bundleParams.put(MAC_RUNTIME.getID(), System.getProperty("java.home")); 209 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); 234 } 235 236 // assert they resolve 237 for (BundlerParamInfo bi :parameters) { 238 bi.fetchFrom(bundleParams); 239 } 240 241 // now that we are done scoping out parameters add more esoteric values 242 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 243 bundleParams.put(VERBOSE.getID(), true); 244 245 // assert it validates 246 boolean valid = bundler.validate(bundleParams); 247 assertTrue(valid); 248 249 // only run the bundle with full tests 250 Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST"))); 251 252 File result = bundler.execute(bundleParams, new File(workDir, "everything")); 253 System.err.println("Bundle at - " + result); 254 assertNotNull(result); 255 assertTrue(result.exists()); 256 assertTrue(result.length() > MIN_SIZE); 257 } 258 } | 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.util.Arrays; 46 import java.util.Collection; 47 import java.util.HashMap; 48 import java.util.HashSet; 49 import java.util.Map; 50 import java.util.Set; 51 import java.util.TreeMap; 52 import java.util.regex.Matcher; 53 import java.util.regex.Pattern; 54 55 import static com.oracle.tools.packager.StandardBundlerParam.*; 56 import static com.oracle.tools.packager.mac.MacAppBundler.*; 57 import static com.oracle.tools.packager.mac.MacAppStoreBundler.*; 58 import static org.junit.Assert.*; 59 60 public class MacAppStoreBundlerTest { 61 62 static final int MIN_SIZE=0x100000; // 1MiB 63 64 static File tmpBase; 65 static File workDir; 66 static File appResourcesDir; 67 static File fakeMainJar; 68 static File hdpiIcon; 69 static Set<File> appResources; 70 static boolean retain = false; 71 72 @BeforeClass 73 public static void prepareApp() throws IOException { 169 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 170 171 bundleParams.put(APP_NAME.getID(), "Smoke Test"); 172 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); 173 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); 174 bundleParams.put(MAIN_JAR.getID(), 175 new RelativeFileSet(fakeMainJar.getParentFile(), 176 new HashSet<>(Arrays.asList(fakeMainJar))) 177 ); 178 bundleParams.put(CLASSPATH.getID(), fakeMainJar.toString()); 179 bundleParams.put(IDENTIFIER.getID(), "com.example.javapacakger.hello.TestPackager"); 180 bundleParams.put(MacAppBundler.MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 181 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 182 bundleParams.put(VERBOSE.getID(), true); 183 184 boolean valid = bundler.validate(bundleParams); 185 assertTrue(valid); 186 187 File result = bundler.execute(bundleParams, new File(workDir, "smoke")); 188 System.err.println("Bundle at - " + result); 189 190 checkFiles(result); 191 } 192 193 private void checkFiles(File result) throws IOException { 194 assertNotNull(result); 195 assertTrue(result.exists()); 196 assertTrue(result.length() > MIN_SIZE); 197 198 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 199 PrintStream printStream = new PrintStream(baos, true); 200 IOUtils.exec( 201 new ProcessBuilder("pkgutil", "--payload-files", result.getCanonicalPath()), 202 false, false, printStream); 203 204 String output = baos.toString(); 205 206 Pattern jreInfoPListPattern = Pattern.compile("/PlugIns/[^/]+/Contents/Info\\.plist"); 207 Matcher matcher = jreInfoPListPattern.matcher(output); 208 assertTrue("Insure that info.plist is packed in for embedded jre", matcher.find()); 209 210 assertFalse("Insure JFX Media isn't packed in", output.contains("/libjfxmedia.dylib")); 211 } 212 213 @Test 214 public void configureEverything() throws Exception { 215 AbstractBundler bundler = new MacAppStoreBundler(); 216 Collection<BundlerParamInfo<?>> parameters = bundler.getBundleParameters(); 217 218 Map<String, Object> bundleParams = new HashMap<>(); 219 220 bundleParams.put(APP_NAME.getID(), "Everything App Name"); 221 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 222 bundleParams.put(BUNDLE_ID_SIGNING_PREFIX.getID(), "everything.signing.prefix."); 223 bundleParams.put(ICON_ICNS.getID(), hdpiIcon); 224 bundleParams.put(JVM_OPTIONS.getID(), "-Xms128M"); 225 bundleParams.put(JVM_PROPERTIES.getID(), "everything.jvm.property=everything.jvm.property.value"); 226 bundleParams.put(MAC_CATEGORY.getID(), "public.app-category.developer-tools"); 227 bundleParams.put(MAC_CF_BUNDLE_IDENTIFIER.getID(), "com.example.everything.cf-bundle-identifier"); 228 bundleParams.put(MAC_CF_BUNDLE_NAME.getID(), "Everything CF Bundle Name"); 229 bundleParams.put(MAC_RUNTIME.getID(), System.getProperty("java.home")); 230 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); 255 } 256 257 // assert they resolve 258 for (BundlerParamInfo bi :parameters) { 259 bi.fetchFrom(bundleParams); 260 } 261 262 // now that we are done scoping out parameters add more esoteric values 263 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 264 bundleParams.put(VERBOSE.getID(), true); 265 266 // assert it validates 267 boolean valid = bundler.validate(bundleParams); 268 assertTrue(valid); 269 270 // only run the bundle with full tests 271 Assume.assumeTrue(Boolean.parseBoolean(System.getProperty("FULL_TEST"))); 272 273 File result = bundler.execute(bundleParams, new File(workDir, "everything")); 274 System.err.println("Bundle at - " + result); 275 276 checkFiles(result); 277 } 278 } |