1 package org
.argeo
.slc
.repo
.osgi
;
3 import java
.util
.ArrayList
;
4 import java
.util
.Iterator
;
6 import java
.util
.SortedSet
;
7 import java
.util
.TreeSet
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.ModuleSet
;
12 import org
.argeo
.slc
.NameVersion
;
13 import org
.argeo
.slc
.build
.Distribution
;
14 import org
.argeo
.slc
.execution
.ExecutionFlow
;
15 import org
.argeo
.slc
.repo
.ArgeoOsgiDistribution
;
16 import org
.argeo
.slc
.repo
.ArtifactDistribution
;
18 /** A consistent and versioned OSGi distribution, which can be built and tested. */
19 public class ArgeoOsgiDistributionImpl
extends ArtifactDistribution
implements
20 ArgeoOsgiDistribution
{
21 private final static Log log
= LogFactory
22 .getLog(ArgeoOsgiDistributionImpl
.class);
24 private List
<Object
> modules
= new ArrayList
<Object
>();
26 public ArgeoOsgiDistributionImpl(String coords
) {
31 if (log
.isDebugEnabled()) {
32 SortedSet
<String
> sort
= new TreeSet
<String
>();
33 Iterator
<?
extends NameVersion
> nvIt
= nameVersions();
34 while (nvIt
.hasNext()) {
35 NameVersion nv
= nvIt
.next();
36 sort
.add(nv
.getName() + ":" + nv
.getVersion());
39 StringBuffer buf
= new StringBuffer(
40 "## OSGi FACTORY MANAGED MODULES : \n");
41 for (String str
: sort
) {
42 buf
.append(str
).append('\n');
49 // private static void print(ModuleSet moduleSet, Integer depth) {
50 // StringBuilder prefix = new StringBuilder();
51 // for (int i = 0; i < depth; i++) {
52 // prefix.append(' ');
54 // String p = prefix.toString();
55 // prefix.setLength(0);
56 // log.debug(p + "## " + moduleSet.toString());
57 // Iterator<? extends NameVersion> nvIt = moduleSet.nameVersions();
58 // while (nvIt.hasNext()) {
59 // NameVersion nv = nvIt.next();
60 // if (nv instanceof ModuleSet)
61 // print((ModuleSet) nv, depth + 1);
68 public void destroy() {
72 public Iterator
<NameVersion
> nameVersions() {
73 List
<NameVersion
> nameVersions
= new ArrayList
<NameVersion
>();
74 for (Object module
: modules
) {
75 // extract runnable from execution flow
76 if (module
instanceof ExecutionFlow
)
77 module
= ((ExecutionFlow
) module
).getRunnable();
79 if (module
instanceof ModuleSet
)
80 addNameVersions(nameVersions
, (ModuleSet
) module
);
81 else if (module
instanceof NameVersion
) {
82 NameVersion nv
= (NameVersion
) module
;
83 if (!nameVersions
.contains(nv
))
86 log
.warn("Ignored " + module
);
88 return nameVersions
.iterator();
91 private void addNameVersions(List
<NameVersion
> nameVersions
,
92 ModuleSet moduleSet
) {
93 Iterator
<?
extends NameVersion
> it
= moduleSet
.nameVersions();
94 while (it
.hasNext()) {
95 NameVersion nv
= it
.next();
96 if (!nameVersions
.contains(nv
))
101 // Modular distribution interface methods. Not yet used.
102 public Distribution
getModuleDistribution(String moduleName
,
103 String moduleVersion
) {
104 // NameVersion searched = new DefaultNameVersion(moduleName,
106 // for (Distribution ad : modules) {
107 // if (ad.equals(searched))
113 public Object
getModulesDescriptor(String descriptorType
) {
114 // TODO Auto-generated method stub
118 /* DEPENDENCY INJECTION */
119 public void setModules(List
<Object
> modules
) {
120 this.modules
= modules
;