changeset 6314:17a6e1b4b091

RT-26314: Linux packaging tools assume rpm build is always available Summary: validate the version is 4.0 or greater, throw a config exception if it isn't.
author shemnon
date Fri, 14 Feb 2014 16:38:40 -0600
parents 755652e72e11
children a3009cab6c7a
files 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/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java
diffstat 4 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxDebBundler.java	Fri Feb 14 13:20:20 2014 -0500
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxDebBundler.java	Fri Feb 14 16:38:40 2014 -0600
@@ -447,7 +447,7 @@
 
         outFile.getParentFile().mkdirs();
 
-        //run rpmbuild
+        //run dpkg
         ProcessBuilder pb = new ProcessBuilder(
                 "fakeroot", TOOL_DPKG, "-b",  FULL_PACKAGE_NAME.fetchFrom(params),
                 outFile.getAbsolutePath());
--- a/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxRPMBundler.java	Fri Feb 14 13:20:20 2014 -0500
+++ b/modules/fxpackager/src/main/java/com/sun/javafx/tools/packager/bundlers/LinuxRPMBundler.java	Fri Feb 14 16:38:40 2014 -0600
@@ -34,6 +34,8 @@
 import java.io.*;
 import java.text.MessageFormat;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static com.oracle.bundlers.StandardBundlerParam.*;
 
@@ -81,25 +83,37 @@
     private final static String DEFAULT_SPEC_TEMPLATE = "template.spec";
     private final static String DEFAULT_DESKTOP_FILE_TEMPLATE = "template.desktop";
 
-    private final static String TOOL_RPMBUILD = "rpmbuild";
+    public final static String TOOL_RPMBUILD = "rpmbuild";
+    public final static double TOOL_RPMBUILD_MIN_VERSION = 4.0d;
 
     public LinuxRPMBundler() {
         super();
         baseResourceLoader = LinuxResources.class;
     }
 
-    private boolean testTool(String toolName, String minVersion) {
-        try {
+    public static boolean testTool(String toolName, double minVersion) {
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos)) {
             ProcessBuilder pb = new ProcessBuilder(
                     toolName,
                     "--version");
-            IOUtils.exec(pb, Log.isDebug(), true); //not interested in the output
+
+            IOUtils.exec(pb, Log.isDebug(), false, ps); //not interested in the output
+
             //TODO: Version is ignored; need to extract version string and compare!
+            String content = new String(baos.toByteArray());
+            Pattern pattern = Pattern.compile("RPM version (\\d+\\.\\d+)");
+            Matcher matcher = pattern.matcher(content);
+            if (matcher.find()) {
+                String v = matcher.group(1);
+                double version = new Double(v);
+                return minVersion <= version;
+            } else {
+               return false;
+            }
         } catch (Exception e) {
             Log.verbose(MessageFormat.format(I18N.getString("message.test-for-tool"), toolName, e.getMessage()));
             return false;
         }
-        return true;
     }
 
     @Override
@@ -113,10 +127,10 @@
         APP_BUNDLER.fetchFrom(p).doValidate(p);
 
         //TODO: validate presense of required tools?
-        if (!testTool(TOOL_RPMBUILD, "4")){
+        if (!testTool(TOOL_RPMBUILD, TOOL_RPMBUILD_MIN_VERSION)){
             throw new ConfigException(
-                    I18N.getString("error.cannot-find-rpmbuild"),
-                    I18N.getString("error.cannot-find-rpmbuild.advice"));
+                    I18N.getString(MessageFormat.format("error.cannot-find-rpmbuild", TOOL_RPMBUILD_MIN_VERSION)),
+                    I18N.getString(MessageFormat.format("error.cannot-find-rpmbuild.advice", TOOL_RPMBUILD_MIN_VERSION)));
         }
 
         return true;
--- a/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties	Fri Feb 14 13:20:20 2014 -0500
+++ b/modules/fxpackager/src/main/resources/com/oracle/bundlers/linux/LinuxRpmBundler.properties	Fri Feb 14 16:38:40 2014 -0600
@@ -19,8 +19,8 @@
 
 error.parameters-null=Parameters map is null.
 error.parameters-null.advice=Pass in a non-null parameters map.
-error.cannot-find-rpmbuild=Can not find rpmbuild.
-error.cannot-find-rpmbuild.advice=\  Install packages needed to build RPM.
+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.
 
 message.test-for-tool=Test for [{0}]. Result\: {1}
 message.one-shortcut-required=At least one type of shortcut is required. Enabling menu shortcut.
--- a/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java	Fri Feb 14 13:20:20 2014 -0500
+++ b/modules/fxpackager/src/test/java/com/oracle/bundlers/linux/LinuxRpmBundlerTest.java	Fri Feb 14 16:38:40 2014 -0600
@@ -65,7 +65,8 @@
         fakeMainJar = new File(appResourcesDir, "mainApp.jar");
 
         appResources = new HashSet<>(Arrays.asList(fakeMainJar));
-        
+
+        Assume.assumeTrue(LinuxRPMBundler.testTool(LinuxRPMBundler.TOOL_RPMBUILD, LinuxRPMBundler.TOOL_RPMBUILD_MIN_VERSION));
     }
     
     /**
@@ -92,6 +93,7 @@
         bundleParams.put(StandardBundlerParam.MAIN_CLASS.getID(), "hello.TestPackager");
         bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 
+        bundler.validate(bundleParams);
         bundler.execute(bundleParams, new File(workDir, "smoke"));
         
         try {
@@ -124,6 +126,7 @@
 
         bundleParams.put(StandardBundlerParam.APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources));
 
+        bundler.validate(bundleParams);
         File output = bundler.execute(bundleParams, new File(workDir, "BareMinimum"));
         System.out.println(output);
         Assume.assumeTrue(output.isFile());