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();
33 for (Iterator
<?
extends NameVersion
> it
= osgiDistribution
34 .nameVersions(); it
.hasNext();)
35 processNameVersion(javaSession
, it
.next());
37 ModularDistributionFactory mdf
= new ModularDistributionFactory(
38 javaSession
, osgiDistribution
);
41 // TODO why is the created distribution not automatically indexed?
42 // osgiFactory.indexNode(node);
43 // javaSession.save();
45 // Node artifact = createDistributionArtifact(javaSession,
48 } catch (RepositoryException e
) {
49 throw new SlcException("Cannot process distribution "
50 + osgiDistribution
, e
);
52 JcrUtils
.logoutQuietly(javaSession
);
56 protected void processNameVersion(Session javaSession
,
57 NameVersion nameVersion
) throws RepositoryException
{
58 if (log
.isTraceEnabled())
59 log
.trace("Check " + nameVersion
+ "...");
60 if (!(nameVersion
instanceof CategorizedNameVersion
))
61 throw new SlcException("Unsupported type " + nameVersion
.getClass());
62 CategorizedNameVersion nv
= (CategorizedNameVersion
) nameVersion
;
63 Artifact artifact
= new DefaultArtifact(nv
.getCategory(), nv
.getName(),
64 "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();
72 log
.warn("Skip unsupported : " + nv
);
75 if (log
.isDebugEnabled())
76 log
.debug("Already available : " + nv
);
80 /* DEPENDENCY INJECTION */
81 public void setOsgiDistribution(ArgeoOsgiDistribution osgiDistribution
) {
82 this.osgiDistribution
= osgiDistribution
;
85 public void setOsgiFactory(OsgiFactory osgiFactory
) {
86 this.osgiFactory
= osgiFactory
;