From: Mathieu Baudier Date: Sun, 26 Jan 2014 12:24:20 +0000 (+0000) Subject: Improve distribution X-Git-Tag: argeo-slc-2.1.7~264 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=fa099b50351a61638bdb1e3becc45ace640c15f2;p=gpl%2Fargeo-slc.git Improve distribution git-svn-id: https://svn.argeo.org/slc/trunk@6767 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java index 5c9ffccde..f0ab4e2e4 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java @@ -6,12 +6,15 @@ import java.util.List; 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 diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java index 55ad84dfd..f1acf49e4 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/BndWrapper.java @@ -29,6 +29,8 @@ public class BndWrapper implements Constants, CategorizedNameVersion, private String version; private Properties bndProperties = new Properties(); + private Boolean doNotModify = false; + public void wrapJar(InputStream in, OutputStream out) { Builder b = new Builder(); try { @@ -72,19 +74,25 @@ public class BndWrapper implements Constants, CategorizedNameVersion, 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 { @@ -162,4 +170,8 @@ public class BndWrapper implements Constants, CategorizedNameVersion, return false; } + public void setDoNotModify(Boolean doNotModify) { + this.doNotModify = doNotModify; + } + } diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java new file mode 100644 index 000000000..26f063991 --- /dev/null +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ProcessDistribution.java @@ -0,0 +1,67 @@ +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 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; + } + +} diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/UriWrapper.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/UriWrapper.java new file mode 100644 index 000000000..45456ad31 --- /dev/null +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/UriWrapper.java @@ -0,0 +1,77 @@ +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; + } +}