6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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 new File(appResourcesDir, "LICENSE"),
75 new File(appResourcesDir, "LICENSE2")
76 ));
77 }
78
79 @Before
80 public void createTmpDir() throws IOException {
81 if (retain) {
82 tmpBase = new File("build/tmp/tests/linuxrpm");
83 } else {
101 attemptDelete(f);
102 }
103 }
104 }
105 boolean success;
106 try {
107 success = !tmpBase.exists() || tmpBase.delete();
108 } catch (SecurityException se) {
109 success = false;
110 }
111 if (!success) {
112 System.err.println("Could not clean up " + tmpBase.toString());
113 }
114 }
115
116 /**
117 * See if smoke comes out
118 */
119 @Test
120 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException {
121 Bundler bundler = new LinuxRPMBundler();
122
123 assertNotNull(bundler.getName());
124 assertNotNull(bundler.getID());
125 assertNotNull(bundler.getDescription());
126 //assertNotNull(bundler.getBundleParameters());
127
128 Map<String, Object> bundleParams = new HashMap<>();
129
130 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
131
132 bundleParams.put(APP_NAME.getID(), "Smoke");
133 bundleParams.put(LinuxRPMBundler.BUNDLE_NAME.getID(), "smokeybundlename");
134 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager");
135 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id");
136 bundleParams.put(MAIN_JAR.getID(),
137 new RelativeFileSet(fakeMainJar.getParentFile(),
138 new HashSet<>(Arrays.asList(fakeMainJar)))
139 );
140 bundleParams.put(MAIN_JAR_CLASSPATH.getID(), fakeMainJar.toString());
141 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
142 bundleParams.put(LICENSE_FILE.getID(), Arrays.asList("LICENSE", "LICENSE2"));
143 bundleParams.put(LICENSE_TYPE.getID(), "GPL2 + Classpath Exception");
144 bundleParams.put(VERBOSE.getID(), true);
145 bundleParams.put(ICON.getID(), "java-logo2.gif"); // force no signing
146
147 boolean valid = bundler.validate(bundleParams);
148 assertTrue(valid);
149
150 File result = bundler.execute(bundleParams, new File(workDir, "smoke"));
151 System.err.println("Bundle at - " + result);
152 assertNotNull(result);
153 assertTrue(result.exists());
154 }
155
156 /**
157 * The bare minimum configuration needed to make it work
158 * <ul>
159 * <li>Where to build it</li>
160 * <li>The jar containing the application (with a main-class attribute)</li>
161 * </ul>
162 *
163 * All other values will be driven off of those two values.
164 */
165 @Test
166 public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException {
167 Bundler bundler = new LinuxRPMBundler();
168
169 Map<String, Object> bundleParams = new HashMap<>();
170
171 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
172
173 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
174
175 bundler.validate(bundleParams);
176 File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum"));
177 System.err.println("Bundle at - " + output);
178 assertNotNull(output);
179 assertTrue(output.exists());
180 }
181
182
183 @Test(expected = ConfigException.class)
184 public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
185 Bundler bundler = new LinuxRPMBundler();
186
187 Map<String, Object> bundleParams = new HashMap<>();
188
189 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
190
191 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
192 bundleParams.put(LICENSE_FILE.getID(), "BOGUS_LICENSE");
193
194 bundler.validate(bundleParams);
195 }
196 }
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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.linux;
27
28 import com.oracle.tools.packager.Bundler;
29 import com.oracle.tools.packager.Log;
30 import com.oracle.tools.packager.ConfigException;
31 import com.oracle.tools.packager.RelativeFileSet;
32 import com.oracle.tools.packager.UnsupportedPlatformException;
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 com.oracle.tools.packager.StandardBundlerParam.*;
45 import static org.junit.Assert.assertNotNull;
46 import static org.junit.Assert.assertTrue;
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", "linuxrpm");
69 appResourcesDir = new File("build/tmp/tests", "appResources");
70 fakeMainJar = new File(appResourcesDir, "mainApp.jar");
71
72 appResources = new HashSet<>(Arrays.asList(fakeMainJar,
73 new File(appResourcesDir, "LICENSE"),
74 new File(appResourcesDir, "LICENSE2")
75 ));
76 }
77
78 @Before
79 public void createTmpDir() throws IOException {
80 if (retain) {
81 tmpBase = new File("build/tmp/tests/linuxrpm");
82 } else {
100 attemptDelete(f);
101 }
102 }
103 }
104 boolean success;
105 try {
106 success = !tmpBase.exists() || tmpBase.delete();
107 } catch (SecurityException se) {
108 success = false;
109 }
110 if (!success) {
111 System.err.println("Could not clean up " + tmpBase.toString());
112 }
113 }
114
115 /**
116 * See if smoke comes out
117 */
118 @Test
119 public void smokeTest() throws IOException, ConfigException, UnsupportedPlatformException {
120 Bundler bundler = new LinuxRpmBundler();
121
122 assertNotNull(bundler.getName());
123 assertNotNull(bundler.getID());
124 assertNotNull(bundler.getDescription());
125 //assertNotNull(bundler.getBundleParameters());
126
127 Map<String, Object> bundleParams = new HashMap<>();
128
129 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
130
131 bundleParams.put(APP_NAME.getID(), "Smoke");
132 bundleParams.put(LinuxRpmBundler.BUNDLE_NAME.getID(), "smokeybundlename");
133 bundleParams.put(MAIN_CLASS.getID(), "hello.TestPackager");
134 bundleParams.put(PREFERENCES_ID.getID(), "the/really/long/preferences/id");
135 bundleParams.put(MAIN_JAR.getID(),
136 new RelativeFileSet(fakeMainJar.getParentFile(),
137 new HashSet<>(Arrays.asList(fakeMainJar)))
138 );
139 bundleParams.put(MAIN_JAR_CLASSPATH.getID(), fakeMainJar.toString());
140 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
141 bundleParams.put(LICENSE_FILE.getID(), Arrays.asList("LICENSE", "LICENSE2"));
142 bundleParams.put(LICENSE_TYPE.getID(), "GPL2 + Classpath Exception");
143 bundleParams.put(VERBOSE.getID(), true);
144 bundleParams.put(ICON.getID(), "java-logo2.gif"); // force no signing
145
146 boolean valid = bundler.validate(bundleParams);
147 assertTrue(valid);
148
149 File result = bundler.execute(bundleParams, new File(workDir, "smoke"));
150 System.err.println("Bundle at - " + result);
151 assertNotNull(result);
152 assertTrue(result.exists());
153 }
154
155 /**
156 * The bare minimum configuration needed to make it work
157 * <ul>
158 * <li>Where to build it</li>
159 * <li>The jar containing the application (with a main-class attribute)</li>
160 * </ul>
161 *
162 * All other values will be driven off of those two values.
163 */
164 @Test
165 public void minimumConfig() throws IOException, ConfigException, UnsupportedPlatformException {
166 Bundler bundler = new LinuxRpmBundler();
167
168 Map<String, Object> bundleParams = new HashMap<>();
169
170 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
171
172 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
173
174 bundler.validate(bundleParams);
175 File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum"));
176 System.err.println("Bundle at - " + output);
177 assertNotNull(output);
178 assertTrue(output.exists());
179 }
180
181 @Test(expected = ConfigException.class)
182 public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
183 Bundler bundler = new LinuxRpmBundler();
184
185 Map<String, Object> bundleParams = new HashMap<>();
186
187 bundleParams.put(BUILD_ROOT.getID(), tmpBase);
188
189 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
190 bundleParams.put(LICENSE_FILE.getID(), "BOGUS_LICENSE");
191
192 bundler.validate(bundleParams);
193 }
194 }
|