]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java
e433d7e29e18a14597460a1b483959c659c023a5
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.osgi / src / main / java / org / argeo / slc / osgi / OsgiRuntime.java
1 package org.argeo.slc.osgi;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.UUID;
6
7 import org.argeo.slc.UnsupportedException;
8 import org.argeo.slc.build.Distribution;
9 import org.argeo.slc.core.build.VersionedResourceDistribution;
10 import org.argeo.slc.deploy.DeploymentData;
11 import org.argeo.slc.deploy.ModularDeployedSystem;
12 import org.argeo.slc.deploy.TargetData;
13 import org.osgi.framework.Bundle;
14 import org.osgi.framework.BundleContext;
15 import org.springframework.context.ResourceLoaderAware;
16 import org.springframework.core.io.Resource;
17 import org.springframework.core.io.ResourceLoader;
18 import org.springframework.osgi.context.BundleContextAware;
19
20 public class OsgiRuntime implements ModularDeployedSystem<OsgiBundle>,
21 BundleContextAware, ResourceLoaderAware {
22 private String uuid = UUID.randomUUID().toString();
23 private BundleContext bundleContext;
24 private ResourceLoader resourceLoader;
25
26 public List<OsgiBundle> listModules() {
27 List<OsgiBundle> modules = new ArrayList<OsgiBundle>();
28 Bundle[] bundles = bundleContext.getBundles();
29 for (Bundle bundle : bundles) {
30 OsgiBundle osgiBundle = new OsgiBundle(bundle);
31 modules.add(osgiBundle);
32 String location = bundle.getLocation();
33 if (location != null) {
34 Resource resource = resourceLoader.getResource(location);
35 osgiBundle
36 .setDistribution(new VersionedResourceDistribution(
37 osgiBundle.getName(), osgiBundle.getVersion(),
38 resource));
39 }
40 }
41 return modules;
42 }
43
44 public String getDeployedSystemId() {
45 return uuid;
46 }
47
48 public DeploymentData getDeploymentData() {
49 throw new UnsupportedException();
50 }
51
52 public Distribution getDistribution() {
53 throw new UnsupportedException();
54 }
55
56 public TargetData getTargetData() {
57 throw new UnsupportedException();
58 }
59
60 public void setBundleContext(BundleContext bundleContext) {
61 this.bundleContext = bundleContext;
62 }
63
64 public void setResourceLoader(ResourceLoader resourceLoader) {
65 this.resourceLoader = resourceLoader;
66 }
67
68 }