]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/BundlesManager.java
Improve OSGi console extension
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.equinox / src / main / java / org / argeo / slc / osgi / BundlesManager.java
1 package org.argeo.slc.osgi;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.osgi.framework.Bundle;
11 import org.osgi.framework.BundleContext;
12 import org.osgi.framework.BundleException;
13 import org.springframework.osgi.context.BundleContextAware;
14
15 public class BundlesManager implements BundleContextAware {
16 private final static Log log = LogFactory.getLog(BundlesManager.class);
17
18 private BundleContext bundleContext;
19
20 private List<String> urlsToInstall;
21
22 public void init() {
23 // Install
24 if (urlsToInstall != null) {
25 Map<String, Bundle> installedBundles = new HashMap<String, Bundle>();
26 for (Bundle bundle : bundleContext.getBundles())
27 installedBundles.put(bundle.getLocation(), bundle);
28
29 for (String url : urlsToInstall)
30 try {
31
32 if (installedBundles.containsKey(url)) {
33 Bundle bundle = installedBundles.get(url);
34 // bundle.update();
35 log.debug("Bundle " + bundle.getSymbolicName()
36 + " already installed from " + url);
37 } else {
38 Bundle bundle = bundleContext.installBundle(url);
39 log.debug("Installed bundle "
40 + bundle.getSymbolicName() + " from " + url);
41 }
42 } catch (BundleException e) {
43 log.warn("Could not install bundle from " + url + ": "
44 + e.getMessage());
45 }
46 }
47
48 }
49
50 public void setBundleContext(BundleContext bundleContext) {
51 this.bundleContext = bundleContext;
52 }
53
54 public void setUrlsToInstall(List<String> urlsToInstall) {
55 this.urlsToInstall = urlsToInstall;
56 }
57
58 }