Improve RPM packaging
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Sep 2016 11:04:05 +0000 (11:04 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Sep 2016 11:04:05 +0000 (11:04 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@9185 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

demo/argeo_node_osgiboot.properties
dep/org.argeo.dep.cms.client/pom.xml
dep/org.argeo.dep.cms.node/pom.xml
dep/org.argeo.dep.cms.platform/pom.xml
dep/org.argeo.dep.cms.sdk/pom.xml
org.argeo.osgi.boot/src/org/argeo/osgi/boot/DistributionBundle.java
org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootException.java
pom.xml

index 81ffed11a447797a9f6801ccc6df6060d895f092..7f700dfcb7c153ac6e2813754a5b9f9ffc982c5d 100644 (file)
@@ -7,7 +7,7 @@ argeo.osgi.baseUrl=file:///home/mbaudier/.m2/repository/
 argeo.osgi.distributionUrl=org/argeo/commons/org.argeo.dep.cms.node/2.1.46-SNAPSHOT/org.argeo.dep.cms.node-2.1.46-SNAPSHOT.jar
 
 #argeo.osgi.distributionUrl=http://forge.argeo.org/data/public/java/argeo-2.1/org/argeo/commons/org.argeo.dep.cms.node/2.1.40/org.argeo.dep.cms.node-2.1.40.jar
-#argeo.osgi.boot.debug=true
+argeo.osgi.boot.debug=true
 
 argeo.osgi.start.1.osgiboot=org.argeo.osgi.boot
 argeo.osgi.start.2.node=org.eclipse.equinox.http.servlet,org.eclipse.equinox.http.jetty,org.eclipse.equinox.cm,org.eclipse.rap.rwt.osgi
index ca8f8adbb518b7510529eef7de54d1324155e45f..b87293dc32825e091c70f3158731ef3c1bcbaf7d 100644 (file)
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                        <execution>
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                </executions>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-argeo</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-tp</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
index 21c8c429711054af9c7d666ccdb084c8046b9ea9..3a7566afd95a24db01b20edad029152a1ec01c56 100644 (file)
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                        <execution>
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                </executions>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-argeo</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-tp</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
index 43b34a84a9190208db11a46f444a8a1cb2b57350..e32aca29a0f156e31afb433746f65817faa251ec 100644 (file)
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                        <execution>
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                </executions>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-argeo</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-tp</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
index 19adea00d15b336dbac64acd286d10381c9bebd9..cc8b791eae82fd99539dcdf6ac2b39e975c2fa48 100644 (file)
@@ -99,6 +99,7 @@
                                                                        <excludeTransitive>true</excludeTransitive>
                                                                        <includeTypes>jar</includeTypes>
                                                                        <includeScope>runtime</includeScope>
+                                                                       <useRepositoryLayout>true</useRepositoryLayout>
                                                                </configuration>
                                                        </execution>
                                                </executions>
                                                                                                <source>
                                                                                                        <location>${project.build.directory}/lib-tp</location>
                                                                                                        <includes>
-                                                                                                               <include>*.jar</include>
+                                                                                                               <include>**/*.jar</include>
                                                                                                        </includes>
                                                                                                </source>
                                                                                        </sources>
index 8dd4d812dca47071d36f6bb3cb43fe32f1078f15..f481473a2d46e47b83be5e1230bd94a9589c83bf 100644 (file)
@@ -19,15 +19,24 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URI;
 import java.net.URL;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.SortedMap;
 import java.util.StringTokenizer;
+import java.util.TreeMap;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
 import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
 
 /**
  * A distribution bundle is a bundle within a maven-like distribution
@@ -60,16 +69,107 @@ public class DistributionBundle {
 
        public DistributionBundle(String baseUrl, String relativeUrl) {
                if (baseUrl == null || !baseUrl.endsWith("/"))
-                       throw new OsgiBootException("Base url " + baseUrl
-                                       + " badly formatted");
+                       throw new OsgiBootException("Base url " + baseUrl + " badly formatted");
                if (relativeUrl.startsWith("http") || relativeUrl.startsWith("file:"))
-                       throw new OsgiBootException("Relative URL " + relativeUrl
-                                       + " badly formatted");
-               this.url = baseUrl + relativeUrl;
+                       throw new OsgiBootException("Relative URL " + relativeUrl + " badly formatted");
+               this.url = constructUrl(baseUrl, relativeUrl);
                this.baseUrl = baseUrl;
                this.relativeUrl = relativeUrl;
        }
 
+       protected String constructUrl(String baseUrl, String relativeUrl) {
+               try {
+                       if (relativeUrl.indexOf('*') >= 0) {
+                               if (!baseUrl.startsWith("file:"))
+                                       throw new IllegalArgumentException(
+                                                       "Wildcard support only for file:, badly formatted " + baseUrl + " and " + relativeUrl);
+                               Path basePath = Paths.get(new URI(baseUrl));
+                               // Path basePath = Paths.get(new URI(baseUrl));
+                               // int li = relativeUrl.lastIndexOf('/');
+                               // String relativeDir = relativeUrl.substring(0, li);
+                               // String relativeFile = relativeUrl.substring(li,
+                               // relativeUrl.length());
+                               String pattern = "glob:" + basePath + '/' + relativeUrl;
+                               PathMatcher pm = basePath.getFileSystem().getPathMatcher(pattern);
+                               SortedMap<Version, Path> res = new TreeMap<>();
+                               checkDir(basePath, pm, res);
+                               if (res.size() == 0)
+                                       throw new OsgiBootException("No file matching " + relativeUrl + " found in " + baseUrl);
+                               return res.get(res.firstKey()).toUri().toString();
+                               // try (DirectoryStream<Path> ds =
+                               // Files.newDirectoryStream(basePath)) {
+                               // Path res = null;
+                               // for (Path path : ds) {
+                               // if (pm.matches(path)) {
+                               // if (res == null)
+                               // res = path;
+                               // else
+                               // throw new OsgiBootException(
+                               // "More than one file matching " + relativeUrl + " found in " +
+                               // baseUrl);
+                               // }
+                               // }
+                               // if (res == null)
+                               // throw new OsgiBootException("No file matching " + relativeUrl
+                               // + " found in " + baseUrl);
+                               // return res.toUri().toURL().toString();
+                               // // Iterator<Path> it = ds.iterator();
+                               // // if (!it.hasNext())
+                               // // throw new OsgiBootException("No file matching " +
+                               // // relativeUrl + " found in " + baseUrl);
+                               // // Path distributionBundlePath = it.next();
+                               // // if (it.hasNext())// TODO implement version ordered
+                               // // throw new OsgiBootException(
+                               // // "More than one file matching " + relativeUrl + " found in
+                               // // " + baseUrl);
+                               // // return distributionBundlePath.toUri().toURL().toString();
+                               // }
+                       } else {
+                               return baseUrl + relativeUrl;
+                       }
+               } catch (Exception e) {
+                       throw new OsgiBootException("Cannot build URL from " + baseUrl + " and " + relativeUrl, e);
+               }
+       }
+
+       private void checkDir(Path dir, PathMatcher pm, SortedMap<Version, Path> res) throws IOException {
+               try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir)) {
+                       for (Path path : ds) {
+                               if (Files.isDirectory(path))
+                                       checkDir(path, pm, res);
+                               else if (pm.matches(path)) {
+                                       String fileName = path.getFileName().toString();
+                                       fileName = fileName.substring(0, fileName.lastIndexOf('.'));
+                                       if (fileName.endsWith("-SNAPSHOT"))
+                                               fileName = fileName.substring(0, fileName.lastIndexOf('-')) + ".SNAPSHOT";
+                                       fileName = fileName.substring(fileName.lastIndexOf('-') + 1);
+                                       Version version = new Version(fileName);
+                                       res.put(version, path);
+                               }
+                       }
+               }
+       }
+
+       // public static void main(String[] args) {
+       // try {
+       // String baseUrl = "file:///home/mbaudier/.m2/repository/";
+       // String relativeUrl =
+       // "org/argeo/commons/org.argeo.dep.cms.node/2.1.*-SNAPSHOT/org.argeo.dep.cms.node-2.1.*-SNAPSHOT.jar";
+       // Path basePath = Paths.get(new URI(baseUrl));
+       // PathMatcher pm = basePath.getFileSystem().getPathMatcher("glob:" +
+       // relativeUrl);
+       //
+       // try (DirectoryStream<Path> ds = Files.newDirectoryStream(basePath, "**"))
+       // {
+       // for (Path path : ds) {
+       // System.out.println(path);
+       // }
+       // }
+       // } catch (Exception e) {
+       // e.printStackTrace();
+       // }
+       // }
+
        public void processUrl() {
                JarInputStream jarIn = null;
                try {
@@ -78,10 +178,8 @@ public class DistributionBundle {
 
                        // meta data
                        manifest = jarIn.getManifest();
-                       symbolicName = manifest.getMainAttributes().getValue(
-                                       Constants.BUNDLE_SYMBOLICNAME);
-                       version = manifest.getMainAttributes().getValue(
-                                       Constants.BUNDLE_VERSION);
+                       symbolicName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+                       version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
 
                        JarEntry indexEntry;
                        while ((indexEntry = jarIn.getNextJarEntry()) != null) {
@@ -94,8 +192,7 @@ public class DistributionBundle {
 
                        // list artifacts
                        if (indexEntry == null)
-                               throw new OsgiBootException("No index " + INDEX_FILE_NAME
-                                               + " in " + url);
+                               throw new OsgiBootException("No index " + INDEX_FILE_NAME + " in " + url);
                        artifacts = listArtifacts(jarIn);
                        jarIn.closeEntry();
 
@@ -103,12 +200,10 @@ public class DistributionBundle {
                        // won't work if distribution artifact is not listed
                        for (int i = 0; i < artifacts.size(); i++) {
                                OsgiArtifact osgiArtifact = (OsgiArtifact) artifacts.get(i);
-                               if (osgiArtifact.getSymbolicName().equals(symbolicName)
-                                               && osgiArtifact.getVersion().equals(version)) {
+                               if (osgiArtifact.getSymbolicName().equals(symbolicName) && osgiArtifact.getVersion().equals(version)) {
                                        String relativeUrl = osgiArtifact.getRelativeUrl();
                                        if (url.endsWith(relativeUrl)) {
-                                               baseUrl = url.substring(0, url.length()
-                                                               - osgiArtifact.getRelativeUrl().length());
+                                               baseUrl = url.substring(0, url.length() - osgiArtifact.getRelativeUrl().length());
                                                break;
                                        }
                                }
@@ -136,8 +231,7 @@ public class DistributionBundle {
                                String moduleName = st.nextToken();
                                String moduleVersion = st.nextToken();
                                String relativeUrl = st.nextToken();
-                               osgiArtifacts.add(new OsgiArtifact(moduleName, moduleVersion,
-                                               relativeUrl));
+                               osgiArtifacts.add(new OsgiArtifact(moduleName, moduleVersion, relativeUrl));
                        }
                } catch (Exception e) {
                        throw new OsgiBootException("Cannot list artifacts", e);
@@ -146,10 +240,8 @@ public class DistributionBundle {
        }
 
        /** Convenience method */
-       public static DistributionBundle processUrl(String baseUrl,
-                       String realtiveUrl) {
-               DistributionBundle distributionBundle = new DistributionBundle(baseUrl,
-                               realtiveUrl);
+       public static DistributionBundle processUrl(String baseUrl, String realtiveUrl) {
+               DistributionBundle distributionBundle = new DistributionBundle(baseUrl, realtiveUrl);
                distributionBundle.processUrl();
                return distributionBundle;
        }
@@ -192,8 +284,7 @@ public class DistributionBundle {
                private final String version;
                private final String relativeUrl;
 
-               public OsgiArtifact(String symbolicName, String version,
-                               String relativeUrl) {
+               public OsgiArtifact(String symbolicName, String version, String relativeUrl) {
                        super();
                        this.symbolicName = symbolicName;
                        this.version = version;
index 9a75f17664a8a02f1a3e304dc59faada1040d84b..49c5e81b14355e13a06fcc3b183d1e13e15f3590 100644 (file)
@@ -26,8 +26,8 @@ public class OsgiBootException extends RuntimeException {
                super(message);
        }
 
-       public OsgiBootException(String message, Throwable cause) {
-               super(message, cause);
+       public OsgiBootException(String message, Throwable e) {
+               super(message, e);
        }
 
 }
diff --git a/pom.xml b/pom.xml
index eb328aa265d1f4bc9ee8e4cb289bcfc3af9fa214..0730f6de871b2cd246f5839be66adc99f3b3293e 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -513,6 +513,30 @@ limitations under the License.
                                                        </execution>
                                                </executions>
                                        </plugin>
+<!--                                   <plugin> -->
+<!--                                           <groupId>org.apache.maven.plugins</groupId> -->
+<!--                                           <artifactId>maven-dependency-plugin</artifactId> -->
+<!--                                           <executions> -->
+<!--                                                   <execution> -->
+<!--                                                           <id>copy</id> -->
+<!--                                                           <phase>package</phase> -->
+<!--                                                           <goals> -->
+<!--                                                                   <goal>copy</goal> -->
+<!--                                                           </goals> -->
+<!--                                                           <configuration> -->
+<!--                                                                   <artifactItems> -->
+<!--                                                                           <artifactItem> -->
+<!--                                                                                   <groupId>${project.groupId}</groupId> -->
+<!--                                                                                   <artifactId>${project.artifactId}</artifactId> -->
+<!--                                                                                   <version>${project.version}</version> -->
+<!--                                                                                   <outputDirectory>${project.build.directory}/lib-argeo</outputDirectory> -->
+<!--                                                                           </artifactItem> -->
+<!--                                                                   </artifactItems> -->
+<!--                                                                   other configurations here -->
+<!--                                                           </configuration> -->
+<!--                                                   </execution> -->
+<!--                                           </executions> -->
+<!--                                   </plugin> -->
                                </plugins>
                        </build>
                </profile>