--- old/modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacPKGBundlerTest.java 2014-04-29 11:32:38.000000000 -0600 +++ /dev/null 2014-04-29 11:32:38.000000000 -0600 @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.oracle.bundlers.mac; - -import com.oracle.bundlers.*; -import com.oracle.bundlers.Bundler; -import com.sun.javafx.tools.packager.Log; -import com.sun.javafx.tools.packager.bundlers.*; -import org.junit.After; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.*; - -import static com.oracle.bundlers.StandardBundlerParam.*; -import static com.sun.javafx.tools.packager.bundlers.MacAppBundler.DEVELOPER_ID_APP_SIGNING_KEY; -import static com.oracle.bundlers.mac.MacPKGBundler.DEVELOPER_ID_INSTALLER_SIGNING_KEY; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class MacPKGBundlerTest { - - static File tmpBase; - static File workDir; - static File appResourcesDir; - static File fakeMainJar; - static Set appResources; - static boolean retain = false; - - @BeforeClass - public static void prepareApp() { - // only run on mac - Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("os x")); - - Log.setLogger(new Log.Logger(true)); - - retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); - - workDir = new File("build/tmp/tests", "macpkg"); - appResourcesDir = new File("build/tmp/tests", "appResources"); - fakeMainJar = new File(appResourcesDir, "mainApp.jar"); - - appResources = new HashSet<>(Arrays.asList(fakeMainJar, - new File(appResourcesDir, "LICENSE"), - new File(appResourcesDir, "LICENSE2") - )); - } - - @Before - public void createTmpDir() throws IOException { - if (retain) { - tmpBase = new File("build/tmp/tests/macpkg"); - } else { - tmpBase = Files.createTempDirectory("fxpackagertests").toFile(); - } - tmpBase.mkdir(); - } - - @After - public void maybeCleanupTmpDir() { - if (!retain) { - attemptDelete(tmpBase); - } - } - - private void attemptDelete(File tmpBase) { - if (tmpBase.isDirectory()) { - File[] children = tmpBase.listFiles(); - if (children != null) { - for (File f : children) { - attemptDelete(f); - } - } - } - boolean success; - try { - success = !tmpBase.exists() || tmpBase.delete(); - } catch (SecurityException se) { - success = false; - } - if (!success) { - System.err.println("Could not clean up " + tmpBase.toString()); - } - } - - /** - * See if smoke comes out - */ - @Test - public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { - AbstractBundler bundler = new MacPKGBundler(); - - assertNotNull(bundler.getName()); - assertNotNull(bundler.getID()); - assertNotNull(bundler.getDescription()); - //assertNotNull(bundler.getBundleParameters()); - - Map bundleParams = new HashMap<>(); - - bundleParams.put(BUILD_ROOT.getID(), tmpBase); - - bundleParams.put(APP_NAME.getID(), "Smoke"); - bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); - bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); - bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); - bundleParams.put(MAIN_JAR.getID(), - new RelativeFileSet(fakeMainJar.getParentFile(), - new HashSet<>(Arrays.asList(fakeMainJar))) - ); - bundleParams.put(MAIN_JAR_CLASSPATH.getID(), fakeMainJar.toString()); - bundleParams.put(VERBOSE.getID(), true); - bundleParams.put(LICENSE_FILE.getID(), Arrays.asList("LICENSE", "LICENSE2")); - bundleParams.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null); // force no signing - bundleParams.put(DEVELOPER_ID_INSTALLER_SIGNING_KEY.getID(), null); // force no signing - -// bundleParams.put(StandardBundlerParam.RUNTIME.getID(), -// JreUtils.extractJreAsRelativeFileSet(MacAppBundler.adjustMacRuntimePath(System.getProperty("java.home")), -// MacAppBundler.macJDKRules)); - - boolean valid = bundler.validate(bundleParams); - assertTrue(valid); - - File result = bundler.execute(bundleParams, new File(workDir, "smoke")); - System.err.println("Bundle at - " + result); - assertNotNull(result); - assertTrue(result.exists()); - } - - /** - * Build smoke test and mark it as quarantined, possibly signed - */ - @Test - public void quarantinedAppTest() throws IOException, ConfigException, UnsupportedPlatformException { - AbstractBundler bundler = new MacPKGBundler(); - - assertNotNull(bundler.getName()); - assertNotNull(bundler.getID()); - assertNotNull(bundler.getDescription()); - //assertNotNull(bundler.getBundleParameters()); - - Map bundleParams = new HashMap<>(); - - bundleParams.put(BUILD_ROOT.getID(), tmpBase); - - bundleParams.put(APP_NAME.getID(), "Quarantine"); - bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); - bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); - bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); - bundleParams.put(VERBOSE.getID(), true); - -// bundleParams.put(StandardBundlerParam.RUNTIME.getID(), -// JreUtils.extractJreAsRelativeFileSet(MacAppBundler.adjustMacRuntimePath(System.getProperty("java.home")), -// MacAppBundler.macJDKRules)); - - boolean valid = bundler.validate(bundleParams); - assertTrue(valid); - - File result = bundler.execute(bundleParams, new File(workDir, "quarantine")); - System.err.println("Bundle at - " + result); - assertNotNull(result); - assertTrue(result.exists()); - - // mark it as though it's been downloaded - ProcessBuilder pb = new ProcessBuilder( - "xattr", "-w", "com.apple.quarantine", - "0000;" + Long.toHexString(System.currentTimeMillis() / 1000L) + ";Java Unit Tests;|com.oracle.jvm.8u", - result.toString()); - IOUtils.exec(pb, true); - } - - /** - * The bare minimum configuration needed to make it work - *
    - *
  • Where to build it
  • - *
  • The jar containing the application (with a main-class attribute)
  • - *
- * - * All other values will be driven off of those two values. - */ - @Test - public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException { - Bundler bundler = new MacPKGBundler(); - - Map bundleParams = new HashMap<>(); - - bundleParams.put(BUILD_ROOT.getID(), tmpBase); - - bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); - - File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum")); - System.err.println("Bundle at - " + output); - assertNotNull(output); - assertTrue(output.exists()); - } - - @Test(expected = ConfigException.class) - public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException { - Bundler bundler = new MacPKGBundler(); - - Map bundleParams = new HashMap<>(); - - bundleParams.put(BUILD_ROOT.getID(), tmpBase); - - bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); - bundleParams.put(LICENSE_FILE.getID(), "BOGUS_LICENSE"); - - bundler.validate(bundleParams); - } -} --- /dev/null 2014-04-29 11:32:38.000000000 -0600 +++ new/modules/fxpackager/src/test/java/com/oracle/tools/packager/mac/MacPkgBundlerTest.java 2014-04-29 11:32:38.000000000 -0600 @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.tools.packager.mac; + +import com.oracle.tools.packager.*; +import com.oracle.tools.packager.Bundler; +import com.oracle.tools.packager.IOUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.*; + +import static com.oracle.tools.packager.StandardBundlerParam.*; +import static com.oracle.tools.packager.mac.MacAppBundler.DEVELOPER_ID_APP_SIGNING_KEY; +import static com.oracle.tools.packager.mac.MacPkgBundler.DEVELOPER_ID_INSTALLER_SIGNING_KEY; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class MacPkgBundlerTest { + + static File tmpBase; + static File workDir; + static File appResourcesDir; + static File fakeMainJar; + static Set appResources; + static boolean retain = false; + + @BeforeClass + public static void prepareApp() { + // only run on mac + Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("os x")); + + Log.setLogger(new Log.Logger(true)); + + retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); + + workDir = new File("build/tmp/tests", "macpkg"); + appResourcesDir = new File("build/tmp/tests", "appResources"); + fakeMainJar = new File(appResourcesDir, "mainApp.jar"); + + appResources = new HashSet<>(Arrays.asList(fakeMainJar, + new File(appResourcesDir, "LICENSE"), + new File(appResourcesDir, "LICENSE2") + )); + } + + @Before + public void createTmpDir() throws IOException { + if (retain) { + tmpBase = new File("build/tmp/tests/macpkg"); + } else { + tmpBase = Files.createTempDirectory("fxpackagertests").toFile(); + } + tmpBase.mkdir(); + } + + @After + public void maybeCleanupTmpDir() { + if (!retain) { + attemptDelete(tmpBase); + } + } + + private void attemptDelete(File tmpBase) { + if (tmpBase.isDirectory()) { + File[] children = tmpBase.listFiles(); + if (children != null) { + for (File f : children) { + attemptDelete(f); + } + } + } + boolean success; + try { + success = !tmpBase.exists() || tmpBase.delete(); + } catch (SecurityException se) { + success = false; + } + if (!success) { + System.err.println("Could not clean up " + tmpBase.toString()); + } + } + + /** + * See if smoke comes out + */ + @Test + public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { + AbstractBundler bundler = new MacPkgBundler(); + + assertNotNull(bundler.getName()); + assertNotNull(bundler.getID()); + assertNotNull(bundler.getDescription()); + //assertNotNull(bundler.getBundleParameters()); + + Map bundleParams = new HashMap<>(); + + bundleParams.put(BUILD_ROOT.getID(), tmpBase); + + bundleParams.put(APP_NAME.getID(), "Smoke"); + bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); + bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); + bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); + bundleParams.put(MAIN_JAR.getID(), + new RelativeFileSet(fakeMainJar.getParentFile(), + new HashSet<>(Arrays.asList(fakeMainJar))) + ); + bundleParams.put(MAIN_JAR_CLASSPATH.getID(), fakeMainJar.toString()); + bundleParams.put(VERBOSE.getID(), true); + bundleParams.put(LICENSE_FILE.getID(), Arrays.asList("LICENSE", "LICENSE2")); + bundleParams.put(DEVELOPER_ID_APP_SIGNING_KEY.getID(), null); // force no signing + bundleParams.put(DEVELOPER_ID_INSTALLER_SIGNING_KEY.getID(), null); // force no signing + +// bundleParams.put(StandardBundlerParam.RUNTIME.getID(), +// JreUtils.extractJreAsRelativeFileSet(MacAppBundler.adjustMacRuntimePath(System.getProperty("java.home")), +// MacAppBundler.macJDKRules)); + + boolean valid = bundler.validate(bundleParams); + assertTrue(valid); + + File result = bundler.execute(bundleParams, new File(workDir, "smoke")); + System.err.println("Bundle at - " + result); + assertNotNull(result); + assertTrue(result.exists()); + } + + /** + * Build smoke test and mark it as quarantined, possibly signed + */ + @Test + public void quarantinedAppTest() throws IOException, ConfigException, UnsupportedPlatformException { + AbstractBundler bundler = new MacPkgBundler(); + + assertNotNull(bundler.getName()); + assertNotNull(bundler.getID()); + assertNotNull(bundler.getDescription()); + //assertNotNull(bundler.getBundleParameters()); + + Map bundleParams = new HashMap<>(); + + bundleParams.put(BUILD_ROOT.getID(), tmpBase); + + bundleParams.put(APP_NAME.getID(), "Quarantine"); + bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); + bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id"); + bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); + bundleParams.put(VERBOSE.getID(), true); + +// bundleParams.put(StandardBundlerParam.RUNTIME.getID(), +// JreUtils.extractJreAsRelativeFileSet(MacAppBundler.adjustMacRuntimePath(System.getProperty("java.home")), +// MacAppBundler.macJDKRules)); + + boolean valid = bundler.validate(bundleParams); + assertTrue(valid); + + File result = bundler.execute(bundleParams, new File(workDir, "quarantine")); + System.err.println("Bundle at - " + result); + assertNotNull(result); + assertTrue(result.exists()); + + // mark it as though it's been downloaded + ProcessBuilder pb = new ProcessBuilder( + "xattr", "-w", "com.apple.quarantine", + "0000;" + Long.toHexString(System.currentTimeMillis() / 1000L) + ";Java Unit Tests;|com.oracle.jvm.8u", + result.toString()); + IOUtils.exec(pb, true); + } + + /** + * The bare minimum configuration needed to make it work + *
    + *
  • Where to build it
  • + *
  • The jar containing the application (with a main-class attribute)
  • + *
+ * + * All other values will be driven off of those two values. + */ + @Test + public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException { + Bundler bundler = new MacPkgBundler(); + + Map bundleParams = new HashMap<>(); + + bundleParams.put(BUILD_ROOT.getID(), tmpBase); + + bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); + + File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum")); + System.err.println("Bundle at - " + output); + assertNotNull(output); + assertTrue(output.exists()); + } + + @Test(expected = ConfigException.class) + public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException { + Bundler bundler = new MacPkgBundler(); + + Map bundleParams = new HashMap<>(); + + bundleParams.put(BUILD_ROOT.getID(), tmpBase); + + bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); + bundleParams.put(LICENSE_FILE.getID(), "BOGUS_LICENSE"); + + bundler.validate(bundleParams); + } +}