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.bundlers.linux; 27 28 import com.oracle.bundlers.Bundler; 29 import com.oracle.bundlers.StandardBundlerParam; 30 import com.sun.javafx.tools.packager.Log; 31 import com.sun.javafx.tools.packager.bundlers.ConfigException; 32 import com.sun.javafx.tools.packager.bundlers.LinuxRPMBundler; 33 import com.sun.javafx.tools.packager.bundlers.RelativeFileSet; 34 import com.sun.javafx.tools.packager.bundlers.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.File; 42 import java.io.IOException; 43 import java.nio.file.Files; 44 import java.util.*; 45 46 import static org.junit.Assert.assertNotNull; 47 48 public class LinuxRpmBundlerTest { 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 linux 60 Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("linux")); 61 62 Assume.assumeTrue(LinuxRPMBundler.testTool(LinuxRPMBundler.TOOL_RPMBUILD, LinuxRPMBundler.TOOL_RPMBUILD_MIN_VERSION)); 63 64 Log.setLogger(new Log.Logger(true)); 65 66 retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); 67 68 workDir = new File("build/tmp/tests", "linuxrrpm"); 69 appResourcesDir = new File("build/tmp/tests", "appResources"); 70 fakeMainJar = new File(appResourcesDir, "mainApp.jar"); 71 72 appResources = new HashSet<>(Arrays.asList(fakeMainJar)); 73 } 74 75 @Before 76 public void createTmpDir() throws IOException { 77 if (retain) { 78 tmpBase = new File("build/tmp/tests/linuxrpm"); 79 } else { 80 tmpBase = Files.createTempDirectory("fxpackagertests").toFile(); 81 } 82 tmpBase.mkdir(); 83 } 84 85 @After 86 public void maybeCleanupTmpDir() { 87 if (!retain) { 88 attemptDelete(tmpBase); 98 } 99 } 100 } 101 boolean success; 102 try { 103 success = !tmpBase.exists() || tmpBase.delete(); 104 } catch (SecurityException se) { 105 success = false; 106 } 107 if (!success) { 108 System.err.println("Could not clean up " + tmpBase.toString()); 109 } 110 } 111 112 /** 113 * See if smoke comes out 114 */ 115 @Test 116 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { 117 Bundler bundler = new LinuxRPMBundler(); 118 ((LinuxRPMBundler)bundler).setVerbose(true); 119 120 assertNotNull(bundler.getName()); 121 assertNotNull(bundler.getID()); 122 assertNotNull(bundler.getDescription()); 123 //assertNotNull(bundler.getBundleParameters()); 124 125 Map<String, Object> bundleParams = new HashMap<>(); 126 127 bundleParams.put(StandardBundlerParam.BUILD_ROOT.getID(), tmpBase); 128 129 bundleParams.put(StandardBundlerParam.NAME.getID(), "Smoke"); 130 bundleParams.put(StandardBundlerParam.MAIN_CLASS.getID(), "hello.TestPackager"); 131 bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 132 133 bundler.validate(bundleParams); 134 bundler.execute(bundleParams, new File(workDir, "smoke")); 135 } 136 137 /** 138 * The bare minimum configuration needed to make it work 139 * <ul> 140 * <li>Where to build it</li> 141 * <li>The jar containing the application (with a main-class attribute)</li> 142 * </ul> 143 * 144 * All other values will be driven off of those two values. 145 */ 146 @Test 147 public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException { 148 Bundler bundler = new LinuxRPMBundler(); 149 ((LinuxRPMBundler)bundler).setVerbose(true); 150 151 Map<String, Object> bundleParams = new HashMap<>(); 152 153 bundleParams.put(StandardBundlerParam.BUILD_ROOT.getID(), tmpBase); 154 155 bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 156 157 bundler.validate(bundleParams); 158 File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum")); 159 System.err.println("Bundle written to " + output); 160 Assume.assumeTrue(output.isFile()); 161 } 162 163 } | 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.bundlers.linux; 27 28 import com.oracle.bundlers.Bundler; 29 import com.sun.javafx.tools.packager.Log; 30 import com.sun.javafx.tools.packager.bundlers.ConfigException; 31 import com.sun.javafx.tools.packager.bundlers.LinuxRPMBundler; 32 import com.sun.javafx.tools.packager.bundlers.RelativeFileSet; 33 import com.sun.javafx.tools.packager.bundlers.UnsupportedPlatformException; 34 import org.junit.After; 35 import org.junit.Assume; 36 import org.junit.Before; 37 import org.junit.BeforeClass; 38 import org.junit.Test; 39 40 import java.io.File; 41 import java.io.IOException; 42 import java.nio.file.Files; 43 import java.util.*; 44 45 import static com.oracle.bundlers.StandardBundlerParam.*; 46 import static org.junit.Assert.assertNotNull; 47 import static org.junit.Assert.assertTrue; 48 49 public class LinuxRpmBundlerTest { 50 51 static File tmpBase; 52 static File workDir; 53 static File appResourcesDir; 54 static File fakeMainJar; 55 static Set<File> appResources; 56 static boolean retain = false; 57 58 @BeforeClass 59 public static void prepareApp() { 60 // only run on linux 61 Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("linux")); 62 63 Assume.assumeTrue(LinuxRPMBundler.testTool(LinuxRPMBundler.TOOL_RPMBUILD, LinuxRPMBundler.TOOL_RPMBUILD_MIN_VERSION)); 64 65 Log.setLogger(new Log.Logger(true)); 66 67 retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); 68 69 workDir = new File("build/tmp/tests", "linuxrpm"); 70 appResourcesDir = new File("build/tmp/tests", "appResources"); 71 fakeMainJar = new File(appResourcesDir, "mainApp.jar"); 72 73 appResources = new HashSet<>(Arrays.asList(fakeMainJar)); 74 } 75 76 @Before 77 public void createTmpDir() throws IOException { 78 if (retain) { 79 tmpBase = new File("build/tmp/tests/linuxrpm"); 80 } else { 81 tmpBase = Files.createTempDirectory("fxpackagertests").toFile(); 82 } 83 tmpBase.mkdir(); 84 } 85 86 @After 87 public void maybeCleanupTmpDir() { 88 if (!retain) { 89 attemptDelete(tmpBase); 99 } 100 } 101 } 102 boolean success; 103 try { 104 success = !tmpBase.exists() || tmpBase.delete(); 105 } catch (SecurityException se) { 106 success = false; 107 } 108 if (!success) { 109 System.err.println("Could not clean up " + tmpBase.toString()); 110 } 111 } 112 113 /** 114 * See if smoke comes out 115 */ 116 @Test 117 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException { 118 Bundler bundler = new LinuxRPMBundler(); 119 120 assertNotNull(bundler.getName()); 121 assertNotNull(bundler.getID()); 122 assertNotNull(bundler.getDescription()); 123 //assertNotNull(bundler.getBundleParameters()); 124 125 Map<String, Object> bundleParams = new HashMap<>(); 126 127 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 128 129 bundleParams.put(APP_NAME.getID(), "Smoke"); 130 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager"); 131 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 132 bundleParams.put(VERBOSE.getID(), true); 133 134 bundler.validate(bundleParams); 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 LinuxRPMBundler(); 153 154 Map<String, Object> bundleParams = new HashMap<>(); 155 156 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 157 158 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 159 160 bundler.validate(bundleParams); 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 167 } |