--- /dev/null
+package org.argeo.slc;
+
+/** Canonical implementation of {@link CategorizedNameVersion} */
+public class DefaultCategorizedNameVersion extends DefaultNameVersion implements CategorizedNameVersion {
+ private String category;
+
+ public DefaultCategorizedNameVersion() {
+ }
+
+ public DefaultCategorizedNameVersion(String category, String name, String version) {
+ super(name, version);
+ this.category = category;
+ }
+
+ public DefaultCategorizedNameVersion(String category, NameVersion nameVersion) {
+ super(nameVersion);
+ this.category = category;
+ }
+
+ @Override
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ @Override
+ public String toString() {
+ return category + ":" + super.toString();
+ }
+
+}
@Override
public int hashCode() {
- return name.hashCode() + version.hashCode();
+ return name.hashCode();
}
@Override
import org.apache.commons.logging.LogFactory;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.CategorizedNameVersion;
-import org.argeo.slc.DefaultNameVersion;
+import org.argeo.slc.DefaultCategorizedNameVersion;
import org.argeo.slc.NameVersion;
import org.argeo.slc.SlcException;
import org.argeo.slc.SlcNames;
st.nextToken(); // moduleVersion
String relativeUrl = st.nextToken();
Artifact currModule = AetherUtils.convertPathToArtifact(relativeUrl, null);
- modules.add(new MyCategorizedNameVersion(currModule.getGroupId(), currModule.getArtifactId(),
+ modules.add(new DefaultCategorizedNameVersion(currModule.getGroupId(), currModule.getArtifactId(),
currModule.getVersion()));
}
return new MyModularDistribution(distribution, modules);
}
}
- /** The created modular distribution */
- private static class MyCategorizedNameVersion extends DefaultNameVersion implements CategorizedNameVersion {
- private final String category;
-
- public MyCategorizedNameVersion(String category, String name, String version) {
- super(name, version);
- this.category = category;
- }
-
- public String getCategory() {
- return category;
- }
- }
-
/**
* A consistent and versioned OSGi distribution, which can be built and tested.
*/
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);
+/**
+ * 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 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());
- }
+ if (log.isDebugEnabled())
+ log.debug(describe());
+ }
- StringBuffer buf = new StringBuffer(
- "## OSGi FACTORY MANAGED MODULES : \n");
- for (String str : sort) {
- buf.append(str).append('\n');
- }
+ public void destroy() {
- 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 String describe() {
+ SortedSet<String> sort = new TreeSet<String>();
+ Iterator<? extends NameVersion> nvIt = nameVersions();
+ while (nvIt.hasNext()) {
+ NameVersion nv = nvIt.next();
+ String str = nv.toString();
+ if (nv instanceof MavenWrapper)
+ str = str + "\t(Maven)";
+ else if (nv instanceof UriWrapper)
+ str = str + "\t(URI)";
+ else if (nv instanceof OsgiCategorizedNV)
+ str = str + "\t(OSGi from archive)";
+ else if (nv instanceof BndWrapper)
+ str = str + "\t(Plain BND from archive)";
+ else
+ str = str + "\t(UNKNOWN??)";
+ sort.add(str);
+ }
+ StringBuffer buf = new StringBuffer("## DISTRIBUTION " + toString() + " ##\n");
+ for (String str : sort) {
+ buf.append(str).append('\n');
+ }
+ return buf.toString();
}
public Iterator<NameVersion> nameVersions() {
for (Object module : modules) {
// extract runnable from execution flow
if (module instanceof ExecutionFlow) {
- for (Iterator<Runnable> it = ((ExecutionFlow) module)
- .runnables(); it.hasNext();) {
+ for (Iterator<Runnable> it = ((ExecutionFlow) module).runnables(); it.hasNext();) {
processModule(nameVersions, it.next());
}
- }
- // module = ((ExecutionFlow) module).getRunnable();
- else {
+ } else {
processModule(nameVersions, module);
}
- // 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();
}
addNameVersions(nameVersions, (ModuleSet) module);
else if (module instanceof NameVersion) {
NameVersion nv = (NameVersion) module;
- if (!nameVersions.contains(nv))
- nameVersions.add(nv);
+ addNameVersion(nameVersions, nv);
} else
log.warn("Ignored " + module);
}
- private void addNameVersions(List<NameVersion> nameVersions,
- ModuleSet moduleSet) {
+ 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);
+ addNameVersion(nameVersions, nv);
+ }
+ }
+
+ protected void addNameVersion(List<NameVersion> nameVersions, NameVersion nv) {
+ if (!nameVersions.contains(nv)) {
+ nameVersions.add(nv);
}
}
// Modular distribution interface methods. Not yet used.
- 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 Distribution getModuleDistribution(String moduleName, String moduleVersion) {
+ throw new UnsupportedOperationException();
}
public Object getModulesDescriptor(String descriptorType) {
- // TODO Auto-generated method stub
- return null;
+ throw new UnsupportedOperationException();
}
/* DEPENDENCY INJECTION */
import aQute.bnd.osgi.Jar;
/** Utilities around the BND library, which manipulates OSGi metadata. */
-public class BndWrapper implements Constants, CategorizedNameVersion,
- Distribution, BeanNameAware {
+public class BndWrapper implements Constants, CategorizedNameVersion, Distribution, BeanNameAware {
private final static Log log = LogFactory.getLog(BndWrapper.class);
private String groupId;
Version versionToUse;
if (sourceManifest != null) {
// Symbolic name
- String sourceSymbolicName = sourceManifest.getMainAttributes()
- .getValue(BUNDLE_SYMBOLICNAME);
- if (sourceSymbolicName != null
- && !sourceSymbolicName.equals(name))
- log.info("The new symbolic name ("
- + name
- + ") is not consistant with the wrapped bundle symbolic name ("
- + sourceSymbolicName + ")");
+ String sourceSymbolicName = sourceManifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
+ if (sourceSymbolicName != null && !sourceSymbolicName.equals(name))
+ log.info("The new symbolic name (" + name
+ + ") is not consistant with the wrapped bundle symbolic name (" + sourceSymbolicName + ")");
// Version
- String sourceVersion = sourceManifest.getMainAttributes()
- .getValue(BUNDLE_VERSION);
+ String sourceVersion = sourceManifest.getMainAttributes().getValue(BUNDLE_VERSION);
if (getVersion() == null && sourceVersion == null) {
throw new SlcException("A bundle version must be defined.");
} else if (getVersion() == null && sourceVersion != null) {
} else {// both set
versionToUse = new Version(getVersion());
Version sv = new Version(sourceVersion);
- if (versionToUse.getMajor() != sv.getMajor()
- || versionToUse.getMinor() != sv.getMinor()
+ if (versionToUse.getMajor() != sv.getMajor() || versionToUse.getMinor() != sv.getMinor()
|| versionToUse.getMicro() != sv.getMicro()) {
- log.warn("The new version ("
- + versionToUse
- + ") is not consistant with the wrapped bundle version ("
- + sv + ")");
+ log.warn("The new version (" + versionToUse
+ + ") is not consistant with the wrapped bundle version (" + sv + ")");
}
}
} else {
if (license != null) {
StringBuilder sb = new StringBuilder(license.getUri());
if (license.getName() != null)
- sb.append(';').append("description=")
- .append(license.getName());
+ sb.append(';').append("description=").append(license.getName());
if (license.getLink() != null)
- sb.append(';').append("link=")
- .append(license.getLink());
+ sb.append(';').append("link=").append(license.getLink());
properties.setProperty(BUNDLE_LICENSE, sb.toString());
// TODO add LICENSE.TXT
} else {
public void setVersion(String version) {
if (this.version != null)
- throw new SlcException("Version already set on " + name + " ("
- + this.version + ")");
+ throw new SlcException("Version already set on " + name + " (" + this.version + ")");
this.version = version;
}
this.name = name;
} else {
if (!name.contains("#"))
- log.warn("Using explicitely set name " + this.name
- + " and not bean name " + name);
+ log.warn("Using explicitely set name " + this.name + " and not bean name " + name);
}
}
}
public String getDistributionId() {
- return getArtifact().toString();
+ return getCategory() + ":" + getName() + ":" + getVersion();
}
public Artifact getArtifact() {
@Override
public String toString() {
- return getArtifact().toString();
+ return getDistributionId();
}
@Override
public int hashCode() {
- return getArtifact().hashCode();
+ if (name != null)
+ return name.hashCode();
+ return super.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof CategorizedNameVersion) {
CategorizedNameVersion cnv = (CategorizedNameVersion) obj;
- return getCategory().equals(cnv.getCategory())
- && getName().equals(cnv.getName())
+ return getCategory().equals(cnv.getCategory()) && getName().equals(cnv.getName())
&& getVersion().equals(cnv.getVersion());
} else
return false;
package org.argeo.slc.repo.osgi;
-import org.argeo.slc.CategorizedNameVersion;
-import org.argeo.slc.DefaultNameVersion;
+import org.argeo.slc.DefaultCategorizedNameVersion;
-class OsgiCategorizedNV extends DefaultNameVersion implements
- CategorizedNameVersion, Runnable {
- private String category;
+/** */
+class OsgiCategorizedNV extends DefaultCategorizedNameVersion implements Runnable {
/** Build runnable */
private Runnable build;
- public OsgiCategorizedNV(String category, String name, String version,
- Runnable build) {
- super(name, version);
- this.category = category;
+ public OsgiCategorizedNV(String category, String name, String version, Runnable build) {
+ super(category, name, version);
this.build = build;
}
- public String getCategory() {
- return category;
- }
-
@Override
public void run() {
if (build != null)