X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fosgi%2FProcessDistribution.java;fp=org.argeo.slc.repo%2Fsrc%2Forg%2Fargeo%2Fslc%2Frepo%2Fosgi%2FProcessDistribution.java;h=0c65814255919d620bb08031c178f1f78d6afe24;hb=825d60c5348dbe3f5be25b0bccf7bdebfe694219;hp=0000000000000000000000000000000000000000;hpb=5e991fff5cba01858dcc5747a27e637325bc5c8e;p=gpl%2Fargeo-jcr.git diff --git a/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ProcessDistribution.java b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ProcessDistribution.java new file mode 100644 index 0000000..0c65814 --- /dev/null +++ b/org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ProcessDistribution.java @@ -0,0 +1,90 @@ +package org.argeo.slc.repo.osgi; + +import java.util.Iterator; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.api.cms.CmsLog; +import org.argeo.jcr.JcrUtils; +import org.argeo.slc.CategoryNameVersion; +import org.argeo.slc.NameVersion; +import org.argeo.slc.SlcException; +import org.argeo.slc.repo.ArgeoOsgiDistribution; +import org.argeo.slc.repo.ModularDistributionFactory; +import org.argeo.slc.repo.OsgiFactory; +import org.argeo.slc.repo.maven.MavenConventionsUtils; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; + +/** + * Executes the processes required so that all managed bundles are available. + */ +public class ProcessDistribution implements Runnable { + private final static CmsLog log = CmsLog.getLog(ProcessDistribution.class); + + private ArgeoOsgiDistribution osgiDistribution; + private OsgiFactory osgiFactory; + + public void run() { + Session javaSession = null; + try { + javaSession = osgiFactory.openJavaSession(); + for (Iterator it = osgiDistribution.nameVersions(); it.hasNext();) + processNameVersion(javaSession, it.next()); + + // Check sources + for (Iterator it = osgiDistribution.nameVersions(); it.hasNext();) { + CategoryNameVersion nv = (CategoryNameVersion) it.next(); + Artifact artifact = new DefaultArtifact(nv.getCategory(), nv.getName() + ".source", "jar", + nv.getVersion()); + String path = MavenConventionsUtils.artifactPath("/", artifact); + if (!javaSession.itemExists(path)) + log.warn("No source available for " + nv); + } + + // explicitly create the corresponding modular distribution as we + // have here all necessary info. + ModularDistributionFactory mdf = new ModularDistributionFactory(osgiFactory, osgiDistribution); + mdf.run(); + + } catch (RepositoryException e) { + throw new SlcException("Cannot process distribution " + osgiDistribution, e); + } finally { + JcrUtils.logoutQuietly(javaSession); + } + } + + protected void processNameVersion(Session javaSession, NameVersion nameVersion) throws RepositoryException { + if (log.isTraceEnabled()) + log.trace("Check " + nameVersion + "..."); + if (!(nameVersion instanceof CategoryNameVersion)) + throw new SlcException("Unsupported type " + nameVersion.getClass()); + CategoryNameVersion nv = (CategoryNameVersion) 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 if (nv instanceof Runnable) { + ((Runnable) nv).run(); + } else { + log.warn("Skip unsupported : " + nv); + } + } else { + if (log.isTraceEnabled()) + log.trace("Already available : " + nv); + } + } + + /* DEPENDENCY INJECTION */ + public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) { + this.osgiDistribution = osgiDistribution; + } + + public void setOsgiFactory(OsgiFactory osgiFactory) { + this.osgiFactory = osgiFactory; + } +} \ No newline at end of file