]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/ArgeoOsgiDistribution.java
709a8882b958524b36bb6bd4158f7b252c940595
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
.build
.ModularDistribution
;
15 import org
.argeo
.slc
.execution
.ExecutionFlow
;
16 import org
.argeo
.slc
.repo
.ArtifactDistribution
;
18 /** A consistent and versioned OSGi distribution, which can be built and tested. */
19 public class ArgeoOsgiDistribution
extends ArtifactDistribution
implements
21 private final static Log log
= LogFactory
22 .getLog(ArgeoOsgiDistribution
.class);
24 private List
<Object
> modules
= new ArrayList
<Object
>();
26 public ArgeoOsgiDistribution(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 Distribution
getModuleDistribution(String moduleName
,
73 String moduleVersion
) {
74 // NameVersion searched = new DefaultNameVersion(moduleName,
76 // for (Distribution ad : modules) {
77 // if (ad.equals(searched))
83 public Iterator
<NameVersion
> nameVersions() {
84 List
<NameVersion
> nameVersions
= new ArrayList
<NameVersion
>();
85 for (Object module
: modules
) {
86 // extract runnable from execution flow
87 if (module
instanceof ExecutionFlow
)
88 module
= ((ExecutionFlow
) module
).getRunnable();
90 if (module
instanceof ModuleSet
)
91 addNameVersions(nameVersions
, (ModuleSet
) module
);
92 else if (module
instanceof NameVersion
) {
93 NameVersion nv
= (NameVersion
) module
;
94 if (!nameVersions
.contains(nv
))
97 log
.warn("Ignored " + module
);
99 return nameVersions
.iterator();
102 private void addNameVersions(List
<NameVersion
> nameVersions
,
103 ModuleSet moduleSet
) {
104 Iterator
<?
extends NameVersion
> it
= moduleSet
.nameVersions();
105 while (it
.hasNext()) {
106 NameVersion nv
= it
.next();
107 if (!nameVersions
.contains(nv
))
108 nameVersions
.add(nv
);
112 public Object
getModulesDescriptor(String descriptorType
) {
113 // TODO Auto-generated method stub
117 public void setModules(List
<Object
> modules
) {
118 this.modules
= modules
;