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 javax
.swing
.text
.StyledEditorKit
.ItalicAction
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.slc
.ModuleSet
;
14 import org
.argeo
.slc
.NameVersion
;
15 import org
.argeo
.slc
.build
.Distribution
;
16 import org
.argeo
.slc
.execution
.ExecutionFlow
;
17 import org
.argeo
.slc
.repo
.ArgeoOsgiDistribution
;
18 import org
.argeo
.slc
.repo
.ArtifactDistribution
;
20 /** A consistent and versioned OSGi distribution, which can be built and tested. */
21 public class ArgeoOsgiDistributionImpl
extends ArtifactDistribution
implements
22 ArgeoOsgiDistribution
{
23 private final static Log log
= LogFactory
24 .getLog(ArgeoOsgiDistributionImpl
.class);
26 private List
<Object
> modules
= new ArrayList
<Object
>();
28 public ArgeoOsgiDistributionImpl(String coords
) {
33 if (log
.isDebugEnabled()) {
34 SortedSet
<String
> sort
= new TreeSet
<String
>();
35 Iterator
<?
extends NameVersion
> nvIt
= nameVersions();
36 while (nvIt
.hasNext()) {
37 NameVersion nv
= nvIt
.next();
38 sort
.add(nv
.getName() + ":" + nv
.getVersion());
41 StringBuffer buf
= new StringBuffer(
42 "## OSGi FACTORY MANAGED MODULES : \n");
43 for (String str
: sort
) {
44 buf
.append(str
).append('\n');
51 // private static void print(ModuleSet moduleSet, Integer depth) {
52 // StringBuilder prefix = new StringBuilder();
53 // for (int i = 0; i < depth; i++) {
54 // prefix.append(' ');
56 // String p = prefix.toString();
57 // prefix.setLength(0);
58 // log.debug(p + "## " + moduleSet.toString());
59 // Iterator<? extends NameVersion> nvIt = moduleSet.nameVersions();
60 // while (nvIt.hasNext()) {
61 // NameVersion nv = nvIt.next();
62 // if (nv instanceof ModuleSet)
63 // print((ModuleSet) nv, depth + 1);
70 public void destroy() {
74 public Iterator
<NameVersion
> nameVersions() {
75 List
<NameVersion
> nameVersions
= new ArrayList
<NameVersion
>();
76 for (Object module
: modules
) {
77 // extract runnable from execution flow
78 if (module
instanceof ExecutionFlow
) {
79 for (Iterator
<Runnable
> it
= ((ExecutionFlow
) module
)
80 .runnables(); it
.hasNext();) {
81 processModule(nameVersions
, it
.next());
84 // module = ((ExecutionFlow) module).getRunnable();
86 processModule(nameVersions
, module
);
88 // if (module instanceof ModuleSet)
89 // addNameVersions(nameVersions, (ModuleSet) module);
90 // else if (module instanceof NameVersion) {
91 // NameVersion nv = (NameVersion) module;
92 // if (!nameVersions.contains(nv))
93 // nameVersions.add(nv);
95 // log.warn("Ignored " + module);
97 return nameVersions
.iterator();
100 private void processModule(List
<NameVersion
> nameVersions
, Object module
) {
101 if (module
instanceof ModuleSet
)
102 addNameVersions(nameVersions
, (ModuleSet
) module
);
103 else if (module
instanceof NameVersion
) {
104 NameVersion nv
= (NameVersion
) module
;
105 if (!nameVersions
.contains(nv
))
106 nameVersions
.add(nv
);
108 log
.warn("Ignored " + module
);
111 private void addNameVersions(List
<NameVersion
> nameVersions
,
112 ModuleSet moduleSet
) {
113 Iterator
<?
extends NameVersion
> it
= moduleSet
.nameVersions();
114 while (it
.hasNext()) {
115 NameVersion nv
= it
.next();
116 if (!nameVersions
.contains(nv
))
117 nameVersions
.add(nv
);
121 // Modular distribution interface methods. Not yet used.
122 public Distribution
getModuleDistribution(String moduleName
,
123 String moduleVersion
) {
124 // NameVersion searched = new DefaultNameVersion(moduleName,
126 // for (Distribution ad : modules) {
127 // if (ad.equals(searched))
133 public Object
getModulesDescriptor(String descriptorType
) {
134 // TODO Auto-generated method stub
138 /* DEPENDENCY INJECTION */
139 public void setModules(List
<Object
> modules
) {
140 this.modules
= modules
;