import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.CategorizedNameVersion;
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;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
/** A consistent and versioned OSGi distribution, which can be built and tested. */
public class ArgeoOsgiDistribution extends ArtifactDistribution implements
private String version;
private Properties bndProperties = new Properties();
+ private Boolean doNotModify = false;
+
public void wrapJar(InputStream in, OutputStream out) {
Builder b = new Builder();
try {
versionToUse = new Version(version);
}
- Properties properties = new Properties();
- properties.putAll(bndProperties);
- properties.setProperty(BUNDLE_SYMBOLICNAME, name);
- properties.setProperty(BUNDLE_VERSION, versionToUse.toString());
+ if (doNotModify) {
+ jar.write(out);
+ } else {
+
+ Properties properties = new Properties();
+ properties.putAll(bndProperties);
+ properties.setProperty(BUNDLE_SYMBOLICNAME, name);
+ properties.setProperty(BUNDLE_VERSION, versionToUse.toString());
- // b.addIncluded(jarFile);
- b.addClasspath(jar);
+ // b.addIncluded(jarFile);
+ b.addClasspath(jar);
- log.debug(properties);
- b.setProperties(properties);
+ if (log.isDebugEnabled())
+ log.debug(properties);
+ b.setProperties(properties);
- Jar newJar = b.build();
- newJar.write(out);
+ Jar newJar = b.build();
+ newJar.write(out);
+ }
} catch (Exception e) {
throw new SlcException("Cannot wrap jar", e);
} finally {
return false;
}
+ public void setDoNotModify(Boolean doNotModify) {
+ this.doNotModify = doNotModify;
+ }
+
}
--- /dev/null
+package org.argeo.slc.repo.osgi;
+
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.OsgiFactory;
+import org.argeo.slc.repo.maven.MavenConventionsUtils;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
+
+public class ProcessDistribution implements Runnable {
+ private final static Log log = LogFactory.getLog(ProcessDistribution.class);
+
+ private ArgeoOsgiDistribution osgiDistribution;
+ private OsgiFactory osgiFactory;
+
+ public void run() {
+ Session javaSession = null;
+ try {
+ javaSession = osgiFactory.openJavaSession();
+
+ Iterator<NameVersion> it = osgiDistribution.nameVersions();
+ while (it.hasNext()) {
+ NameVersion t = it.next();
+ if (log.isDebugEnabled())
+ log.debug("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 {
+ log.warn("Skipped unsupported " + nv);
+ }
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot process distribution "
+ + osgiDistribution, e);
+ } finally {
+ JcrUtils.logoutQuietly(javaSession);
+ }
+ }
+
+ public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) {
+ this.osgiDistribution = osgiDistribution;
+ }
+
+ public void setOsgiFactory(OsgiFactory osgiFactory) {
+ this.osgiFactory = osgiFactory;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.repo.osgi;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.OsgiFactory;
+import org.argeo.slc.repo.RepoUtils;
+
+public class UriWrapper extends BndWrapper implements Runnable {
+ private final static Log log = LogFactory.getLog(UriWrapper.class);
+
+ private String uri;
+ private String baseUri;
+ private String versionSeparator = "-";
+ private String extension = "jar";
+
+ private OsgiFactory osgiFactory;
+
+ public void run() {
+ Session distSession = null;
+ Session javaSession = null;
+ InputStream in;
+ ByteArrayOutputStream out;
+ try {
+ distSession = osgiFactory.openDistSession();
+ javaSession = osgiFactory.openJavaSession();
+ if (uri == null) {
+ uri = baseUri + '/' + getName() + versionSeparator
+ + getVersion() + "." + extension;
+ }
+ Node sourceArtifact = osgiFactory.getDist(distSession, uri);
+
+ // TODO factorize with Maven
+ in = sourceArtifact.getNode(Node.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary().getStream();
+ out = new ByteArrayOutputStream();
+ wrapJar(in, out);
+ Node newJarNode = RepoUtils
+ .copyBytesAsArtifact(javaSession.getRootNode(),
+ getArtifact(), out.toByteArray());
+ osgiFactory.indexNode(newJarNode);
+ newJarNode.getSession().save();
+ if (log.isDebugEnabled())
+ log.debug("Wrapped " + uri + " to " + newJarNode.getPath());
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot wrap Maven " + uri, e);
+ } finally {
+ JcrUtils.logoutQuietly(distSession);
+ JcrUtils.logoutQuietly(javaSession);
+ }
+ }
+
+ public void setUri(String sourceCoords) {
+ this.uri = sourceCoords;
+ }
+
+ public void setOsgiFactory(OsgiFactory osgiFactory) {
+ this.osgiFactory = osgiFactory;
+ }
+
+ public void setBaseUri(String baseUri) {
+ this.baseUri = baseUri;
+ }
+
+ public void setVersionSeparator(String versionSeparator) {
+ this.versionSeparator = versionSeparator;
+ }
+}