--- /dev/null
+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 {
+
+}
+++ /dev/null
-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;
- }
-
-}
--- /dev/null
+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;
+ }
+
+}
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);
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);
}
}
+ 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;
}