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
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.jcr
.JcrUtils
;
11 import org
.argeo
.slc
.CategoryNameVersion
;
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
.eclipse
.aether
.artifact
.Artifact
;
19 import org
.eclipse
.aether
.artifact
.DefaultArtifact
;
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);
25 private ArgeoOsgiDistribution osgiDistribution
;
26 private OsgiFactory osgiFactory
;
29 Session javaSession
= null;
31 javaSession
= osgiFactory
.openJavaSession();
32 for (Iterator
<?
extends NameVersion
> it
= osgiDistribution
33 .nameVersions(); it
.hasNext();)
34 processNameVersion(javaSession
, it
.next());
37 for (Iterator
<?
extends NameVersion
> it
= osgiDistribution
38 .nameVersions(); it
.hasNext();) {
39 CategoryNameVersion nv
= (CategoryNameVersion
) it
.next();
40 Artifact artifact
= new DefaultArtifact(nv
.getCategory(),
41 nv
.getName() + ".source", "jar", nv
.getVersion());
42 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
43 if (!javaSession
.itemExists(path
))
44 log
.warn("No source available for " + nv
);
47 // explicitly create the corresponding modular distribution as we
48 // have here all necessary info.
49 ModularDistributionFactory mdf
= new ModularDistributionFactory(
50 osgiFactory
, osgiDistribution
);
53 } catch (RepositoryException e
) {
54 throw new SlcException("Cannot process distribution "
55 + osgiDistribution
, e
);
57 JcrUtils
.logoutQuietly(javaSession
);
61 protected void processNameVersion(Session javaSession
,
62 NameVersion nameVersion
) throws RepositoryException
{
63 if (log
.isTraceEnabled())
64 log
.trace("Check " + nameVersion
+ "...");
65 if (!(nameVersion
instanceof CategoryNameVersion
))
66 throw new SlcException("Unsupported type " + nameVersion
.getClass());
67 CategoryNameVersion nv
= (CategoryNameVersion
) nameVersion
;
68 Artifact artifact
= new DefaultArtifact(nv
.getCategory(), nv
.getName(),
69 "jar", nv
.getVersion());
70 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
71 if (!javaSession
.itemExists(path
)) {
72 if (nv
instanceof BndWrapper
) {
73 if (log
.isDebugEnabled())
74 log
.debug("Run factory for : " + nv
+ "...");
75 ((BndWrapper
) nv
).getFactory().run();
76 } else if (nv
instanceof Runnable
) {
77 ((Runnable
) nv
).run();
79 log
.warn("Skip unsupported : " + nv
);
82 if (log
.isTraceEnabled())
83 log
.trace("Already available : " + nv
);
87 /* DEPENDENCY INJECTION */
88 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
89 this.osgiDistribution
= osgiDistribution
;
92 public void setOsgiFactory(OsgiFactory osgiFactory
) {
93 this.osgiFactory
= osgiFactory
;