From: Mathieu Baudier Date: Fri, 26 Jun 2009 09:31:01 +0000 (+0000) Subject: Make OSGiBoot compatible with JDK 1.4 X-Git-Tag: argeo-slc-2.1.7~1756 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;ds=sidebyside;h=5a6f312be273231164d31304311d3fef193cc879;p=gpl%2Fargeo-slc.git Make OSGiBoot compatible with JDK 1.4 git-svn-id: https://svn.argeo.org/slc/trunk@2587 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.osgiboot/.classpath b/runtime/org.argeo.slc.osgiboot/.classpath index df370c061..05a2e8f84 100644 --- a/runtime/org.argeo.slc.osgiboot/.classpath +++ b/runtime/org.argeo.slc.osgiboot/.classpath @@ -1,8 +1,8 @@ - - - - - - - - + + + + + + + + diff --git a/runtime/org.argeo.slc.osgiboot/.settings/org.eclipse.jdt.core.prefs b/runtime/org.argeo.slc.osgiboot/.settings/org.eclipse.jdt.core.prefs index 23b8bc714..ba812fb90 100644 --- a/runtime/org.argeo.slc.osgiboot/.settings/org.eclipse.jdt.core.prefs +++ b/runtime/org.argeo.slc.osgiboot/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,12 @@ -#Tue Mar 03 21:15:27 CET 2009 +#Fri Jun 26 11:15:56 CEST 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.compliance=1.4 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 diff --git a/runtime/org.argeo.slc.osgiboot/pom.xml b/runtime/org.argeo.slc.osgiboot/pom.xml index 8278d1400..39ab6a9de 100644 --- a/runtime/org.argeo.slc.osgiboot/pom.xml +++ b/runtime/org.argeo.slc.osgiboot/pom.xml @@ -16,6 +16,10 @@ org.apache.maven.plugins maven-compiler-plugin + + 1.4 + 1.4 + org.apache.maven.plugins diff --git a/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java b/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java index 0f4f5ab23..3709e1a75 100644 --- a/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java +++ b/runtime/org.argeo.slc.osgiboot/src/main/java/org/argeo/slc/osgiboot/OsgiBoot.java @@ -25,8 +25,9 @@ public class OsgiBoot { public final static String DEFAULT_BASE_URL = "reference:file:"; public final static String EXCLUDES_SVN_PATTERN = "**/.svn/**"; - private Boolean debug = Boolean.parseBoolean(System.getProperty( - PROP_SLC_OSGIBOOT_DEBUG, "false")); + private boolean debug = Boolean.valueOf( + System.getProperty(PROP_SLC_OSGIBOOT_DEBUG, "false")) + .booleanValue(); private boolean excludeSvn = true; @@ -36,12 +37,13 @@ public class OsgiBoot { this.bundleContext = bundleContext; } - public void installUrls(List urls) { - Map installedBundles = getInstalledBundles(); - for (String url : urls) { + public void installUrls(List urls) { + Map installedBundles = getInstalledBundles(); + for (int i = 0; i < urls.size(); i++) { + String url = (String) urls.get(i); try { if (installedBundles.containsKey(url)) { - Bundle bundle = installedBundles.get(url); + Bundle bundle = (Bundle) installedBundles.get(url); // bundle.update(); if (debug) debug("Bundle " + bundle.getSymbolicName() @@ -82,10 +84,10 @@ public class OsgiBoot { if (bundlesToStart.size() == 0) return; - Map bundles = getBundles(); + Map bundles = getBundles(); for (int i = 0; i < bundlesToStart.size(); i++) { String name = bundlesToStart.get(i).toString(); - Bundle bundle = bundles.get(name); + Bundle bundle = (Bundle) bundles.get(name); if (bundle != null) try { bundle.start(); @@ -100,31 +102,34 @@ public class OsgiBoot { } /** Key is location */ - public Map getInstalledBundles() { - Map installedBundles = new HashMap(); + public Map getInstalledBundles() { + Map installedBundles = new HashMap(); - for (Bundle bundle : bundleContext.getBundles()) { - installedBundles.put(bundle.getLocation(), bundle); + Bundle[] bundles = bundleContext.getBundles(); + for (int i = 0; i < bundles.length; i++) { + installedBundles.put(bundles[i].getLocation(), bundles[i]); } return installedBundles; } /** Key is symbolic name */ - public Map getBundles() { - Map installedBundles = new HashMap(); - for (Bundle bundle : bundleContext.getBundles()) - installedBundles.put(bundle.getSymbolicName(), bundle); - return installedBundles; + public Map getBundles() { + Map namedBundles = new HashMap(); + Bundle[] bundles = bundleContext.getBundles(); + for (int i = 0; i < bundles.length; i++) { + namedBundles.put(bundles[i].getSymbolicName(), bundles[i]); + } + return namedBundles; } - public List getLocationsUrls() { + public List getLocationsUrls() { String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, DEFAULT_BASE_URL); String bundleLocations = getProperty(PROP_SLC_OSGI_LOCATIONS); return getLocationsUrls(baseUrl, bundleLocations); } - public List getLocationsUrls(String baseUrl, String bundleLocations) { - List urls = new ArrayList(); + public List getLocationsUrls(String baseUrl, String bundleLocations) { + List urls = new ArrayList(); if (bundleLocations == null) return urls; @@ -141,16 +146,16 @@ public class OsgiBoot { return urls; } - public List getBundlesUrls() { + public List getBundlesUrls() { String baseUrl = getProperty(PROP_SLC_OSGI_BASE_URL, DEFAULT_BASE_URL); String bundlePatterns = getProperty(PROP_SLC_OSGI_BUNDLES); return getBundlesUrls(baseUrl, bundlePatterns); } - public List getBundlesUrls(String baseUrl, String bundlePatterns) { - List urls = new ArrayList(); + public List getBundlesUrls(String baseUrl, String bundlePatterns) { + List urls = new ArrayList(); - List bundlesSets = new ArrayList(); + List bundlesSets = new ArrayList(); if (bundlePatterns == null) return urls; bundlePatterns = SystemPropertyUtils @@ -164,18 +169,27 @@ public class OsgiBoot { bundlesSets.add(new BundlesSet(st.nextToken())); } - List included = new ArrayList(); + List included = new ArrayList(); PathMatcher matcher = new AntPathMatcher(); - for (BundlesSet bundlesSet : bundlesSets) - for (String pattern : bundlesSet.getIncludes()) + for (int i = 0; i < bundlesSets.size(); i++) { + BundlesSet bundlesSet = (BundlesSet) bundlesSets.get(i); + for (int j = 0; j < bundlesSet.getIncludes().size(); j++) { + String pattern = (String) bundlesSet.getIncludes().get(j); match(matcher, included, bundlesSet.getDir(), null, pattern); + } + } - List excluded = new ArrayList(); - for (BundlesSet bundlesSet : bundlesSets) - for (String pattern : bundlesSet.getExcludes()) + List excluded = new ArrayList(); + for (int i = 0; i < bundlesSets.size(); i++) { + BundlesSet bundlesSet = (BundlesSet) bundlesSets.get(i); + for (int j = 0; j < bundlesSet.getExcludes().size(); j++) { + String pattern = (String) bundlesSet.getExcludes().get(j); match(matcher, excluded, bundlesSet.getDir(), null, pattern); + } + } - for (String fullPath : included) { + for (int i = 0; i < included.size(); i++) { + String fullPath = (String) included.get(i); if (!excluded.contains(fullPath)) urls.add(baseUrl + fullPath); } @@ -183,8 +197,8 @@ public class OsgiBoot { return urls; } - protected void match(PathMatcher matcher, List matched, - String base, String currentPath, String pattern) { + protected void match(PathMatcher matcher, List matched, String base, + String currentPath, String pattern) { if (currentPath == null) { // Init File baseDir = new File(base.replace('/', File.separatorChar)); @@ -197,8 +211,8 @@ public class OsgiBoot { return; } - for (File file : files) - match(matcher, matched, base, file.getName(), pattern); + for (int i = 0; i < files.length; i++) + match(matcher, matched, base, files[i].getName(), pattern); } else { String fullPath = base + '/' + currentPath; if (matched.contains(fullPath)) @@ -212,14 +226,14 @@ public class OsgiBoot { matched.add(fullPath); return; } else { - String newFullPath = (base + '/' + currentPath).replace('/', - File.separatorChar); - File[] files = new File(newFullPath).listFiles(); + String newFullPath = relativeToFullPath(base, currentPath); + File newFile = new File(newFullPath); + File[] files = newFile.listFiles(); if (files != null) { - for (File file : files) - if (file.isDirectory()) { - String newCurrentPath = currentPath + '/' - + file.getName(); + for (int i = 0; i < files.length; i++) { + String newCurrentPath = currentPath + '/' + + files[i].getName(); + if (files[i].isDirectory()) { if (matcher.matchStart(pattern, newCurrentPath)) { // recurse only if start matches match(matcher, matched, base, newCurrentPath, @@ -231,14 +245,27 @@ public class OsgiBoot { + pattern); } + } else { + boolean nonDirectoryOk = matcher.match(pattern, + newCurrentPath); + if (debug) + debug(currentPath + " " + (ok ? "" : " not ") + + " matched with " + pattern); + if (nonDirectoryOk) + matched.add(relativeToFullPath(base, + newCurrentPath)); } - } else { - // warn("Not a directory: " + newFullPath); + } } } } } + /** Transforms a relative path in a full system path. */ + protected String relativeToFullPath(String basePath, String relativePath) { + return (basePath + '/' + relativePath).replace('/', File.separatorChar); + } + protected void info(Object obj) { System.out.println("# INFO " + obj); } @@ -274,11 +301,11 @@ public class OsgiBoot { return getProperty(name, null); } - public Boolean getDebug() { + public boolean getDebug() { return debug; } - public void setDebug(Boolean debug) { + public void setDebug(boolean debug) { this.debug = debug; } @@ -298,8 +325,8 @@ public class OsgiBoot { protected class BundlesSet { private String baseUrl = "reference:file";// not used yet private final String dir; - private List includes = new ArrayList(); - private List excludes = new ArrayList(); + private List includes = new ArrayList(); + private List excludes = new ArrayList(); public BundlesSet(String def) { StringTokenizer st = new StringTokenizer(def, ";"); @@ -345,11 +372,11 @@ public class OsgiBoot { return dir; } - public List getIncludes() { + public List getIncludes() { return includes; } - public List getExcludes() { + public List getExcludes() { return excludes; }