]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/ProcessDistribution.java
Make Eclipse E4 optional
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / argeo / slc / repo / osgi / 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.argeo.api.cms.CmsLog;
9 import org.argeo.jcr.JcrUtils;
10 import org.argeo.slc.CategoryNameVersion;
11 import org.argeo.slc.NameVersion;
12 import org.argeo.slc.SlcException;
13 import org.argeo.slc.repo.ArgeoOsgiDistribution;
14 import org.argeo.slc.repo.ModularDistributionFactory;
15 import org.argeo.slc.repo.OsgiFactory;
16 import org.argeo.slc.repo.maven.MavenConventionsUtils;
17 import org.eclipse.aether.artifact.Artifact;
18 import org.eclipse.aether.artifact.DefaultArtifact;
19
20 /**
21 * Executes the processes required so that all managed bundles are available.
22 */
23 public class ProcessDistribution implements Runnable {
24 private final static CmsLog log = CmsLog.getLog(ProcessDistribution.class);
25
26 private ArgeoOsgiDistribution osgiDistribution;
27 private OsgiFactory osgiFactory;
28
29 public void run() {
30 Session javaSession = null;
31 try {
32 javaSession = osgiFactory.openJavaSession();
33 for (Iterator<? extends NameVersion> it = osgiDistribution.nameVersions(); it.hasNext();)
34 processNameVersion(javaSession, it.next());
35
36 // Check sources
37 for (Iterator<? extends NameVersion> it = osgiDistribution.nameVersions(); it.hasNext();) {
38 CategoryNameVersion nv = (CategoryNameVersion) it.next();
39 Artifact artifact = new DefaultArtifact(nv.getCategory(), nv.getName() + ".source", "jar",
40 nv.getVersion());
41 String path = MavenConventionsUtils.artifactPath("/", artifact);
42 if (!javaSession.itemExists(path))
43 log.warn("No source available for " + nv);
44 }
45
46 // explicitly create the corresponding modular distribution as we
47 // have here all necessary info.
48 ModularDistributionFactory mdf = new ModularDistributionFactory(osgiFactory, osgiDistribution);
49 mdf.run();
50
51 } catch (RepositoryException e) {
52 throw new SlcException("Cannot process distribution " + osgiDistribution, e);
53 } finally {
54 JcrUtils.logoutQuietly(javaSession);
55 }
56 }
57
58 protected void processNameVersion(Session javaSession, NameVersion nameVersion) throws RepositoryException {
59 if (log.isTraceEnabled())
60 log.trace("Check " + nameVersion + "...");
61 if (!(nameVersion instanceof CategoryNameVersion))
62 throw new SlcException("Unsupported type " + nameVersion.getClass());
63 CategoryNameVersion nv = (CategoryNameVersion) nameVersion;
64 Artifact artifact = new DefaultArtifact(nv.getCategory(), nv.getName(), "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 if (nv instanceof Runnable) {
72 ((Runnable) nv).run();
73 } else {
74 log.warn("Skip unsupported : " + nv);
75 }
76 } else {
77 if (log.isTraceEnabled())
78 log.trace("Already available : " + nv);
79 }
80 }
81
82 /* DEPENDENCY INJECTION */
83 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution) {
84 this.osgiDistribution = osgiDistribution;
85 }
86
87 public void setOsgiFactory(OsgiFactory osgiFactory) {
88 this.osgiFactory = osgiFactory;
89 }
90 }