diff options
author | DJ Houghton | 2008-11-25 19:51:23 +0000 |
---|---|---|
committer | DJ Houghton | 2008-11-25 19:51:23 +0000 |
commit | 9532e99fe38608885b871fcd2d361020b89f12c0 (patch) | |
tree | 03c7edfe0d37b0a9e7798456585ecfe1c59a5a53 /bundles/org.eclipse.equinox.frameworkadmin | |
parent | 4722ab4bc3574c191036f1014c05334977736d35 (diff) | |
download | rt.equinox.p2-9532e99fe38608885b871fcd2d361020b89f12c0.tar.gz rt.equinox.p2-9532e99fe38608885b871fcd2d361020b89f12c0.tar.xz rt.equinox.p2-9532e99fe38608885b871fcd2d361020b89f12c0.zip |
Merged path_fun_2008 branch.v20081125_postPathFunMerge
Diffstat (limited to 'bundles/org.eclipse.equinox.frameworkadmin')
5 files changed, 114 insertions, 125 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java index f0f4f4523..9a479d614 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/SimpleBundlesState.java @@ -11,7 +11,8 @@ package org.eclipse.equinox.internal.frameworkadmin.utils; import java.io.File; -import java.net.MalformedURLException; +import java.io.IOException; +import java.net.URI; import java.util.*; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; import org.osgi.framework.Constants; @@ -118,7 +119,7 @@ public class SimpleBundlesState implements BundlesState { * @see org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState#getPrerequisteBundles(org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo) */ public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo) { - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); final String requiredBundles = Utils.getManifestMainAttributes(location, Constants.REQUIRE_BUNDLE); if (requiredBundles == null) return new BundleInfo[] {this.getSystemBundle()}; @@ -132,7 +133,7 @@ public class SimpleBundlesState implements BundlesState { ret.add(this.getSystemBundle()); for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo currentBInfo = (BundleInfo) ite.next(); - String currentLocation = currentBInfo.getLocation(); + URI currentLocation = currentBInfo.getLocation(); String currentSymbolicName = Utils.getManifestMainAttributes(currentLocation, Constants.BUNDLE_SYMBOLICNAME); if (currentSymbolicName == null) continue; @@ -154,7 +155,7 @@ public class SimpleBundlesState implements BundlesState { BundleInfo bInfo = (BundleInfo) ite.next(); // if (bInfo.getStartLevel() != 1) // return null;; - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String bundleName = Utils.getManifestMainAttributes(location, Constants.BUNDLE_NAME); if (systemBundleName.equals(bundleName)) { String bundleVendor = Utils.getManifestMainAttributes(location, Constants.BUNDLE_VENDOR); @@ -166,7 +167,7 @@ public class SimpleBundlesState implements BundlesState { } for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo bInfo = (BundleInfo) ite.next(); - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String symbolicName = Utils.getManifestMainAttributes(location, Constants.BUNDLE_SYMBOLICNAME); symbolicName = Utils.getPathFromClause(symbolicName); if (this.systemBundleSymbolicName.equals(symbolicName)) @@ -183,7 +184,7 @@ public class SimpleBundlesState implements BundlesState { List list = new LinkedList(); for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo bInfo = (BundleInfo) ite.next(); - String location = bInfo.getLocation(); + URI location = bInfo.getLocation(); String manifestVersion = Utils.getManifestMainAttributes(location, Constants.BUNDLE_MANIFESTVERSION); if (manifestVersion == null) continue; @@ -227,20 +228,14 @@ public class SimpleBundlesState implements BundlesState { this.installBundle(bInfos[j]); if (getSystemBundle() == null) { - try { - BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURL().toExternalForm(), 0, true, 0); - this.installBundle(sysBInfo); - - } catch (MalformedURLException e) { - // Nothign to do because never happens. - e.printStackTrace(); - } + BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURI(), 0, true, 0); + this.installBundle(sysBInfo); } } public void installBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { - String newLocation = bInfo.getLocation(); + URI newLocation = bInfo.getLocation(); Dictionary newManifest = Utils.getOSGiManifest(newLocation); if (newManifest == null) { // TODO log something here @@ -252,7 +247,7 @@ public class SimpleBundlesState implements BundlesState { boolean found = false; for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { BundleInfo currentBInfo = (BundleInfo) ite.next(); - String location = currentBInfo.getLocation(); + URI location = currentBInfo.getLocation(); if (newLocation.equals(location)) { found = true; break; @@ -315,12 +310,12 @@ public class SimpleBundlesState implements BundlesState { } public void uninstallBundle(BundleInfo bInfo) throws FrameworkAdminRuntimeException { - String targetLocation = bInfo.getLocation(); + URI targetLocation = bInfo.getLocation(); int index = -1; for (Iterator ite = this.bundleInfosList.iterator(); ite.hasNext();) { index++; BundleInfo currentBInfo = (BundleInfo) ite.next(); - String location = currentBInfo.getLocation(); + URI location = currentBInfo.getLocation(); if (targetLocation.equals(location)) { break; } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java index 68a5575ef..95d79bf58 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/frameworkadmin/utils/Utils.java @@ -26,7 +26,7 @@ import org.osgi.framework.Constants; public class Utils { private static final String FEATURE_MANIFEST = "feature.xml"; //$NON-NLS-1$ - private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$ + private static final String FILE_SCHEME = "file"; //$NON-NLS-1$ private static final String FRAGMENT_MANIFEST = "fragment.xml"; //$NON-NLS-1$ private static final String PATH_SEP = "/"; //$NON-NLS-1$ private static final String PLUGIN_MANIFEST = "plugin.xml"; //$NON-NLS-1$ @@ -171,11 +171,13 @@ public class Utils { } } - public static void createParentDir(File file) throws IOException { + public static boolean createParentDir(File file) { File parent = file.getParentFile(); if (parent == null) - return; - parent.mkdirs(); + return false; + if (parent.exists()) + return true; + return parent.mkdirs(); } public static BundleInfo[] getBundleInfosFromList(List list) { @@ -197,32 +199,32 @@ public class Utils { return ret; } - public static String[] getClausesManifestMainAttributes(String location, String name) { + public static String[] getClausesManifestMainAttributes(URI location, String name) { return getClauses(getManifestMainAttributes(location, name)); } - public static String getManifestMainAttributes(String location, String name) { + public static String getManifestMainAttributes(URI location, String name) { Dictionary manifest = Utils.getOSGiManifest(location); if (manifest == null) throw new RuntimeException("Unable to locate bundle manifest: " + location); return (String) manifest.get(name); } - public static Dictionary getOSGiManifest(String location) { + public static Dictionary getOSGiManifest(URI location) { if (location == null) return null; // if we have a file-based URL that doesn't end in ".jar" then... - if (location.startsWith(FILE_PROTOCOL) && !location.endsWith(".jar")) - return basicLoadManifest(new File(location.substring(FILE_PROTOCOL.length()))); + if (FILE_SCHEME.equals(location.getScheme()) && !location.getPath().endsWith(".jar")) + return basicLoadManifest(new File(location)); try { JarFile jar = null; File file = null; - if (location.startsWith(FILE_PROTOCOL)) { - file = new File(location.substring(FILE_PROTOCOL.length())); + if (FILE_SCHEME.equals(location.getScheme())) { + file = new File(location); jar = new JarFile(file); } else { - URL url = new URL("jar:" + location + "!/"); + URL url = new URL("jar:" + location.toString() + "!/"); JarURLConnection jarConnection = (JarURLConnection) url.openConnection(); jar = jarConnection.getJarFile(); // todo should set this var if possible diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java index c3c1c1a9d..c755c0dab 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/BundleInfo.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.equinox.internal.provisional.frameworkadmin; -import org.eclipse.core.runtime.Path; +import java.net.URI; /** * This object represents information of a bundle. @@ -22,7 +22,8 @@ public class BundleInfo { private String symbolicName = null; private String version = null; - private String location; + private URI baseLocation; + private URI location; private long bundleId = NO_BUNDLEID; private boolean markedAsStarted = false; @@ -34,71 +35,50 @@ public class BundleInfo { public BundleInfo() { } - public BundleInfo(String location) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location) { + this.location = location; } - public BundleInfo(String location, boolean started) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, boolean started) { + this.location = location; this.markedAsStarted = started; } - public BundleInfo(String location, int startLevel) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel) { + this.location = location; this.startLevel = startLevel; } - public BundleInfo(String location, int startLevel, boolean started) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel, boolean started) { + this.location = location; this.startLevel = startLevel; this.markedAsStarted = started; } - public BundleInfo(String location, int startLevel, boolean started, long bundleId) { - if (location != null) - this.location = location.trim(); + public BundleInfo(URI location, int startLevel, boolean started, long bundleId) { + this.location = location; this.startLevel = startLevel; this.markedAsStarted = started; this.bundleId = bundleId; } - public BundleInfo(String symbolic, String version, String location, int startLevel, boolean started) { + public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started) { this.symbolicName = symbolic; this.version = version; - if (location != null) - this.location = location.trim(); + this.location = location; this.markedAsStarted = started; this.startLevel = startLevel; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object toCompare) { - if (toCompare instanceof BundleInfo) { - BundleInfo info = (BundleInfo) toCompare; - //if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.url == null || url == null ? true : info.url.equals(url))) - if (info.symbolicName != null && info.version != null && symbolicName != null && version != null) { - // TODO: the equalsIgnoreCase for location comparison is a bug; - // need a platform sensitive location comparison method - if (info.symbolicName.equals(symbolicName) && info.version.equals(version) && (info.location == null || location == null ? true : new Path(info.location).toFile().equals(new Path(location).toFile()))) - return true; - } else { - return (info.location == null || location == null ? false : new Path(info.location).toFile().equals(new Path(location).toFile())); - } - } - return false; - } - public long getBundleId() { return bundleId; } - public String getLocation() { + public URI getBaseLocation() { + return baseLocation; + } + + public URI getLocation() { return location; } @@ -118,15 +98,6 @@ public class BundleInfo { return version; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - int result = symbolicName == null ? 0 : symbolicName.hashCode(); - result = result + (version == null ? 0 : version.hashCode()); - return result; - } - public boolean isMarkedAsStarted() { return markedAsStarted; } @@ -139,9 +110,12 @@ public class BundleInfo { this.bundleId = bundleId; } - public void setLocation(String location) { - this.location = (location != null ? location.trim() : null); + public void setBaseLocation(URI baseLocation) { + this.baseLocation = baseLocation; + } + public void setLocation(URI location) { + this.location = location; } public void setManifest(String manifest) { @@ -179,8 +153,12 @@ public class BundleInfo { buffer.append(", "); //$NON-NLS-1$ if (version != null) buffer.append(version); - buffer.append(", "); //$NON-NLS-1$ - buffer.append("location="); //$NON-NLS-1$ + + if (baseLocation != null) { + buffer.append(", baseLocation="); //$NON-NLS-1$ + buffer.append(baseLocation); + } + buffer.append(", location="); //$NON-NLS-1$ buffer.append(location); buffer.append(", startLevel="); //$NON-NLS-1$ buffer.append(startLevel); @@ -194,4 +172,45 @@ public class BundleInfo { buffer.append(')'); return buffer.toString(); } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((symbolicName == null) ? 0 : symbolicName.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (obj == null) + return false; + + if (getClass() != obj.getClass()) + return false; + + BundleInfo other = (BundleInfo) obj; + if (symbolicName == null) { + if (other.symbolicName != null) + return false; + } else if (!symbolicName.equals(other.symbolicName)) + return false; + + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + + if (location == null || other.location == null) + return true; + + //compare absolute location URIs + URI absoluteLocation = baseLocation == null ? location : baseLocation.resolve(location); + URI otherAbsoluteLocation = other.baseLocation == null ? other.location : other.baseLocation.resolve(other.location); + + return absoluteLocation.equals(otherAbsoluteLocation); + } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java index 8a4bf076f..2118b5e72 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/ConfigData.java @@ -47,9 +47,8 @@ public class ConfigData { private int initialBundleStartLevel = BundleInfo.NO_LEVEL; // List of BundleInfo private LinkedHashSet bundlesList = new LinkedHashSet(); - private Properties fwIndependentProps = new Properties(); - private Properties fwDependentProps = new Properties(); + private Properties properties = new Properties(); public ConfigData(String fwName, String fwVersion, String launcherName, String launcherVersion) { this.fwName = fwName; @@ -75,23 +74,13 @@ public class ConfigData { return ret; } - public String getFwDependentProp(String key) { - return fwDependentProps.getProperty(key); + public String getProperty(String key) { + return properties.getProperty(key); } - public Properties getFwDependentProps() { + public Properties getProperties() { Properties ret = new Properties(); - appendProperties(ret, fwDependentProps); - return ret; - } - - public String getFwIndependentProp(String key) { - return fwIndependentProps.getProperty(key); - } - - public Properties getFwIndependentProps() { - Properties ret = new Properties(); - appendProperties(ret, fwIndependentProps); + appendProperties(ret, properties); return ret; } @@ -119,8 +108,8 @@ public class ConfigData { beginningFwStartLevel = BundleInfo.NO_LEVEL; initialBundleStartLevel = BundleInfo.NO_LEVEL; bundlesList.clear(); - fwIndependentProps.clear(); - fwDependentProps.clear(); + properties.clear(); + properties.clear(); } public boolean removeBundle(BundleInfo bundleInfo) { @@ -140,28 +129,16 @@ public class ConfigData { bundlesList.add(bundleInfos[i]); } - public void setFwDependentProp(String key, String value) { - if (value == null) - fwDependentProps.remove(key); - else - fwDependentProps.setProperty(key, value); - } - - public void setFwDependentProps(Properties props) { - fwDependentProps.clear(); - appendProperties(fwDependentProps, props); - } - - public void setFwIndependentProp(String key, String value) { + public void setProperty(String key, String value) { if (value == null) - fwIndependentProps.remove(key); + properties.remove(key); else - fwIndependentProps.setProperty(key, value); + properties.setProperty(key, value); } - public void setFwIndependentProps(Properties props) { - fwIndependentProps.clear(); - appendProperties(fwIndependentProps, props); + public void setProperties(Properties props) { + properties.clear(); + appendProperties(properties, props); } public void setInitialBundleStartLevel(int startLevel) { @@ -189,12 +166,9 @@ public class ConfigData { } } - sb.append("============ Fw Independent Props ===============\n"); //$NON-NLS-1$ + sb.append("============ Properties ===============\n"); //$NON-NLS-1$ sb.append("fwIndependentProps="); //$NON-NLS-1$ - setPropsStrings(sb, fwIndependentProps); - sb.append("============ Fw Dependent Props ===============\n"); //$NON-NLS-1$ - sb.append("fwDependentProps="); //$NON-NLS-1$ - setPropsStrings(sb, fwDependentProps); + setPropsStrings(sb, properties); return sb.toString(); } diff --git a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java index ad8fd4917..a5dcb34d8 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java +++ b/bundles/org.eclipse.equinox.frameworkadmin/src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java @@ -23,7 +23,6 @@ import java.util.*; * @see Manipulator */ public class LauncherData { - //private static final String[] NULL_STRINGS = new String[0]; private File fwPersistentDataLocation = null; private File jvm = null; private List jvmArgs = new LinkedList(); |