changeset 6639:0d1ee234cb2e

RT-36323: [Packager] License files not validated Summary: for bundles that accept a licenceFile the validate method should validate the license file can be found and thow an error if not
author shemnon
date Mon, 07 Apr 2014 20:55:38 -0600
parents 930c2035c980
children 8ab1fc996d14
files modules/fxpackager/src/main/java/com/oracle/bundlers/mac/MacPKGBundler.java modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxDebBundler.java modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxRPMBundler.java modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/MacDMGBundler.java modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/RelativeFileSet.java modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/WinExeBundler.java modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxDebBundler.properties modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties modules/fxpackager/src/main/resources/com/oracle/bundlers/mac/MacDMGBundler.properties modules/fxpackager/src/main/resources/com/oracle/bundlers/mac/MacPKGBundler.properties modules/fxpackager/src/main/resources/com/oracle/bundlers/windows/WinExeBundler.properties modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxDebBundlerTest.java modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacDMGBundlerTest.java modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacPKGBundlerTest.java modules/fxpackager/src/test/java/com/oracle/bundlers/windows/WinEXEBundlerTest.java
diffstat 16 files changed, 177 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxpackager/src/main/java/com/oracle/bundlers/mac/MacPKGBundler.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/oracle/bundlers/mac/MacPKGBundler.java	Mon Apr 07 20:55:38 2014 -0600
@@ -30,6 +30,7 @@
 import com.sun.javafx.tools.packager.Log;
 import com.sun.javafx.tools.packager.bundlers.ConfigException;
 import com.sun.javafx.tools.packager.bundlers.IOUtils;
+import com.sun.javafx.tools.packager.bundlers.RelativeFileSet;
 import com.sun.javafx.tools.packager.bundlers.UnsupportedPlatformException;
 import com.sun.javafx.tools.resource.mac.MacResources;
 
@@ -430,12 +431,25 @@
                     I18N.getString("error.parameters-null"),
                     I18N.getString("error.parameters-null.advice"));
 
-            // hdiutil is always available so there's no need to test for availability.
-            //run basic validation to ensure requirements are met
-
             //run basic validation to ensure requirements are met
             //we are not interested in return code, only possible exception
             APP_BUNDLER.fetchFrom(params).doValidate(params);
+
+            // validate license file, if used, exists in the proper place
+            if (params.containsKey(LICENSE_FILE.getID())) {
+                RelativeFileSet appResources = APP_RESOURCES.fetchFrom(params);
+                for (String license : LICENSE_FILE.fetchFrom(params)) {
+                    if (!appResources.contains(license)) {
+                        throw new ConfigException(
+                                I18N.getString("error.license-missing"),
+                                MessageFormat.format(I18N.getString("error.license-missing.advice"),
+                                        license, appResources.getBaseDirectory().toString()));
+                    }
+                }
+            }
+
+            // hdiutil is always available so there's no need to test for availability.
+
             return true;
         } catch (RuntimeException re) {
             throw new ConfigException(re);
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxDebBundler.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxDebBundler.java	Mon Apr 07 20:55:38 2014 -0600
@@ -198,6 +198,21 @@
                         I18N.getString("error.tool-not-found.advice"));
             }
 
