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
.CategorizedNameVersion
;
12 import org
.argeo
.slc
.DefaultNameVersion
;
13 import org
.argeo
.slc
.NameVersion
;
14 import org
.argeo
.slc
.SlcException
;
15 import org
.argeo
.slc
.repo
.ArgeoOsgiDistribution
;
16 import org
.argeo
.slc
.repo
.ModularDistributionFactory
;
17 import org
.argeo
.slc
.repo
.OsgiFactory
;
18 import org
.argeo
.slc
.repo
.maven
.MavenConventionsUtils
;
19 import org
.sonatype
.aether
.artifact
.Artifact
;
20 import org
.sonatype
.aether
.util
.artifact
.DefaultArtifact
;
22 /** Executes the processes required so that all managed bundles are available. */
23 public class ProcessDistribution
implements Runnable
{
24 private final static Log log
= LogFactory
.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
34 .nameVersions(); it
.hasNext();)
35 processNameVersion(javaSession
, it
.next());
38 for (Iterator
<?
extends NameVersion
> it
= osgiDistribution
39 .nameVersions(); it
.hasNext();) {
40 CategorizedNameVersion nv
= (CategorizedNameVersion
) it
.next();
41 Artifact artifact
= new DefaultArtifact(nv
.getCategory(),
42 nv
.getName() + ".source", "jar", nv
.getVersion());
43 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
44 if (!javaSession
.itemExists(path
))
45 log
.warn("No source available for " + nv
);
48 // explicitly create the corresponding modular distribution as we
49 // have here all necessary info.
50 ModularDistributionFactory mdf
= new ModularDistributionFactory(
51 osgiFactory
, osgiDistribution
);
54 } catch (RepositoryException e
) {
55 throw new SlcException("Cannot process distribution "
56 + osgiDistribution
, e
);
58 JcrUtils
.logoutQuietly(javaSession
);
62 protected void processNameVersion(Session javaSession
,
63 NameVersion nameVersion
) throws RepositoryException
{
64 if (log
.isTraceEnabled())
65 log
.trace("Check " + nameVersion
+ "...");
66 if (!(nameVersion
instanceof CategorizedNameVersion
))
67 throw new SlcException("Unsupported type " + nameVersion
.getClass());
68 CategorizedNameVersion nv
= (CategorizedNameVersion
) nameVersion
;
69 Artifact artifact
= new DefaultArtifact(nv
.getCategory(), nv
.getName(),
70 "jar", nv
.getVersion());
71 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
72 if (!javaSession
.itemExists(path
)) {
73 if (nv
instanceof BndWrapper
) {
74 if (log
.isDebugEnabled())
75 log
.debug("Run factory for : " + nv
+ "...");
76 ((BndWrapper
) nv
).getFactory().run();
77 } else if (nv
instanceof Runnable
) {
78 ((Runnable
) nv
).run();
80 log
.warn("Skip unsupported : " + nv
);
83 if (log
.isTraceEnabled())
84 log
.trace("Already available : " + nv
);
88 /* DEPENDENCY INJECTION */
89 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
90 this.osgiDistribution
= osgiDistribution
;
93 public void setOsgiFactory(OsgiFactory osgiFactory
) {
94 this.osgiFactory
= osgiFactory
;