Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2008-03-04 03:16:27 +0000
committerPascal Rapicault2008-03-04 03:16:27 +0000
commitd731012886ac574825ebe13666dc1c0fb5ad5323 (patch)
tree77c2521ab49cc0b1564cb20ef1e28ea416e4eca4
parent7a0d2f5567d3eacf6cd14efed77fd551d0eaa50b (diff)
downloadrt.equinox.p2-d731012886ac574825ebe13666dc1c0fb5ad5323.tar.gz
rt.equinox.p2-d731012886ac574825ebe13666dc1c0fb5ad5323.tar.xz
rt.equinox.p2-d731012886ac574825ebe13666dc1c0fb5ad5323.zip
Bug 221256 - [um] paths to site in platform are not relativized
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java39
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Configuration.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationParser.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationWriter.java15
-rw-r--r--bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Utils.java101
10 files changed, 175 insertions, 27 deletions
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
index b9c4cfdb8..4a494d2d5 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
@@ -56,7 +56,7 @@ public class LinksManager {
return;
// read the existing configuration from disk
- configuration = ConfigurationParser.parse(configurationFile);
+ configuration = ConfigurationParser.parse(configurationFile, null);
if (configuration == null)
return;
@@ -71,7 +71,7 @@ public class LinksManager {
// write out a new file if there were any changes.
if (dirty)
- ConfigurationWriter.save(configuration, configurationFile);
+ ConfigurationWriter.save(configuration, configurationFile, null);
dirty = false;
}
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
index d83fdba3b..8b9a67180 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
@@ -70,7 +70,7 @@ public class PlatformXmlListener extends DirectoryChangeListener {
* Parse the platform.xml file and return the list of sites.
*/
private List parseConfiguration() throws ProvisionException {
- Configuration cfg = ConfigurationParser.parse(root);
+ Configuration cfg = ConfigurationParser.parse(root, null);
return cfg == null ? new ArrayList(0) : cfg.getSites();
}
diff --git a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
index b9c4cfdb8..4a494d2d5 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/LinksManager.java
@@ -56,7 +56,7 @@ public class LinksManager {
return;
// read the existing configuration from disk
- configuration = ConfigurationParser.parse(configurationFile);
+ configuration = ConfigurationParser.parse(configurationFile, null);
if (configuration == null)
return;
@@ -71,7 +71,7 @@ public class LinksManager {
// write out a new file if there were any changes.
if (dirty)
- ConfigurationWriter.save(configuration, configurationFile);
+ ConfigurationWriter.save(configuration, configurationFile, null);
dirty = false;
}
diff --git a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
index d83fdba3b..8b9a67180 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
@@ -70,7 +70,7 @@ public class PlatformXmlListener extends DirectoryChangeListener {
* Parse the platform.xml file and return the list of sites.
*/
private List parseConfiguration() throws ProvisionException {
- Configuration cfg = ConfigurationParser.parse(root);
+ Configuration cfg = ConfigurationParser.parse(root, null);
return cfg == null ? new ArrayList(0) : cfg.getSites();
}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
index 396454d5c..8464bce28 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/EclipseTouchpoint.java
@@ -145,7 +145,7 @@ public class EclipseTouchpoint extends Touchpoint {
if (INSTALL_PHASE_ID.equals(phaseId) || UNINSTALL_PHASE_ID.equals(phaseId)) {
PlatformConfigurationWrapper configuration = (PlatformConfigurationWrapper) touchpointParameters.get(PARM_PLATFORM_CONFIGURATION);
try {
- configuration.save();
+ configuration.save(getOSGiInstallArea(manipulator));
} catch (ProvisionException pe) {
return createError("Error saving platform configuration.", pe);
}
@@ -733,19 +733,50 @@ public class EclipseTouchpoint extends Touchpoint {
public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) {
touchpointParameters.put(PARM_INSTALL_FOLDER, Util.getInstallFolder(profile));
- touchpointParameters.put(PARM_MANIPULATOR, new LazyManipulator(profile));
+ LazyManipulator manipulator = new LazyManipulator(profile);
+ touchpointParameters.put(PARM_MANIPULATOR, manipulator);
touchpointParameters.put(PARM_SOURCE_BUNDLES, new SourceManipulator(profile));
try {
URL configURL = getConfigurationURL(profile);
URL poolURL = Util.getBundlePoolLocation(profile);
- touchpointParameters.put(PARM_PLATFORM_CONFIGURATION, new PlatformConfigurationWrapper(configURL, poolURL));
+ touchpointParameters.put(PARM_PLATFORM_CONFIGURATION, new PlatformConfigurationWrapper(configURL, poolURL, getOSGiInstallArea(manipulator)));
} catch (CoreException ce) {
- touchpointParameters.put(PARM_PLATFORM_CONFIGURATION, new PlatformConfigurationWrapper(null, null));
+ touchpointParameters.put(PARM_PLATFORM_CONFIGURATION, new PlatformConfigurationWrapper(null, null, null));
return createError("Error constructing platform configuration url.", ce);
}
return null;
}
+ private static URL getOSGiInstallArea(Manipulator manipulator) {
+ final String OSGI = "org.eclipse.osgi"; //$NON-NLS-1$
+ BundleInfo[] bis = manipulator.getConfigData().getBundles();
+ String searchFor = "org.eclipse.equinox.launcher"; //$NON-NLS-1$
+ for (int i = 0; i < bis.length; i++) {
+ if (bis[i].getSymbolicName().equals(searchFor)) {
+ if (bis[i].getLocation() != null) {
+ try {
+ if (bis[i].getLocation().startsWith("file:")) //$NON-NLS-1$
+ return fromOSGiJarToOSGiInstallArea(bis[i].getLocation().substring(5)).toURL();
+ } catch (MalformedURLException e) {
+ //do nothing
+ }
+ }
+ if (searchFor.equals(OSGI))
+ return null;
+ searchFor = OSGI;
+ i = -1;
+ }
+ }
+ return null;
+ }
+
+ private static File fromOSGiJarToOSGiInstallArea(String path) {
+ IPath parentFolder = new Path(path).removeLastSegments(1);
+ if (parentFolder.lastSegment().equals("plugins")) //$NON-NLS-1$
+ return parentFolder.removeLastSegments(1).toFile();
+ return parentFolder.toFile();
+ }
+
IStatus installBundle(Map parameters) {
IProfile profile = (IProfile) parameters.get(PARM_PROFILE);
IInstallableUnit iu = (IInstallableUnit) parameters.get(PARM_IU);
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java
index 4f0fa876f..8f7e1c786 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/touchpoint/eclipse/PlatformConfigurationWrapper.java
@@ -30,10 +30,11 @@ public class PlatformConfigurationWrapper {
private Site poolSite = null;
private File configFile;
private URL poolURL;
+ private String osgiInstallArea;
private static String FEATURES = "features/"; //$NON-NLS-1$
- public PlatformConfigurationWrapper(URL configDir, URL featurePool) {
+ public PlatformConfigurationWrapper(URL configDir, URL featurePool, URL osgiInstallArea) {
this.configuration = null;
this.configFile = new File(configDir.getFile(), "/org.eclipse.update/platform.xml"); //$NON-NLS-1$
this.poolURL = featurePool;
@@ -45,7 +46,7 @@ public class PlatformConfigurationWrapper {
try {
if (configFile.exists()) {
- configuration = Configuration.load(configFile);
+ configuration = Configuration.load(configFile, osgiInstallArea);
} else {
configuration = new Configuration();
}
@@ -104,10 +105,10 @@ public class PlatformConfigurationWrapper {
/*
* @see org.eclipse.update.configurator.IPlatformConfiguration#save()
*/
- public void save() throws ProvisionException {
+ public void save(URL newOsgiInstallArea) throws ProvisionException {
if (configuration != null) {
configFile.getParentFile().mkdirs();
- configuration.save(configFile);
+ configuration.save(configFile, newOsgiInstallArea);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Configuration.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Configuration.java
index bb455a9a5..dd7ccf468 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Configuration.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Configuration.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.internal.p2.update;
import java.io.File;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
@@ -26,16 +27,16 @@ public class Configuration {
String version;
String shared_ur;
- public static Configuration load(File location) throws ProvisionException {
- return ConfigurationParser.parse(location);
+ public static Configuration load(File location, String osgiInstallArea) throws ProvisionException {
+ return ConfigurationParser.parse(location, osgiInstallArea);
}
public Configuration() {
super();
}
- public void save(File location) throws ProvisionException {
- ConfigurationWriter.save(this, location);
+ public void save(File location, URL osgiInstallArea) throws ProvisionException {
+ ConfigurationWriter.save(this, location, osgiInstallArea);
}
public String getSharedUR() {
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationParser.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationParser.java
index e775715ba..0a05889b1 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationParser.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationParser.java
@@ -23,13 +23,18 @@ import org.xml.sax.SAXException;
* @since 1.0
*/
public class ConfigurationParser implements ConfigurationConstants {
+ private String osgiInstallArea;
/*
* Parse the given file handle which points to a platform.xml file and a configuration object.
* Returns null if the file doesn't exist.
*/
- public static Configuration parse(File file) throws ProvisionException {
- return new ConfigurationParser().internalParse(file);
+ public static Configuration parse(File file, String osgiInstallArea) throws ProvisionException {
+ return new ConfigurationParser(osgiInstallArea).internalParse(file);
+ }
+
+ private ConfigurationParser(String osgiInstallArea) {
+ this.osgiInstallArea = osgiInstallArea;
}
/*
@@ -83,8 +88,12 @@ public class ConfigurationParser implements ConfigurationConstants {
if (updateable != null)
result.setUpdateable(Boolean.valueOf(updateable).booleanValue());
String url = getAttribute(node, ATTRIBUTE_URL);
- if (url != null)
- result.setUrl(url);
+ if (url != null) {
+ if (osgiInstallArea == null)
+ result.setUrl(url);
+ else
+ result.setUrl(Utils.makeAbsolute(url, osgiInstallArea));
+ }
String linkFile = getAttribute(node, ATTRIBUTE_LINKFILE);
if (linkFile != null)
result.setLinkFile(linkFile);
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationWriter.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationWriter.java
index 09421d212..f986e5304 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationWriter.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/ConfigurationWriter.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.internal.p2.update;
import java.io.*;
+import java.net.URL;
import java.util.*;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
@@ -22,7 +23,7 @@ public class ConfigurationWriter implements ConfigurationConstants {
/*
* Save the given configuration to the specified location.
*/
- public static void save(Configuration configuration, File location) throws ProvisionException {
+ public static void save(Configuration configuration, File location, URL osgiInstallArea) throws ProvisionException {
XMLWriter writer = null;
try {
OutputStream output = new BufferedOutputStream(new FileOutputStream(location));
@@ -47,7 +48,7 @@ public class ConfigurationWriter implements ConfigurationConstants {
for (Iterator iter = configuration.getSites().iterator(); iter.hasNext();) {
Site site = (Site) iter.next();
- write(writer, site);
+ write(writer, site, osgiInstallArea);
}
writer.endTag(ELEMENT_CONFIG);
@@ -66,7 +67,7 @@ public class ConfigurationWriter implements ConfigurationConstants {
/*
* Write out the given site.
*/
- private static void write(XMLWriter writer, Site site) {
+ private static void write(XMLWriter writer, Site site, URL osgiInstallArea) {
Map args = new HashMap();
String value = site.getLinkFile();
@@ -78,8 +79,12 @@ public class ConfigurationWriter implements ConfigurationConstants {
args.put(ATTRIBUTE_POLICY, value);
value = site.getUrl();
- if (value != null)
- args.put(ATTRIBUTE_URL, value);
+ if (value != null) {
+ if (osgiInstallArea == null)
+ args.put(ATTRIBUTE_URL, value);
+ else
+ args.put(ATTRIBUTE_URL, Utils.makeRelative(value, osgiInstallArea));
+ }
value = toString(site.getList());
if (value != null)
diff --git a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Utils.java b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Utils.java
index 32c3af1e1..e58f988a2 100644
--- a/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Utils.java
+++ b/bundles/org.eclipse.equinox.p2.touchpoint.eclipse/src/org/eclipse/equinox/internal/p2/update/Utils.java
@@ -13,6 +13,8 @@ package org.eclipse.equinox.internal.p2.update;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.*;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
/**
*
@@ -92,4 +94,103 @@ public class Utils {
return true;
}
+ private static final String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
+
+ public static String makeRelative(String urlString, URL rootURL) {
+ // we only traffic in file: URLs
+ int index = urlString.indexOf(FILE_PROTOCOL);
+ if (index == -1)
+ return urlString;
+ index = index + 5;
+
+ // ensure we have an absolute path to start with
+ boolean done = false;
+ URL url = null;
+ String file = urlString;
+ while (!done) {
+ try {
+ url = new URL(file);
+ file = url.getFile();
+ } catch (java.net.MalformedURLException e) {
+ done = true;
+ }
+ }
+ if (url == null || !new File(url.getFile()).isAbsolute())
+ return urlString;
+
+ String rootString = rootURL.toExternalForm();
+ return urlString.substring(0, index) + makeRelative(urlString.substring(index), rootString.substring(rootString.indexOf(FILE_PROTOCOL) + 5));
+ }
+
+ public static String makeRelative(String original, String rootPath) {
+ IPath path = new Path(original);
+ // ensure we have an absolute path to start with
+ if (!path.isAbsolute())
+ return original;
+
+ //Returns the original string if no relativization has been done
+ String result = makeRelative(path, new Path(rootPath));
+ return path.toOSString().equals(result) ? original : result;
+ }
+
+ /*
+ * Make the given path relative to the specified root, if applicable. If not, then
+ * return the path as-is.
+ *
+ * Method similar to one from SimpleConfigurationManipulatorImpl.
+ */
+ private static String makeRelative(IPath toRel, IPath base) {
+ int i = base.matchingFirstSegments(toRel);
+ if (i == 0) {
+ return toRel.toOSString();
+ }
+ String result = "";
+ for (int j = 0; j < (base.segmentCount() - i); j++) {
+ result += ".." + Path.SEPARATOR;
+ }
+ if (i == toRel.segmentCount())
+ return ".";
+ result += toRel.setDevice(null).removeFirstSegments(i).toOSString();
+ return result;
+ }
+
+ /*
+ * Make the given path absolute to the specified root, if applicable. If not, then
+ * return the path as-is.
+ *
+ * Method similar to one from SimpleConfigurationManipulatorImpl.
+ */
+ public static String makeAbsolute(String original, String rootPath) {
+ IPath path = new Path(original);
+ // ensure we have a relative path to start with
+ if (path.isAbsolute())
+ return original;
+ IPath root = new Path(rootPath);
+ return root.addTrailingSeparator().append(original.replace(':', '}')).toOSString().replace('}', ':');
+ }
+
+ public static String makeAbsolute(String urlString, URL rootURL) {
+ // we only traffic in file: URLs
+ int index = urlString.indexOf(FILE_PROTOCOL);
+ if (index == -1)
+ return urlString;
+ index = index + 5;
+
+ // ensure we have a relative path to start with
+ boolean done = false;
+ URL url = null;
+ String file = urlString;
+ while (!done) {
+ try {
+ url = new URL(file);
+ file = url.getFile();
+ } catch (java.net.MalformedURLException e) {
+ done = true;
+ }
+ }
+ if (url == null || new File(url.getFile()).isAbsolute())
+ return urlString;
+
+ return urlString.substring(0, index - 5) + makeAbsolute(urlString.substring(index), rootURL.toExternalForm());
+ }
}

Back to the top