- protected static void installUrls(BundleContext bundleContext,
- List<String> urls) {
- Map<String, Bundle> installedBundles = getInstalledBundles(bundleContext);
- for (String url : urls) {
- try {
-
- if (installedBundles.containsKey(url)) {
- Bundle bundle = installedBundles.get(url);
- // bundle.update();
- if (debug)
- debug("Bundle " + bundle.getSymbolicName()
- + " already installed from " + url);
- } else {
- Bundle bundle = bundleContext.installBundle(url);
- if (debug)
- debug("Installed bundle " + bundle.getSymbolicName()
- + " from " + url);
- }
- } catch (BundleException e) {
- warn("Could not install bundle from " + url + ": "
- + e.getMessage());
- }
- }
-
- }
-
- protected List<String> getLocationsUrls() {
- List<String> urlsProvided = new ArrayList<String>();
-
- String bundlesList = getProperty(PROP_SLC_OSGI_LOCATIONS);
- if (bundlesList == null)
- return urlsProvided;
- bundlesList = SystemPropertyUtils.resolvePlaceholders(bundlesList);
-
- StringTokenizer st = new StringTokenizer(bundlesList,
- File.pathSeparator);
- while (st.hasMoreTokens()) {
- urlsProvided.add("reference:file:" + st.nextToken().trim());
- }
- return urlsProvided;
- }
-
- protected List<String> getDevLocationsUrls() {
- List<String> urls = new ArrayList<String>();
-
- String devBase = getProperty(PROP_SLC_OSGI_DEV_BASES);
- String devPatterns = getProperty(PROP_SLC_OSGI_DEV_PATTERNS);
- if (devBase == null)
- return urls;
- devBase = SystemPropertyUtils.resolvePlaceholders(devBase);
- devBase = devBase.replace(File.separatorChar, '/');
- devPatterns = SystemPropertyUtils.resolvePlaceholders(devPatterns);
-
- List<String> bases = new ArrayList<String>();
- StringTokenizer st = new StringTokenizer(devBase, ",");
- while (st.hasMoreTokens()) {
- String token = st.nextToken().trim();
- char lastChar = token.charAt(token.length() - 1);
- if (lastChar != '/')
- token = token + '/';
- bases.add(token);
- }
-
- List<String> patterns = new ArrayList<String>();
- st = new StringTokenizer(devPatterns, ";");
- while (st.hasMoreTokens()) {
- patterns.add(st.nextToken().trim());
- }
-
- List<String> matched = new ArrayList<String>();
- PathMatcher matcher = new AntPathMatcher();
- for (String base : bases)
- for (String pattern : patterns)
- match(matcher, matched, base, null, pattern);
-
- for (String fullPath : matched)
- urls.add("reference:file:" + fullPath);
-
- return urls;
- }
-
- protected void match(PathMatcher matcher, List<String> matched,
- String base, String currentPath, String pattern) {
- if (currentPath == null) {
- // Init
- File baseDir = new File(base.replace('/', File.separatorChar));
- File[] files = baseDir.listFiles();
-
- if (files == null) {
- warn("Base dir " + baseDir + " has no children, exists="
- + baseDir.exists() + ", isDirectory="
- + baseDir.isDirectory());
- return;
- }
-
- for (File file : files)
- if (file.isDirectory())
- match(matcher, matched, base, file.getName(), pattern);
- } else {
- String fullPath = base + currentPath;
- if (matched.contains(fullPath))
- return;// don't try deeper if already matched
-
- boolean ok = matcher.match(pattern, currentPath);
- if (debug)
- debug(currentPath + " " + (ok ? "" : " not ")
- + " matched with " + pattern);
- if (ok) {
- matched.add(fullPath);
- return;
- } else {
- File[] files = new File((base + currentPath).replace('/',
- File.separatorChar)).listFiles();
- for (File file : files)
- if (file.isDirectory()) {
- String newCurrentPath = currentPath + '/'
- + file.getName();
- if (matcher.matchStart(pattern, newCurrentPath)) {
- // recurse only if start matches
- match(matcher, matched, base, newCurrentPath,
- pattern);
- } else {
- if (debug)
- debug(newCurrentPath
- + " does not start match with "
- + pattern);
-
- }
- }
- }
- }
- }
-