+            // validate license file, if used, exists in the proper place
+            if (p.containsKey(LICENSE_FILE.getID())) {
+                RelativeFileSet appResources = APP_RESOURCES.fetchFrom(p);
+                for (String license : LICENSE_FILE.fetchFrom(p)) {
+                    if (!appResources.contains(license)) {
+                        throw new ConfigException(
+                                I18N.getString("error.license-missing"),
+                                MessageFormat.format(I18N.getString("error.license-missing.advice"),
+                                        license, appResources.getBaseDirectory().toString()));
+                    }
+                }
+            } else {
+                Log.info("message.debs-like-licenses");
+            }
+
             return true;
         } catch (RuntimeException re) {
             throw new ConfigException(re);
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxRPMBundler.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxRPMBundler.java	Mon Apr 07 20:55:38 2014 -0600
@@ -134,7 +134,20 @@
             //we are not interested in return code, only possible exception
             APP_BUNDLER.fetchFrom(p).doValidate(p);
 
-            //TODO: validate presense of required tools?
+            // validate license file, if used, exists in the proper place
+            if (p.containsKey(LICENSE_FILE.getID())) {
+                RelativeFileSet appResources = APP_RESOURCES.fetchFrom(p);
+                for (String license : LICENSE_FILE.fetchFrom(p)) {
+                    if (!appResources.contains(license)) {
+                        throw new ConfigException(
+                                I18N.getString("error.license-missing"),
+                                MessageFormat.format(I18N.getString("error.license-missing.advice"),
+                                        license, appResources.getBaseDirectory().toString()));
+                    }
+                }
+            }
+
+            //validate presense of required tools
             if (!testTool(TOOL_RPMBUILD, TOOL_RPMBUILD_MIN_VERSION)){
                 throw new ConfigException(
                         I18N.getString(MessageFormat.format("error.cannot-find-rpmbuild", TOOL_RPMBUILD_MIN_VERSION)),
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/MacDMGBundler.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/MacDMGBundler.java	Mon Apr 07 20:55:38 2014 -0600
@@ -31,12 +31,16 @@
 import sun.misc.BASE64Encoder;
 
 import java.io.*;
+import java.text.MessageFormat;
 import java.util.*;
 
 import static com.oracle.bundlers.StandardBundlerParam.*;
 
 public class MacDMGBundler extends MacBaseInstallerBundler {
 
+    private static final ResourceBundle I18N =
+            ResourceBundle.getBundle("com.oracle.bundlers.mac.MacDMGBundler");
+
     static final String DEFAULT_BACKGROUND_IMAGE="background_dmg.png";
     static final String DEFAULT_DMG_SETUP_SCRIPT="DMGsetup.scpt";
     static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns";
@@ -455,19 +459,32 @@
     @Override
     public boolean validate(Map<String, ? super Object> params) throws UnsupportedPlatformException, ConfigException {
         try {
-            if (params == null) throw new ConfigException("Parameters map is null.", "Pass in a non-null parameters map.");
-
-            // hdiutil is always available so there's no need to test for availability.
-            //run basic validation to ensure requirements are met
+            if (params == null) throw new ConfigException(
+                    I18N.getString("error.parameters-null"),
+                    I18N.getString("error.parameters-null.advice"));
 
             //run basic validation to ensure requirements are met
             //we are not interested in return code, only possible exception
             validateAppImageAndBundeler(params);
 
+            // hdiutil is always available so there's no need to test for availability.
             if (SERVICE_HINT.fetchFrom(params)) {
                 throw new ConfigException(
-                        "DMG bundler doesn't support services.",
-                        "Make sure that the service hint is set to false.");
+                        I18N.getString("error.dmg-does-not-do-daemons"),
+                        I18N.getString("error.dmg-does-not-do-daemons.advice"));
+            }
+
+            // validate license file, if used, exists in the proper place
+            if (params.containsKey(LICENSE_FILE.getID())) {
+                RelativeFileSet appResources = APP_RESOURCES.fetchFrom(params);
+                for (String license : LICENSE_FILE.fetchFrom(params)) {
+                    if (!appResources.contains(license)) {
+                        throw new ConfigException(
+                                I18N.getString("error.license-missing"),
+                                MessageFormat.format(com.sun.imageio.plugins.common.I18N.getString("error.license-missing.advice"),
+                                        license, appResources.getBaseDirectory().toString()));
+                    }
+                }
             }
 
             return true;
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/RelativeFileSet.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/RelativeFileSet.java	Mon Apr 07 20:55:38 2014 -0600
@@ -63,6 +63,15 @@
         return result;
     }
 
+    public boolean contains(String requiredFile) {
+        if (files.contains(requiredFile)) {
+            return true;
+        } else {
+            Log.debug("  Runtime does not contain [" + requiredFile + "]");
+            return false;
+        }
+    }
+
     public File getBaseDirectory() {
         return basedir;
     }
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/WinExeBundler.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/WinExeBundler.java	Mon Apr 07 20:55:38 2014 -0600
@@ -224,10 +224,24 @@
             //we are not interested in return code, only possible exception
             APP_BUNDLER.fetchFrom(p).validate(p);
 
+            // validate license file, if used, exists in the proper place
+            if (p.containsKey(LICENSE_FILE.getID())) {
+                RelativeFileSet appResources = APP_RESOURCES.fetchFrom(p);
+                for (String license : LICENSE_FILE.fetchFrom(p)) {
+                    if (!appResources.contains(license)) {
+                        throw new ConfigException(
+                                I18N.getString("error.license-missing"),
+                                MessageFormat.format(I18N.getString("error.license-missing.advice"),
+                                        license, appResources.getBaseDirectory().toString()));
+                    }
+                }
+            }
+
+
             if (SERVICE_HINT.fetchFrom(p)) {
-                SERVICE_BUNDLER.fetchFrom(p).validate(p);                
+                SERVICE_BUNDLER.fetchFrom(p).validate(p);
             }
-            
+
             double innoVersion = findToolVersion(TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p));
 
             //Inno Setup 5+ is required
--- a/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxDebBundler.properties	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxDebBundler.properties	Mon Apr 07 20:55:38 2014 -0600
@@ -48,6 +48,8 @@
 error.parameters-null.advice=Pass in a non-null parameters map.
 error.tool-not-found=Can not find {0}.
 error.tool-not-found.advice=\  Please install required packages.
+error.license-missing=Specified license file is missing.
+error.license-missing.advice=Make sure that {0} references a file in the app resources, and that it is relative to the basedir {1}.
 
 message.test-for-tool=Test for [{0}]. Result\: {1}
 message.debug-working-directory=Kept working directory for debug\: {0}
--- a/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties	Mon Apr 07 20:55:38 2014 -0600
@@ -22,6 +22,8 @@
 error.parameters-null.advice=Pass in a non-null parameters map.
 error.cannot-find-rpmbuild=Can not find rpmbuild {0} or newer.
 error.cannot-find-rpmbuild.advice=\  Install packages needed to build RPM, version {0} or newer.
+error.license-missing=Specified license file is missing.
+error.license-missing.advice=Make sure that {0} references a file in the app resources, and that it is relative to the basedir {1}.
 
 message.test-for-tool=Test for [{0}]. Result\: {1}
 message.one-shortcut-required=At least one type of shortcut is required. Enabling menu shortcut.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/mac/MacDMGBundler.properties	Mon Apr 07 20:55:38 2014 -0600
@@ -0,0 +1,6 @@
+error.parameters-null=Parameters map is null.
+error.parameters-null.advice=Pass in a non-null parameters map.
+error.dmg-does-not-do-daemons=DMG bundler doesn't support services.
+error.dmg-does-not-do-daemons.advice=Make sure that the service hint is set to false.
+error.license-missing=Specified license file is missing.
+error.license-missing.advice=Make sure that {0} references a file in the app resources, and that it is relative to the basedir {1}.
--- a/modules/fxpackager/src/main/resources/com/oracle/bundlers/mac/MacPKGBundler.properties	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/mac/MacPKGBundler.properties	Mon Apr 07 20:55:38 2014 -0600
@@ -15,6 +15,8 @@
 
 error.parameters-null=Parameters map is null.
 error.parameters-null.advice=Pass in a non-null parameters map.
+error.license-missing=Specified license file is missing.
+error.license-missing.advice=Make sure that {0} references a file in the app resources, and that it is relative to the basedir {1}.
 
 message.building-pkg=Building PKG package for {0}
 message.preparing-scripts=Preparing package scripts
--- a/modules/fxpackager/src/main/resources/com/oracle/bundlers/windows/WinExeBundler.properties	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/windows/WinExeBundler.properties	Mon Apr 07 20:55:38 2014 -0600
@@ -30,6 +30,8 @@
 error.parameters-null.advice=Pass in a non-null parameters map.
 error.iscc-not-found=Can not find Inno Setup Compiler (iscc.exe).
 error.iscc-not-found.advice=\  Download Inno Setup 5 or later from http\://www.jrsoftware.org and add it to the PATH.
+error.license-missing=Specified license file is missing.
+error.license-missing.advice=Make sure that {0} references a file in the app resources, and that it is relative to the basedir {1}.
 
 message.tool-wrong-version=Detected [{0}] version {1} but version {2} is required.
 message.debug-working-directory=Kept working directory for debug\: {0}
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxDebBundlerTest.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxDebBundlerTest.java	Mon Apr 07 20:55:38 2014 -0600
@@ -173,4 +173,17 @@
         assertTrue(output.exists());
     }
 
+    @Test(expected = ConfigException.class)
+    public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
+        Bundler bundler = new LinuxDebBundler();
+
+        Map<String, Object> 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);
+    }
 }
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java	Mon Apr 07 20:55:38 2014 -0600
@@ -176,4 +176,18 @@
         assertTrue(output.exists());
     }
 
