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
.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
;
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());
36 // explicitly create the corresponding modular distribution as we
37 // have here all necessary info.
38 ModularDistributionFactory mdf
= new ModularDistributionFactory(
39 osgiFactory
, osgiDistribution
);
42 } catch (RepositoryException e
) {
43 throw new SlcException("Cannot process distribution "
44 + osgiDistribution
, e
);
46 JcrUtils
.logoutQuietly(javaSession
);
50 protected void processNameVersion(Session javaSession
,
51 NameVersion nameVersion
) throws RepositoryException
{
52 if (log
.isTraceEnabled())
53 log
.trace("Check " + nameVersion
+ "...");
54 if (!(nameVersion
instanceof CategorizedNameVersion
))
55 throw new SlcException("Unsupported type " + nameVersion
.getClass());
56 CategorizedNameVersion nv
= (CategorizedNameVersion
) nameVersion
;
57 Artifact artifact
= new DefaultArtifact(nv
.getCategory(), nv
.getName(),
58 "jar", nv
.getVersion());
59 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
60 if (!javaSession
.itemExists(path
)) {
61 if (nv
instanceof BndWrapper
) {
62 if (log
.isDebugEnabled())
63 log
.debug("Run factory for : " + nv
+ "...");
64 ((BndWrapper
) nv
).getFactory().run();
65 } else if (nv
instanceof Runnable
) {
66 ((Runnable
) nv
).run();
68 log
.warn("Skip unsupported : " + nv
);
71 if (log
.isTraceEnabled())
72 log
.trace("Already available : " + nv
);
76 /* DEPENDENCY INJECTION */
77 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
78 this.osgiDistribution
= osgiDistribution
;
81 public void setOsgiFactory(OsgiFactory osgiFactory
) {
82 this.osgiFactory
= osgiFactory
;