]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow specifying version per java package (#10322) 47/447/1
authorArtur Signell <artur@vaadin.com>
Sun, 2 Dec 2012 09:16:17 +0000 (11:16 +0200)
committerArtur Signell <artur@vaadin.com>
Sun, 2 Dec 2012 09:16:17 +0000 (11:16 +0200)
Change-Id: Ib7cba6c4229c3a213efb57f096800268c5dd3512

buildhelpers/src/com/vaadin/buildhelpers/GeneratePackageExports.java

index 0a69fbdf9765e0298ef82b5b7339b50490981918..e2786dd4d868c6117f227197a49cf20241132c94 100644 (file)
@@ -10,6 +10,7 @@ import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
+import java.util.logging.Logger;
 
 /**
  * Generates Export-Packages attribute for OSGi compatible manifest.
@@ -33,7 +34,6 @@ public class GeneratePackageExports {
                             + "Use -Dvaadin.version to specify the version to be used for the packages");
             System.exit(1);
         }
-        String vaadinVersion = System.getProperty("vaadin.version");
 
         // Open the JAR
         String jarFilename = args[0];
@@ -59,7 +59,7 @@ public class GeneratePackageExports {
             return;
         }
 
-        String exportPackage = sortAndJoinPackages(packages, vaadinVersion);
+        String exportPackage = sortAndJoinPackages(packages);
 
         // Read old manifest
         Manifest oldMF = null;
@@ -97,8 +97,7 @@ public class GeneratePackageExports {
         }
     }
 
-    private static String sortAndJoinPackages(HashSet<String> packages,
-            String vaadinVersion) {
+    private static String sortAndJoinPackages(HashSet<String> packages) {
         // Produce an ordered listing of the package names
         String packageArray[] = new String[packages.size()];
         packages.toArray(packageArray);
@@ -108,9 +107,13 @@ public class GeneratePackageExports {
             if (i != 0) {
                 joinedPackages.append(",");
             }
+            String version = getVersion(packageArray[i]);
             String packageAndVersion = packageArray[i];
-            if (vaadinVersion != null) {
-                packageAndVersion += ";version=\"" + vaadinVersion + "\"";
+            if (version != null) {
+                packageAndVersion += ";version=\"" + version + "\"";
+            } else {
+                Logger.getLogger(GeneratePackageExports.class.getName())
+                        .severe("No version defined for " + packageArray[i]);
             }
             joinedPackages.append(packageAndVersion);
         }
@@ -118,6 +121,39 @@ public class GeneratePackageExports {
         return joinedPackages.toString();
     }
 
+    /**
+     * Tries to find version specified using system properties of type
+     * version.<java package>. Searches for the packge and then its parents
+     * recursively. Falls back to the "vaadin.version" system property if no
+     * other properties are found.
+     * 
+     * @param javaPackage
+     *            The package to determine a version for
+     * @return A version or null if no version has been defined
+     */
+    private static String getVersion(String javaPackage) {
+        String packageVersion = System.getProperty("version." + javaPackage);
+        if (packageVersion != null) {
+            return packageVersion;
+        }
+        String parentPackage = null;
+        if (javaPackage.contains(".")) {
+            parentPackage = javaPackage.substring(0,
+                    javaPackage.lastIndexOf('.'));
+            String parentVersion = getVersion(parentPackage);
+            if (parentVersion != null) {
+                return parentVersion;
+            }
+        }
+
+        String vaadinVersion = System.getProperty("vaadin.version");
+        if (vaadinVersion != null) {
+            return vaadinVersion;
+        }
+
+        return null;
+    }
+
     private static HashSet<String> getPackages(JarFile jar,
             List<String> acceptedPackagePrefixes) {
         HashSet<String> packages = new HashSet<String>();