+
+    @Test(expected = ConfigException.class)
+    public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
+        Bundler bundler = new LinuxRPMBundler();
+
+        Map<String, Object> 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);
+    }
 }
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacDMGBundlerTest.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacDMGBundlerTest.java	Mon Apr 07 20:55:38 2014 -0600
@@ -172,4 +172,18 @@
         assertNotNull(output);
         assertTrue(output.exists());
     }
+
+    @Test(expected = ConfigException.class)
+    public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
+        Bundler bundler = new MacDMGBundler();
+
+        Map<String, Object> 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);
+    }
 }
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacPKGBundlerTest.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/mac/MacPKGBundlerTest.java	Mon Apr 07 20:55:38 2014 -0600
@@ -218,4 +218,18 @@
         assertNotNull(output);
         assertTrue(output.exists());
     }
+
+    @Test(expected = ConfigException.class)
+    public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
+        Bundler bundler = new MacPKGBundler();
+
+        Map<String, Object> 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);
+    }
 }
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/windows/WinEXEBundlerTest.java	Mon Apr 07 19:12:04 2014 -0600
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/windows/WinEXEBundlerTest.java	Mon Apr 07 20:55:38 2014 -0600
@@ -215,4 +215,18 @@
         File output = bundler.execute(bundleParams, new File(workDir, "NullISSC"));
         assertNull(output);
     }
+
+    @Test(expected = ConfigException.class)
+    public void invalidLicenseFile() throws ConfigException, UnsupportedPlatformException {
+        Bundler bundler = new WinExeBundler();
+
+        Map<String, Object> 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);
+    }
 }