Introduce Argeo OSGi distribution interface
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 5 Jun 2014 10:03:35 +0000 (10:03 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 5 Jun 2014 10:03:35 +0000 (10:03 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@7039 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArgeoOsgiDistribution.java [new file with mode: 0644]
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java [deleted file]
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java [new file with mode: 0644]
runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java

diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArgeoOsgiDistribution.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ArgeoOsgiDistribution.java
new file mode 100644 (file)
index 0000000..493486e
--- /dev/null
@@ -0,0 +1,11 @@
+package org.argeo.slc.repo;
+
+import org.argeo.slc.CategorizedNameVersion;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.ModularDistribution;
+
+/** Aether compatible OSGi distribution */
+public interface ArgeoOsgiDistribution extends Distribution,
+               CategorizedNameVersion, ModularDistribution {
+
+}
diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java
deleted file mode 100644 (file)
index 709a888..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-package org.argeo.slc.repo.osgi;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.ModuleSet;
-import org.argeo.slc.NameVersion;
-import org.argeo.slc.build.Distribution;
-import org.argeo.slc.build.ModularDistribution;
-import org.argeo.slc.execution.ExecutionFlow;
-import org.argeo.slc.repo.ArtifactDistribution;
-
-/** A consistent and versioned OSGi distribution, which can be built and tested. */
-public class ArgeoOsgiDistribution extends ArtifactDistribution implements
-               ModularDistribution {
-       private final static Log log = LogFactory
-                       .getLog(ArgeoOsgiDistribution.class);
-
-       private List<Object> modules = new ArrayList<Object>();
-
-       public ArgeoOsgiDistribution(String coords) {
-               super(coords);
-       }
-
-       public void init() {
-               if (log.isDebugEnabled()) {
-                       SortedSet<String> sort = new TreeSet<String>();
-                       Iterator<? extends NameVersion> nvIt = nameVersions();
-                       while (nvIt.hasNext()) {
-                               NameVersion nv = nvIt.next();
-                               sort.add(nv.getName() + ":" + nv.getVersion());
-                       }
-
-                       StringBuffer buf = new StringBuffer(
-                                       "## OSGi FACTORY MANAGED MODULES : \n");
-                       for (String str : sort) {
-                               buf.append(str).append('\n');
-                       }
-
-                       log.debug(buf);
-               }
-       }
-
-       // private static void print(ModuleSet moduleSet, Integer depth) {
-       // StringBuilder prefix = new StringBuilder();
-       // for (int i = 0; i < depth; i++) {
-       // prefix.append(' ');
-       // }
-       // String p = prefix.toString();
-       // prefix.setLength(0);
-       // log.debug(p + "## " + moduleSet.toString());
-       // Iterator<? extends NameVersion> nvIt = moduleSet.nameVersions();
-       // while (nvIt.hasNext()) {
-       // NameVersion nv = nvIt.next();
-       // if (nv instanceof ModuleSet)
-       // print((ModuleSet) nv, depth + 1);
-       // else
-       // log.debug(p + nv);
-       //
-       // }
-       // }
-
-       public void destroy() {
-
-       }
-
-       public Distribution getModuleDistribution(String moduleName,
-                       String moduleVersion) {
-               // NameVersion searched = new DefaultNameVersion(moduleName,
-               // moduleVersion);
-               // for (Distribution ad : modules) {
-               // if (ad.equals(searched))
-               // return ad;
-               // }
-               return null;
-       }
-
-       public Iterator<NameVersion> nameVersions() {
-               List<NameVersion> nameVersions = new ArrayList<NameVersion>();
-               for (Object module : modules) {
-                       // extract runnable from execution flow
-                       if (module instanceof ExecutionFlow)
-                               module = ((ExecutionFlow) module).getRunnable();
-
-                       if (module instanceof ModuleSet)
-                               addNameVersions(nameVersions, (ModuleSet) module);
-                       else if (module instanceof NameVersion) {
-                               NameVersion nv = (NameVersion) module;
-                               if (!nameVersions.contains(nv))
-                                       nameVersions.add(nv);
-                       } else
-                               log.warn("Ignored " + module);
-               }
-               return nameVersions.iterator();
-       }
-
-       private void addNameVersions(List<NameVersion> nameVersions,
-                       ModuleSet moduleSet) {
-               Iterator<? extends NameVersion> it = moduleSet.nameVersions();
-               while (it.hasNext()) {
-                       NameVersion nv = it.next();
-                       if (!nameVersions.contains(nv))
-                               nameVersions.add(nv);
-               }
-       }
-
-       public Object getModulesDescriptor(String descriptorType) {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       public void setModules(List<Object> modules) {
-               this.modules = modules;
-       }
-
-}
diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistributionImpl.java
new file mode 100644 (file)
index 0000000..4591598
--- /dev/null
@@ -0,0 +1,121 @@
+package org.argeo.slc.repo.osgi;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.ModuleSet;
+import org.argeo.slc.NameVersion;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.repo.ArgeoOsgiDistribution;
+import org.argeo.slc.repo.ArtifactDistribution;
+
+/** A consistent and versioned OSGi distribution, which can be built and tested. */
+public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements
+               ArgeoOsgiDistribution {
+       private final static Log log = LogFactory
+                       .getLog(ArgeoOsgiDistributionImpl.class);
+
+       private List<Object> modules = new ArrayList<Object>();
+
+       public ArgeoOsgiDistributionImpl(String coords) {
+               super(coords);
+       }
+
+       public void init() {
+               if (log.isDebugEnabled()) {
+                       SortedSet<String> sort = new TreeSet<String>();
+                       Iterator<? extends NameVersion> nvIt = nameVersions();
+                       while (nvIt.hasNext()) {
+                               NameVersion nv = nvIt.next();
+                               sort.add(nv.getName() + ":" + nv.getVersion());
+                       }
+
+                       StringBuffer buf = new StringBuffer(
+                                       "## OSGi FACTORY MANAGED MODULES : \n");
+                       for (String str : sort) {
+                               buf.append(str).append('\n');
+                       }
+
+                       log.debug(buf);
+               }
+       }
+
+       // private static void print(ModuleSet moduleSet, Integer depth) {
+       // StringBuilder prefix = new StringBuilder();
+       // for (int i = 0; i < depth; i++) {
+       // prefix.append(' ');
+       // }
+       // String p = prefix.toString();
+       // prefix.setLength(0);
+       // log.debug(p + "## " + moduleSet.toString());
+       // Iterator<? extends NameVersion> nvIt = moduleSet.nameVersions();
+       // while (nvIt.hasNext()) {
+       // NameVersion nv = nvIt.next();
+       // if (nv instanceof ModuleSet)
+       // print((ModuleSet) nv, depth + 1);
+       // else
+       // log.debug(p + nv);
+       //
+       // }
+       // }
+
+       public void destroy() {
+
+       }
+
+       public Distribution getModuleDistribution(String moduleName,
+                       String moduleVersion) {
+               // NameVersion searched = new DefaultNameVersion(moduleName,
+               // moduleVersion);
+               // for (Distribution ad : modules) {
+               // if (ad.equals(searched))
+               // return ad;
+               // }
+               return null;
+       }
+
+       public Iterator<NameVersion> nameVersions() {
+               List<NameVersion> nameVersions = new ArrayList<NameVersion>();
+               for (Object module : modules) {
+                       // extract runnable from execution flow
+                       if (module instanceof ExecutionFlow)
+                               module = ((ExecutionFlow) module).getRunnable();
+
+                       if (module instanceof ModuleSet)
+                               addNameVersions(nameVersions, (ModuleSet) module);
+                       else if (module instanceof NameVersion) {
+                               NameVersion nv = (NameVersion) module;
+                               if (!nameVersions.contains(nv))
+                                       nameVersions.add(nv);
+                       } else
+                               log.warn("Ignored " + module);
+               }
+               return nameVersions.iterator();
+       }
+
+       private void addNameVersions(List<NameVersion> nameVersions,
+                       ModuleSet moduleSet) {
+               Iterator<? extends NameVersion> it = moduleSet.nameVersions();
+               while (it.hasNext()) {
+                       NameVersion nv = it.next();
+                       if (!nameVersions.contains(nv))
+                               nameVersions.add(nv);
+               }
+       }
+
+       public Object getModulesDescriptor(String descriptorType) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public void setModules(List<Object> modules) {
+               this.modules = modules;
+       }
+
+}
index 982492c99667da69979aee6ade87ad4d4e9e13b6..bca8356c92ba70b1f2578d6233bd5809bc685980 100644 (file)
@@ -11,11 +11,13 @@ import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.CategorizedNameVersion;
 import org.argeo.slc.NameVersion;
 import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.ArgeoOsgiDistribution;
 import org.argeo.slc.repo.OsgiFactory;
 import org.argeo.slc.repo.maven.MavenConventionsUtils;
 import org.sonatype.aether.artifact.Artifact;
 import org.sonatype.aether.util.artifact.DefaultArtifact;
 
+/** Executes the processes required so that all managed bundles are available. */
 public class ProcessDistribution implements Runnable {
        private final static Log log = LogFactory.getLog(ProcessDistribution.class);
 
@@ -27,35 +29,12 @@ public class ProcessDistribution implements Runnable {
                try {
                        javaSession = osgiFactory.openJavaSession();
 
-                       Iterator<NameVersion> it = osgiDistribution.nameVersions();
-                       while (it.hasNext()) {
-                               NameVersion t = it.next();
-                               if (log.isTraceEnabled())
-                                       log.trace("Check " + t + "...");
-                               if (!(t instanceof CategorizedNameVersion))
-                                       throw new SlcException("Unsupported type " + t.getClass());
-                               CategorizedNameVersion nv = (CategorizedNameVersion) t;
-                               Artifact artifact = new DefaultArtifact(nv.getCategory(),
-                                               nv.getName(), "jar", nv.getVersion());
-                               String path = MavenConventionsUtils.artifactPath("/", artifact);
-                               if (!javaSession.itemExists(path)) {
-                                       // if (nv instanceof Runnable) {
-                                       // if (log.isDebugEnabled())
-                                       // log.debug("Run " + nv + "...");
-                                       // ((Runnable) nv).run();
-                                       // } else
-                                       if (nv instanceof BndWrapper) {
-                                               if (log.isDebugEnabled())
-                                                       log.debug("Run factory for   : " + nv + "...");
-                                               ((BndWrapper) nv).getFactory().run();
-                                       } else {
-                                               log.warn("Skip unsupported   : " + nv);
-                                       }
-                               } else {
-                                       if (log.isDebugEnabled())
-                                               log.debug("Already available : " + nv);
-                               }
-                       }
+                       for (Iterator<? extends NameVersion> it = osgiDistribution
+                                       .nameVersions(); it.hasNext();)
+                               processNameVersion(javaSession, it.next());
+
+                       // TODO generate distribution indexes (pom.xml, P2, OBR)
+                       // osgiFactory.indexNode(node);
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot process distribution "
                                        + osgiDistribution, e);
@@ -64,6 +43,31 @@ public class ProcessDistribution implements Runnable {
                }
        }
 
+       protected void processNameVersion(Session javaSession,
+                       NameVersion nameVersion) throws RepositoryException {
+               if (log.isTraceEnabled())
+                       log.trace("Check " + nameVersion + "...");
+               if (!(nameVersion instanceof CategorizedNameVersion))
+                       throw new SlcException("Unsupported type " + nameVersion.getClass());
+               CategorizedNameVersion nv = (CategorizedNameVersion) nameVersion;
+               Artifact artifact = new DefaultArtifact(nv.getCategory(), nv.getName(),
+                               "jar", nv.getVersion());
+               String path = MavenConventionsUtils.artifactPath("/", artifact);
+               if (!javaSession.itemExists(path)) {
+                       if (nv instanceof BndWrapper) {
+                               if (log.isDebugEnabled())
+                                       log.debug("Run factory for   : " + nv + "...");
+                               ((BndWrapper) nv).getFactory().run();
+                       } else {
+                               log.warn("Skip unsupported   : " + nv);
+                       }
+               } else {
+                       if (log.isDebugEnabled())
+                               log.debug("Already available : " + nv);
+               }
+
+       }
+
        public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) {
                this.osgiDistribution = osgiDistribution;
        }