]> git.argeo.org Git - gpl/argeo-slc.git/blob - ProcessDistribution.java
544b1c634aa38e2fd6539be2850395ee580fcbd3
[gpl/argeo-slc.git] / ProcessDistribution.java
1 package org.argeo.slc.repo.osgi;
2
3 import java.util.Iterator;
4
5 import javax.jcr.RepositoryException;
6 import javax.jcr.Session;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.argeo.jcr.JcrUtils;
11 import org.argeo.slc.CategorizedNameVersion;
12 import org.argeo.slc.NameVersion;
13 import org.argeo.slc.SlcException;
14 import org.argeo.slc.repo.ArgeoOsgiDistribution;
15 import org.argeo.slc.repo.ModularDistributionFactory;
16 import org.argeo.slc.repo.OsgiFactory;
17 import org.argeo.slc.repo.maven.MavenConventionsUtils;
18 import org.sonatype.aether.artifact.Artifact;
19 import org.sonatype.aether.util.artifact.DefaultArtifact;
20
21 /** Executes the processes required so that all managed bundles are available. */
22 public class ProcessDistribution implements Runnable {
23 private final static Log log = LogFactory.getLog(ProcessDistribution.class);
24
25 private ArgeoOsgiDistribution osgiDistribution;
26 private OsgiFactory osgiFactory;
27
28 public void run() {
29 Session javaSession = null;
30 try {
31 javaSession = osgiFactory.openJavaSession();
32
33 for (Iterator<? extends NameVersion> it = osgiDistribution
34 .nameVersions(); it.hasNext();)
35 processNameVersion(javaSession, it.next());
36
37 ModularDistributionFactory mdf = new ModularDistributionFactory(
38 javaSession, osgiDistribution);
39 mdf.run();
40
41 // TODO why is the created distribution not automatically indexed?
42 // osgiFactory.indexNode(node);
43 // javaSession.save();
44
45 // Node artifact = createDistributionArtifact(javaSession,
46 // osgiDistribution);
47
48 } catch (RepositoryException e) {
49 throw new SlcException("Cannot process distribution "
50 + osgiDistribution, e);
51 } finally {
52 JcrUtils.logoutQuietly(javaSession);
53 }
54 }
55
56 protected void processNameVersion(Session javaSession,
57 NameVersion nameVersion) throws RepositoryException {
58 if (log.isTraceEnabled())
59 log.trace("Check " + nameVersion + "...");
60 if (!(nameVersion instanceof CategorizedNameVersion))
61 throw new SlcException("Unsupported type " + nameVersion.getClass());
62 CategorizedNameVersion nv = (CategorizedNameVersion) nameVersion;
63 Artifact artifact = new DefaultArtifact(nv.getCategory(), nv.getName(),
64 "jar", nv.getVersion());
65 String path = MavenConventionsUtils.artifactPath("/", artifact);
66 if (!javaSession.itemExists(path)) {
67 if (nv instanceof BndWrapper) {
68 if (log.isDebugEnabled())
69 log.debug("Run factory for : " + nv + "...");
70 ((BndWrapper) nv).getFactory().run();
71 } else {
72 log.warn("Skip unsupported : " + nv);
73 }
74 } else {
75 if (log.isDebugEnabled())
76 log.debug("Already available : " + nv);
77 }
78 }
79
80 /* DEPENDENCY INJECTION */
81 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) {
82 this.osgiDistribution = osgiDistribution;
83 }
84
85 public void setOsgiFactory(OsgiFactory osgiFactory) {
86 this.osgiFactory = osgiFactory;
87 }
88 }