1 package org
.argeo
.slc
.repo
.osgi
;
3 import java
.util
.Iterator
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
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
;
21 * Executes the processes required so that all managed bundles are available.
23 public class ProcessDistribution
implements Runnable
{
24 private final static CmsLog log
= CmsLog
.getLog(ProcessDistribution
.class);
26 private ArgeoOsgiDistribution osgiDistribution
;
27 private OsgiFactory osgiFactory
;
30 Session javaSession
= null;
32 javaSession
= osgiFactory
.openJavaSession();
33 for (Iterator
<?
extends NameVersion
> it
= osgiDistribution
.nameVersions(); it
.hasNext();)
34 processNameVersion(javaSession
, it
.next());
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",
41 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
42 if (!javaSession
.itemExists(path
))
43 log
.warn("No source available for " + nv
);
46 // explicitly create the corresponding modular distribution as we
47 // have here all necessary info.
48 ModularDistributionFactory mdf
= new ModularDistributionFactory(osgiFactory
, osgiDistribution
);
51 } catch (RepositoryException e
) {
52 throw new SlcException("Cannot process distribution " + osgiDistribution
, e
);
54 JcrUtils
.logoutQuietly(javaSession
);
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();
74 log
.warn("Skip unsupported : " + nv
);
77 if (log
.isTraceEnabled())
78 log
.trace("Already available : " + nv
);
82 /* DEPENDENCY INJECTION */
83 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
84 this.osgiDistribution
= osgiDistribution
;
87 public void setOsgiFactory(OsgiFactory osgiFactory
) {
88 this.osgiFactory
= osgiFactory
;