From 366986c3687b920a4b68eb0a0fadf3bc19dbb1bd Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 19 Sep 2016 11:04:05 +0000 Subject: [PATCH] Improve RPM packaging git-svn-id: https://svn.argeo.org/commons/trunk@9185 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- demo/argeo_node_osgiboot.properties | 2 +- dep/org.argeo.dep.cms.client/pom.xml | 6 +- dep/org.argeo.dep.cms.node/pom.xml | 6 +- dep/org.argeo.dep.cms.platform/pom.xml | 6 +- dep/org.argeo.dep.cms.sdk/pom.xml | 3 +- .../argeo/osgi/boot/DistributionBundle.java | 137 +++++++++++++++--- .../argeo/osgi/boot/OsgiBootException.java | 4 +- pom.xml | 24 +++ 8 files changed, 155 insertions(+), 33 deletions(-) diff --git a/demo/argeo_node_osgiboot.properties b/demo/argeo_node_osgiboot.properties index 81ffed11a..7f700dfcb 100644 --- a/demo/argeo_node_osgiboot.properties +++ b/demo/argeo_node_osgiboot.properties @@ -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 diff --git a/dep/org.argeo.dep.cms.client/pom.xml b/dep/org.argeo.dep.cms.client/pom.xml index ca8f8adbb..b87293dc3 100644 --- a/dep/org.argeo.dep.cms.client/pom.xml +++ b/dep/org.argeo.dep.cms.client/pom.xml @@ -230,6 +230,7 @@ true jar runtime + true @@ -245,6 +246,7 @@ true jar runtime + true @@ -272,7 +274,7 @@ ${project.build.directory}/lib-argeo - *.jar + **/*.jar @@ -317,7 +319,7 @@ ${project.build.directory}/lib-tp - *.jar + **/*.jar diff --git a/dep/org.argeo.dep.cms.node/pom.xml b/dep/org.argeo.dep.cms.node/pom.xml index 21c8c4297..3a7566afd 100644 --- a/dep/org.argeo.dep.cms.node/pom.xml +++ b/dep/org.argeo.dep.cms.node/pom.xml @@ -274,6 +274,7 @@ true jar runtime + true @@ -289,6 +290,7 @@ true jar runtime + true @@ -316,7 +318,7 @@ ${project.build.directory}/lib-argeo - *.jar + **/*.jar @@ -361,7 +363,7 @@ ${project.build.directory}/lib-tp - *.jar + **/*.jar diff --git a/dep/org.argeo.dep.cms.platform/pom.xml b/dep/org.argeo.dep.cms.platform/pom.xml index 43b34a84a..e32aca29a 100644 --- a/dep/org.argeo.dep.cms.platform/pom.xml +++ b/dep/org.argeo.dep.cms.platform/pom.xml @@ -187,6 +187,7 @@ true jar runtime + true @@ -202,6 +203,7 @@ true jar runtime + true @@ -229,7 +231,7 @@ ${project.build.directory}/lib-argeo - *.jar + **/*.jar @@ -274,7 +276,7 @@ ${project.build.directory}/lib-tp - *.jar + **/*.jar diff --git a/dep/org.argeo.dep.cms.sdk/pom.xml b/dep/org.argeo.dep.cms.sdk/pom.xml index 19adea00d..cc8b791ea 100644 --- a/dep/org.argeo.dep.cms.sdk/pom.xml +++ b/dep/org.argeo.dep.cms.sdk/pom.xml @@ -99,6 +99,7 @@ true jar runtime + true @@ -127,7 +128,7 @@ ${project.build.directory}/lib-tp - *.jar + **/*.jar diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/DistributionBundle.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/DistributionBundle.java index 8dd4d812d..f481473a2 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/DistributionBundle.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/DistributionBundle.java @@ -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 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 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 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 res) throws IOException { + try (DirectoryStream 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 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; diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootException.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootException.java index 9a75f1766..49c5e81b1 100644 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootException.java +++ b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootException.java @@ -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 eb328aa26..0730f6de8 100644 --- a/pom.xml +++ b/pom.xml @@ -513,6 +513,30 @@ limitations under the License. + + + + + + + + + + + + + + + + + + + + + + + + -- 2.30.2