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);
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);
}
}
+ 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;
}
public void setOsgiFactory(OsgiFactory osgiFactory) {
this.osgiFactory = osgiFactory;
}
-
-}
+}
\ No newline at end of file