]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java
Update comments
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / ProcessDistribution.java
index 982492c99667da69979aee6ade87ad4d4e9e13b6..9ea467d773d9d5a507ad6e60b835d9cc6c49b7fa 100644 (file)
@@ -11,11 +11,14 @@ 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.ModularDistributionFactory;
 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);
 
@@ -26,36 +29,16 @@ public class ProcessDistribution implements Runnable {
                Session javaSession = null;
                try {
                        javaSession = osgiFactory.openJavaSession();
+                       for (Iterator<? extends NameVersion> it = osgiDistribution
+                                       .nameVersions(); it.hasNext();)
+                               processNameVersion(javaSession, it.next());
+
+                       // explicitly create the corresponding modular distribution as we
+                       // have here all necessary info.
+                       ModularDistributionFactory mdf = new ModularDistributionFactory(
+                                       osgiFactory, osgiDistribution);
+                       mdf.run();
 
-                       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);
-                               }
-                       }
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot process distribution "
                                        + osgiDistribution, e);
@@ -64,6 +47,33 @@ 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 if (nv instanceof Runnable) {
+                               ((Runnable) nv).run();
+                       } else {
+                               log.warn("Skip unsupported   : " + nv);
+                       }
+               } else {
+                       if (log.isTraceEnabled())
+                               log.trace("Already available : " + nv);
+               }
+       }
+
+       /* DEPENDENCY INJECTION */
        public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) {
                this.osgiDistribution = osgiDistribution;
        }
@@ -71,5 +81,4 @@ public class ProcessDistribution implements Runnable {
        public void setOsgiFactory(OsgiFactory osgiFactory) {
                this.osgiFactory = osgiFactory;
        }
-
-}
+}
\ No newline at end of file