]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java
Improve OSGi factory
[gpl/argeo-slc.git] / runtime / org.argeo.slc.repo / src / main / java / org / argeo / slc / repo / osgi / ArgeoOsgiDistribution.java
1 package org.argeo.slc.repo.osgi;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.slc.ModuleSet;
10 import org.argeo.slc.NameVersion;
11 import org.argeo.slc.build.Distribution;
12 import org.argeo.slc.build.ModularDistribution;
13 import org.argeo.slc.execution.ExecutionFlow;
14 import org.argeo.slc.repo.ArtifactDistribution;
15
16 /** A consistent and versioned OSGi distribution, which can be built and tested. */
17 public class ArgeoOsgiDistribution extends ArtifactDistribution implements
18 ModularDistribution {
19 private final static Log log = LogFactory
20 .getLog(ArgeoOsgiDistribution.class);
21
22 private List<Object> modules = new ArrayList<Object>();
23
24 public ArgeoOsgiDistribution(String coords) {
25 super(coords);
26 }
27
28 public void init() {
29 if (log.isDebugEnabled()) {
30 Iterator<? extends NameVersion> nvIt = nameVersions();
31 while (nvIt.hasNext()) {
32 log.debug(nvIt.next());
33
34 }
35 }
36 }
37
38 // private static void print(ModuleSet moduleSet, Integer depth) {
39 // StringBuilder prefix = new StringBuilder();
40 // for (int i = 0; i < depth; i++) {
41 // prefix.append(' ');
42 // }
43 // String p = prefix.toString();
44 // prefix.setLength(0);
45 // log.debug(p + "## " + moduleSet.toString());
46 // Iterator<? extends NameVersion> nvIt = moduleSet.nameVersions();
47 // while (nvIt.hasNext()) {
48 // NameVersion nv = nvIt.next();
49 // if (nv instanceof ModuleSet)
50 // print((ModuleSet) nv, depth + 1);
51 // else
52 // log.debug(p + nv);
53 //
54 // }
55 // }
56
57 public void destroy() {
58
59 }
60
61 public Distribution getModuleDistribution(String moduleName,
62 String moduleVersion) {
63 // NameVersion searched = new DefaultNameVersion(moduleName,
64 // moduleVersion);
65 // for (Distribution ad : modules) {
66 // if (ad.equals(searched))
67 // return ad;
68 // }
69 return null;
70 }
71
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();
78
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))
84 nameVersions.add(nv);
85 } else
86 log.warn("Ignored " + module);
87 }
88 return nameVersions.iterator();
89 }
90
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))
97 nameVersions.add(nv);
98 }
99 }
100
101 public Object getModulesDescriptor(String descriptorType) {
102 // TODO Auto-generated method stub
103 return null;
104 }
105
106 public void setModules(List<Object> modules) {
107 this.modules = modules;
108 }
109
110 }