import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
}
}
+ /**
+ * List sub-runnables that would be executed if run() method would be
+ * called.
+ */
+ public Iterator<Runnable> runnables() {
+ return executables.iterator();
+ }
+
+ /**
+ * If there is one and only one runnable wrapped return it, throw an
+ * exeception otherwise.
+ */
+ public Runnable getRunnable() {
+ if (executables.size() == 1)
+ return executables.get(0);
+ else
+ throw new SlcException("There are " + executables.size()
+ + " runnables in flow " + getName());
+ }
+
public void doExecuteRunnable(Runnable runnable) {
runnable.run();
}
*/\r
package org.argeo.slc.core.execution.generator;\r
\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
\r
try {\r
for (int callIndex = 0; callIndex < runnableCalls.size(); ++callIndex) {\r
RunnableCall runnableCall = runnableCalls.get(callIndex);\r
- Object bean = applicationContext.getBean(runnableCall\r
- .getBeanName(), Runnable.class);\r
+ Object bean = applicationContext.getBean(\r
+ runnableCall.getBeanName(), Runnable.class);\r
if (log.isDebugEnabled())\r
log.debug("Running flow '" + runnableCall.getBeanName()\r
+ "'");\r
}\r
}\r
\r
+ public Iterator<Runnable> runnables() {\r
+ List<Runnable> runnables = new ArrayList<Runnable>();\r
+ for (int callIndex = 0; callIndex < runnableCalls.size(); ++callIndex) {\r
+ RunnableCall runnableCall = runnableCalls.get(callIndex);\r
+ Object bean = applicationContext.getBean(\r
+ runnableCall.getBeanName(), Runnable.class);\r
+ runnables.add((Runnable) bean);\r
+ }\r
+ return runnables.iterator();\r
+ }\r
+\r
+ public Runnable getRunnable() {\r
+ if (runnableCalls.size() == 1)\r
+ return runnables().next();\r
+ else\r
+ throw new SlcException("There are " + runnableCalls.size()\r
+ + " runnables in flow " + getName());\r
+ }\r
+\r
@Override\r
public String toString() {\r
return new StringBuffer("RunnableCallFlow ").append(name).toString();\r
- } \r
- \r
+ }\r
+\r
public ExecutionSpec getExecutionSpec() {\r
return executionSpec;\r
}\r
package org.argeo.slc.repo;
-import org.argeo.slc.DefaultNameVersion;
-import org.argeo.slc.NameVersion;
+import org.argeo.slc.CategorizedNameVersion;
import org.argeo.slc.build.Distribution;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.util.artifact.DefaultArtifact;
/** A {@link Distribution} based on an Aether {@link Artifact} */
-public class ArtifactDistribution extends DefaultNameVersion implements
- Distribution {
+public class ArtifactDistribution implements Distribution,
+ CategorizedNameVersion {
private final Artifact artifact;
public ArtifactDistribution(Artifact artifact) {
this.artifact = artifact;
- setName(artifact.getArtifactId());
- setVersion(artifact.getVersion());
}
public ArtifactDistribution(String coords) {
return artifact;
}
+ public String getName() {
+ return getArtifact().getArtifactId();
+ }
+
+ public String getVersion() {
+ return getArtifact().getVersion();
+ }
+
+ public String getCategory() {
+ return getArtifact().getGroupId();
+ }
+
@Override
public int hashCode() {
return artifact.hashCode();
@Override
public boolean equals(Object obj) {
- if (obj instanceof NameVersion)
- return super.equals(obj);
- else
+ if (obj instanceof CategorizedNameVersion) {
+ CategorizedNameVersion cnv = (CategorizedNameVersion) obj;
+ return getCategory().equals(cnv.getCategory())
+ && getName().equals(cnv.getName())
+ && getVersion().equals(cnv.getVersion());
+ } else
return artifact.equals(obj);
}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.ModuleSet;
import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
import org.argeo.slc.aether.ArtifactIdComparator;
+import org.argeo.slc.build.Distribution;
import org.argeo.slc.repo.OsgiFactory;
import org.argeo.slc.repo.RepoUtils;
import org.sonatype.aether.artifact.Artifact;
* the jars, or import them directly if they are already OSGi bundles and don't
* need further modification.
*/
-public class ArchiveWrapper implements Runnable {
+public class ArchiveWrapper implements Runnable, ModuleSet, Distribution {
private final static Log log = LogFactory.getLog(ArchiveWrapper.class);
private OsgiFactory osgiFactory;
private String version;
-
+
private String uri;
- private List<String> fallbackUris = new ArrayList<String>();
-
+
// jars to wrap as OSGi bundles
private Map<String, BndWrapper> wrappers = new HashMap<String, BndWrapper>();
}
+ public String getDistributionId() {
+ return uri;
+ }
+
+ public Iterator<? extends NameVersion> nameVersions() {
+ return wrappers.values().iterator();
+ }
+
public void run() {
if (mavenGroupIndexes && (version == null))
throw new SlcException(
package org.argeo.slc.repo.osgi;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.DefaultNameVersion;
+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 Set<ArtifactDistribution> modules = new HashSet<ArtifactDistribution>();
+ private List<Object> modules = new ArrayList<Object>();
public ArgeoOsgiDistribution(String coords) {
super(coords);
public void init() {
if (log.isDebugEnabled()) {
- log.debug("## " + toString());
- for (NameVersion nv : listModulesNameVersions()) {
- log.debug(nv);
+ Iterator<? extends NameVersion> nvIt = nameVersions();
+ while (nvIt.hasNext()) {
+ log.debug(nvIt.next());
+
}
}
}
+ // 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 (ArtifactDistribution ad : modules) {
- if (ad.equals(searched))
- return ad;
- }
+ // NameVersion searched = new DefaultNameVersion(moduleName,
+ // moduleVersion);
+ // for (Distribution ad : modules) {
+ // if (ad.equals(searched))
+ // return ad;
+ // }
return null;
}
- public Set<NameVersion> listModulesNameVersions() {
- return new TreeSet<NameVersion>(modules);
+ 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) {
return null;
}
- public void setModules(Set<ArtifactDistribution> modules) {
+ public void setModules(List<Object> modules) {
this.modules = modules;
}
package org.argeo.slc.repo.osgi;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.jar.Manifest;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.NameVersion;
+import org.argeo.slc.CategorizedNameVersion;
import org.argeo.slc.SlcException;
+import org.argeo.slc.build.Distribution;
import org.osgi.framework.Version;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.util.artifact.DefaultArtifact;
import aQute.lib.osgi.Jar;
/** Utilities around the BND library, which manipulates OSGi metadata. */
-public class BndWrapper implements Constants, NameVersion, BeanNameAware {
+public class BndWrapper implements Constants, CategorizedNameVersion,
+ Distribution, BeanNameAware {
private final static Log log = LogFactory.getLog(BndWrapper.class);
private String groupId;
return groupId;
}
+ public String getCategory() {
+ return getGroupId();
+ }
+
public void setGroupId(String groupId) {
this.groupId = groupId;
}
+ public String getDistributionId() {
+ return getArtifact().toString();
+ }
+
public Artifact getArtifact() {
return new DefaultArtifact(groupId, name, "jar", version);
}
- public static void main(String[] args) {
- BndWrapper bndWrapper = new BndWrapper();
- bndWrapper.setName("org.slf4j");
+ @Override
+ public String toString() {
+ return getArtifact().toString();
+ }
- InputStream in = null;
- InputStream propertiesIn = null;
- OutputStream out = null;
- Properties properties = new Properties();
- File jarFile = new File(
- "/home/mbaudier/dev/work/130129-Distribution/slf4j/slf4j-1.7.5/slf4j-api-1.7.5.jar");
- File propertiesFile = new File(
- "/home/mbaudier/dev/git/git.argeo.org/distribution/bnd/org.slf4j/bnd.bnd");
- try {
- in = new FileInputStream(jarFile);
- // propertiesIn = new FileInputStream(propertiesFile);
- out = new FileOutputStream(new File("test.jar"));
- // properties.load(propertiesIn);
- bndWrapper.wrapJar(in, out);
- } catch (Exception e) {
- throw new SlcException("Cannot test", e);
- } finally {
- IOUtils.closeQuietly(in);
- IOUtils.closeQuietly(propertiesIn);
- IOUtils.closeQuietly(out);
- }
+ @Override
+ public int hashCode() {
+ return getArtifact().hashCode();
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof CategorizedNameVersion) {
+ CategorizedNameVersion cnv = (CategorizedNameVersion) obj;
+ return getCategory().equals(cnv.getCategory())
+ && getName().equals(cnv.getName())
+ && getVersion().equals(cnv.getVersion());
+ } else
+ return false;
+ }
+
}
--- /dev/null
+package org.argeo.slc;
+
+/**
+ * Adds a dimension to {@link NameVersion} by adding an arbitrary category (e.g.
+ * Maven groupId, yum repository ID, etc.)
+ */
+public interface CategorizedNameVersion extends NameVersion {
+ /** The category of the component. */
+ public String getCategory();
+}
--- /dev/null
+package org.argeo.slc;
+
+import java.util.Iterator;
+
+/** A set of {@link NameVersion}. */
+public interface ModuleSet {
+ Iterator<? extends NameVersion> nameVersions();
+}
*/
package org.argeo.slc.build;
-import java.util.Set;
-
+import org.argeo.slc.ModuleSet;
import org.argeo.slc.NameVersion;
/**
*
* @see NameVersion
*/
-public interface ModularDistribution extends Distribution, NameVersion {
+public interface ModularDistribution extends Distribution, NameVersion,
+ ModuleSet {
public Distribution getModuleDistribution(String moduleName,
String moduleVersion);
- public Set<NameVersion> listModulesNameVersions();
-
/** A descriptor such as P2, OBR or yum metadata. */
public Object getModulesDescriptor(String descriptorType);
}
*/
package org.argeo.slc.execution;
+import java.util.Iterator;
+
/** Abstraction of an execution that can be identified and configured. */
public interface ExecutionFlow extends Runnable {
/** Retrieve an immutable parameter */
/** The specifications of the execution flow. */
public ExecutionSpec getExecutionSpec();
+ /**
+ * List sub-runnables that would be executed if run() method would be
+ * called.
+ */
+ public Iterator<Runnable> runnables();
+
+ /**
+ * If there is one and only one runnable wrapped return it, throw an
+ * exeception otherwise.
+ */
+ public Runnable getRunnable();
+
/**
* The name of this execution flow. Can contains '/' which will be
* interpreted by UIs as a hierarchy;
*/
package org.argeo.slc.osgi;
-import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.DefaultNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.build.Distribution;
import org.argeo.slc.core.build.ResourceDistribution;
import org.springframework.core.io.Resource;
/** A deployed OSGi bundle. */
-public class OsgiBundle extends BasicNameVersion implements Module {
- private static final long serialVersionUID = 35073826504550477L;
-
+public class OsgiBundle extends DefaultNameVersion implements Module {
private ResourceDistribution distribution;
private Long internalBundleId;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.DefaultNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
import org.argeo.slc.core.execution.AbstractExecutionModulesManager;
String moduleName, String version) {
ExecutionModuleDescriptor md = new ExecutionModuleDescriptor();
OsgiBundle osgiBundle = null;
- BasicNameVersion nameVersion = new BasicNameVersion(moduleName, version);
+ DefaultNameVersion nameVersion = new DefaultNameVersion(moduleName,
+ version);
bundles: for (Iterator<OsgiBundle> iterator = executionContexts
.keySet().iterator(); iterator.hasNext();) {
OsgiBundle ob = iterator.next();
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.SortedMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.DefaultNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
import org.argeo.slc.UnsupportedException;
public Distribution getModuleDistribution(String moduleName,
String moduleVersion) {
- return distributions
- .get(new BasicNameVersion(moduleName, moduleVersion));
+ return distributions.get(new DefaultNameVersion(moduleName,
+ moduleVersion));
}
public String getDistributionId() {
return bundleContext.getBundle().getSymbolicName()
+ "-"
- + bundleContext.getBundle().getHeaders().get(
- Constants.BUNDLE_VERSION);
+ + bundleContext.getBundle().getHeaders()
+ .get(Constants.BUNDLE_VERSION);
}
public Set<NameVersion> listModulesNameVersions() {
return distributions.keySet();
}
+ public Iterator<NameVersion> nameVersions() {
+ return distributions.keySet().iterator();
+ }
+
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
}
public String getVersion() {
- return bundleContext.getBundle().getHeaders().get(
- Constants.BUNDLE_VERSION).toString();
+ return bundleContext.getBundle().getHeaders()
+ .get(Constants.BUNDLE_VERSION).toString();
}
@Override
public String toString() {
- return new BasicNameVersion(this).toString();
+ return new DefaultNameVersion(this).toString();
}
public void setEclipseUpdateSite(EclipseUpdateSite eclipseUpdateSite) {
import java.util.jar.Manifest;
import org.apache.commons.io.IOUtils;
-import org.argeo.slc.BasicNameVersion;
+import org.argeo.slc.DefaultNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.build.Distribution;
import org.argeo.slc.core.build.VersionedResourceDistribution;
String version = mf.getMainAttributes().getValue(
Constants.BUNDLE_VERSION);
- BasicNameVersion nameVersion = new BasicNameVersion(name,
+ DefaultNameVersion nameVersion = new DefaultNameVersion(name,
version);
distributions.put(nameVersion,
new VersionedResourceDistribution(name, version,