1 package org.argeo.slc.repo.osgi;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.SortedSet;
7 import java.util.TreeSet;
8
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;
17
18
19 public class ArgeoOsgiDistributionImpl extends ArtifactDistribution implements
20 ArgeoOsgiDistribution {
21 private final static Log log = LogFactory
22 .getLog(ArgeoOsgiDistributionImpl.class);
23
24 private List<Object> modules = new ArrayList<Object>();
25
26 public ArgeoOsgiDistributionImpl(String coords) {
27 super(coords);
28 }
29
30 public void init() {
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());
37 }
38
39 StringBuffer buf = new StringBuffer(
40 "## OSGi FACTORY MANAGED MODULES : \n");
41 for (String str : sort) {
42 buf.append(str).append('\n');
43 }
44
45 log.debug(buf);
46 }
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public void destroy() {
69
70 }
71
72 public Iterator<NameVersion> nameVersions() {
73 List<NameVersion> nameVersions = new ArrayList<NameVersion>();
74 for (Object module : modules) {
75
76 if (module instanceof ExecutionFlow) {
77 for (Iterator<Runnable> it = ((ExecutionFlow) module)
78 .runnables(); it.hasNext();) {
79 processModule(nameVersions, it.next());
80 }
81 }
82
83 else {
84 processModule(nameVersions, module);
85 }
86
87
88
89
90
91
92
93
94 }
95 return nameVersions.iterator();
96 }
97
98 private void processModule(List<NameVersion> nameVersions, Object module) {
99 if (module instanceof ModuleSet)
100 addNameVersions(nameVersions, (ModuleSet) module);
101 else if (module instanceof NameVersion) {
102 NameVersion nv = (NameVersion) module;
103 if (!nameVersions.contains(nv))
104 nameVersions.add(nv);
105 } else
106 log.warn("Ignored " + module);
107 }
108
109 private void addNameVersions(List<NameVersion> nameVersions,
110 ModuleSet moduleSet) {
111 Iterator<? extends NameVersion> it = moduleSet.nameVersions();
112 while (it.hasNext()) {
113 NameVersion nv = it.next();
114 if (!nameVersions.contains(nv))
115 nameVersions.add(nv);
116 }
117 }
118
119
120 public Distribution getModuleDistribution(String moduleName,
121 String moduleVersion) {
122
123
124
125
126
127
128 return null;
129 }
130
131 public Object getModulesDescriptor(String descriptorType) {
132
133 return null;
134 }
135
136
137 public void setModules(List<Object> modules) {
138 this.modules = modules;
139 }
140 }