Document A2 OSGi Boot. Add classpath provisioning source.
[lgpl/argeo-commons.git] / org.argeo.osgi.boot / src / org / argeo / osgi / boot / a2 / FsA2Source.java
index b9f9193ffa512e4c4f0eaab7a7dd060118478350..a8e79d4574b1b82f327a6429841d23688a42aced 100644 (file)
@@ -11,6 +11,7 @@ import java.util.TreeSet;
 import org.argeo.osgi.boot.OsgiBootUtils;
 import org.osgi.framework.Version;
 
+/** A file system {@link ProvisioningSource} in A2 format. */
 public class FsA2Source extends ProvisioningSource {
        private final Path base;
 
@@ -43,9 +44,11 @@ public class FsA2Source extends ProvisioningSource {
                                        if (!"jar".equals(ext))
                                                continue modules;
                                        String moduleName = moduleFileName.substring(0, lastDot);
-                                       int firstDash = moduleName.indexOf('-');
-                                       String versionStr = moduleName.substring(firstDash + 1);
-                                       String componentName = moduleName.substring(0, firstDash);
+                                       if (moduleName.endsWith("-SNAPSHOT"))
+                                               moduleName = moduleName.substring(0, moduleName.length() - "-SNAPSHOT".length());
+                                       int lastDash = moduleName.lastIndexOf('-');
+                                       String versionStr = moduleName.substring(lastDash + 1);
+                                       String componentName = moduleName.substring(0, lastDash);
                                        // if(versionStr.endsWith("-SNAPSHOT")) {
                                        // versionStr = readVersionFromModule(modulePath);
                                        // }
@@ -54,9 +57,12 @@ public class FsA2Source extends ProvisioningSource {
                                                version = new Version(versionStr);
                                        } catch (Exception e) {
                                                versionStr = readVersionFromModule(modulePath);
-                                               version = new Version(versionStr);
-                                               // OsgiBootUtils.debug("Ignore " + modulePath + " (" + e.getMessage() + ")");
-                                               // continue modules;
+                                               if (versionStr != null) {
+                                                       version = new Version(versionStr);
+                                               } else {
+                                                       OsgiBootUtils.debug("Ignore " + modulePath + " (" + e.getMessage() + ")");
+                                                       continue modules;
+                                               }
                                        }
                                        A2Component component = contribution.getOrAddComponent(componentName);
                                        A2Module module = component.getOrAddModule(version, modulePath);
@@ -71,7 +77,7 @@ public class FsA2Source extends ProvisioningSource {
        public static void main(String[] args) {
                try {
                        FsA2Source context = new FsA2Source(Paths.get(
-                                       "/home/mbaudier/dev/git/apache2/argeo-commons/dist/argeo-node/target/argeo-node-2.1.74-SNAPSHOT/argeo-node/share/osgi"));
+                                       "/home/mbaudier/dev/git/apache2/argeo-commons/dist/argeo-node/target/argeo-node-2.1.77-SNAPSHOT/share/osgi"));
                        context.load();
                        context.asTree();
                } catch (Exception e) {