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 ModularDistributionFactory mdf
= new ModularDistributionFactory(
37 osgiFactory
, osgiDistribution
);
40 // TODO why is the created distribution not automatically indexed?
41 // osgiFactory.indexNode(node);
42 // javaSession.save();
44 // Node artifact = createDistributionArtifact(javaSession,
47 } catch (RepositoryException e
) {
48 throw new SlcException("Cannot process distribution "
49 + osgiDistribution
, e
);
51 JcrUtils
.logoutQuietly(javaSession
);
55 protected void processNameVersion(Session javaSession
,
56 NameVersion nameVersion
) throws RepositoryException
{
57 if (log
.isTraceEnabled())
58 log
.trace("Check " + nameVersion
+ "...");
59 if (!(nameVersion
instanceof CategorizedNameVersion
))
60 throw new SlcException("Unsupported type " + nameVersion
.getClass());
61 CategorizedNameVersion nv
= (CategorizedNameVersion
) nameVersion
;
62 Artifact artifact
= new DefaultArtifact(nv
.getCategory(), nv
.getName(),
63 "jar", nv
.getVersion());
64 String path
= MavenConventionsUtils
.artifactPath("/", artifact
);
65 if (!javaSession
.itemExists(path
)) {
66 if (nv
instanceof BndWrapper
) {
67 if (log
.isDebugEnabled())
68 log
.debug("Run factory for : " + nv
+ "...");
69 ((BndWrapper
) nv
).getFactory().run();
70 } else if (nv
instanceof Runnable
) {
71 ((Runnable
) nv
).run();
73 log
.warn("Skip unsupported : " + nv
);
76 if (log
.isTraceEnabled())
77 log
.trace("Already available : " + nv
);
81 /* DEPENDENCY INJECTION */
82 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
83 this.osgiDistribution
= osgiDistribution
;
86 public void setOsgiFactory(OsgiFactory osgiFactory
) {
87 this.osgiFactory
= osgiFactory
;