modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacAppBundlerTest.java

Print this page




  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.bundlers.mac;
  27 
  28 import com.oracle.bundlers.AbstractBundler;
  29 import com.oracle.bundlers.Bundler;
  30 import com.oracle.bundlers.StandardBundlerParam;
  31 import com.sun.javafx.tools.packager.Log;
  32 import com.sun.javafx.tools.packager.bundlers.*;
  33 import org.junit.After;
  34 import org.junit.Assume;
  35 import org.junit.Before;
  36 import org.junit.BeforeClass;
  37 import org.junit.Test;
  38 
  39 import java.io.File;
  40 import java.io.IOException;
  41 import java.nio.file.Files;
  42 import java.util.*;
  43 


  44 import static org.junit.Assert.assertNotNull;
  45 import static org.junit.Assert.assertTrue;
  46 
  47 public class MacAppBundlerTest {
  48 
  49     static File tmpBase;
  50     static File workDir;
  51     static File appResourcesDir;
  52     static File fakeMainJar;
  53     static Set<File> appResources;
  54     static boolean retain = false;
  55 
  56     @BeforeClass
  57     public static void prepareApp() {
  58         // only run on mac
  59         Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("os x"));
  60 
  61         Log.setLogger(new Log.Logger(true));
  62 
  63         retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS"));


  95                 }
  96             }
  97         }
  98         boolean success;
  99         try {
 100             success = !tmpBase.exists() || tmpBase.delete();
 101         } catch (SecurityException se) {
 102             success = false;
 103         }
 104         if (!success) {
 105             System.err.println("Could not clean up " + tmpBase.toString());
 106         }
 107     }
 108 
 109     /**
 110      * See if smoke comes out
 111      */
 112     @Test
 113     public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException {
 114         AbstractBundler bundler = new MacAppBundler();
 115         bundler.setVerbose(true);
 116 
 117         assertNotNull(bundler.getName());
 118         assertNotNull(bundler.getID());
 119         assertNotNull(bundler.getDescription());
 120         //assertNotNull(bundler.getBundleParameters());
 121 
 122         Map<String, Object> bundleParams = new HashMap<>();
 123 
 124         bundleParams.put(StandardBundlerParam.BUILD_ROOT.getID(), tmpBase);
 125 
 126         bundleParams.put(StandardBundlerParam.NAME.getID(), "Smoke");
 127         bundleParams.put(StandardBundlerParam.MAIN_CLASS.getID(), "hello.TestPackager");
 128         bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 129 //        bundleParams.put(StandardBundlerParam.MAIN_JAR.getID(), new RelativeFileSet(appResourcesDir, appResources));

 130 
 131         bundleParams.put(StandardBundlerParam.RUNTIME.getID(),
 132                 StandardBundlerParam.extractJreAsRelativeFileSet("~/tools/jdk1.8.0.jdk/Contents/Home/jre"));
 133         boolean valid = bundler.validate(bundleParams);
 134         assertTrue(valid);
 135 
 136         bundler.execute(bundleParams, new File(workDir, "smoke"));



 137     }
 138 
 139     /**
 140      * The bare minimum configuration needed to make it work
 141      * <ul>
 142      *     <li>Where to build it</li>
 143      *     <li>The jar containing the application (with a main-class attribute)</li>
 144      * </ul>
 145      *
 146      * All other values will be driven off of those two values.
 147      */
 148     @Test
 149     public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException {
 150         Bundler bundler = new MacAppBundler();
 151         ((AbstractBundler)bundler).setVerbose(true);
 152 
 153         Map<String, Object> bundleParams = new HashMap<>();
 154 
 155         // not part of the typical setup, for testing
 156         bundleParams.put(StandardBundlerParam.BUILD_ROOT.getID(), tmpBase);
 157 
 158         bundleParams.put(StandardBundlerParam.NAME.getID(), "Smoke");
 159         bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 160 

 161 
 162         File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum"));
 163         assertTrue(output.isDirectory());


 164     }
 165 }


  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.bundlers.mac;
  27 
  28 import com.oracle.bundlers.AbstractBundler;
  29 import com.oracle.bundlers.Bundler;

  30 import com.sun.javafx.tools.packager.Log;
  31 import com.sun.javafx.tools.packager.bundlers.*;
  32 import org.junit.After;
  33 import org.junit.Assume;
  34 import org.junit.Before;
  35 import org.junit.BeforeClass;
  36 import org.junit.Test;
  37 
  38 import java.io.File;
  39 import java.io.IOException;
  40 import java.nio.file.Files;
  41 import java.util.*;
  42 
  43 import static com.oracle.bundlers.StandardBundlerParam.*;
  44 import static com.sun.javafx.tools.packager.bundlers.MacAppBundler.MAC_CF_BUNDLE_NAME;
  45 import static org.junit.Assert.assertNotNull;
  46 import static org.junit.Assert.assertTrue;
  47 
  48 public class MacAppBundlerTest {
  49 
  50     static File tmpBase;
  51     static File workDir;
  52     static File appResourcesDir;
  53     static File fakeMainJar;
  54     static Set<File> appResources;
  55     static boolean retain = false;
  56 
  57     @BeforeClass
  58     public static void prepareApp() {
  59         // only run on mac
  60         Assume.assumeTrue(System.getProperty("os.name").toLowerCase().contains("os x"));
  61 
  62         Log.setLogger(new Log.Logger(true));
  63 
  64         retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS"));


  96                 }
  97             }
  98         }
  99         boolean success;
 100         try {
 101             success = !tmpBase.exists() || tmpBase.delete();
 102         } catch (SecurityException se) {
 103             success = false;
 104         }
 105         if (!success) {
 106             System.err.println("Could not clean up " + tmpBase.toString());
 107         }
 108     }
 109 
 110     /**
 111      * See if smoke comes out
 112      */
 113     @Test
 114     public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException {
 115         AbstractBundler bundler = new MacAppBundler();

 116 
 117         assertNotNull(bundler.getName());
 118         assertNotNull(bundler.getID());
 119         assertNotNull(bundler.getDescription());
 120         //assertNotNull(bundler.getBundleParameters());
 121 
 122         Map<String, Object> bundleParams = new HashMap<>();
 123 
 124         bundleParams.put(BUILD_ROOT.getID(), tmpBase);
 125 
 126         bundleParams.put(APP_NAME.getID(), "Smoke Test App");
 127         bundleParams.put(MAC_CF_BUNDLE_NAME.getID(), "Smoke");
 128         bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager");
 129         bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 130         bundleParams.put(VERBOSE.getID(), true);
 131 


 132         boolean valid = bundler.validate(bundleParams);
 133         assertTrue(valid);
 134 
 135         File result = bundler.execute(bundleParams, new File(workDir, "smoke"));
 136         System.err.println("Bundle at - " + result);
 137         assertNotNull(result);
 138         assertTrue(result.exists());
 139     }
 140 
 141     /**
 142      * The bare minimum configuration needed to make it work
 143      * <ul>
 144      *     <li>Where to build it</li>
 145      *     <li>The jar containing the application (with a main-class attribute)</li>
 146      * </ul>
 147      *
 148      * All other values will be driven off of those two values.
 149      */
 150     @Test
 151     public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException {
 152         Bundler bundler = new MacAppBundler();

 153 
 154         Map<String, Object> bundleParams = new HashMap<>();
 155 
 156         // not part of the typical setup, for testing
 157         bundleParams.put(BUILD_ROOT.getID(), tmpBase);



 158 
 159         bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 160 
 161         File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum"));
 162         System.err.println("Bundle at - " + output);
 163         assertNotNull(output);
 164         assertTrue(output.exists());
 165     }
 166 }