Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2010-01-08 22:49:57 +0000
committerThomas Watson2010-01-08 22:49:57 +0000
commitf683b85bb9dfc02038965eeb637c43747fb1ab98 (patch)
tree88dfc4056d8ac178be0ad67fdde2b24b647e6d4c /bundles
parentaceb073cec7aae53502521a6e1b79ab5b6de64d9 (diff)
downloadrt.equinox.framework-f683b85bb9dfc02038965eeb637c43747fb1ab98.tar.gz
rt.equinox.framework-f683b85bb9dfc02038965eeb637c43747fb1ab98.tar.xz
rt.equinox.framework-f683b85bb9dfc02038965eeb637c43747fb1ab98.zip
Bug 177783 - need a way to get state locations for bundlesv20100108
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java55
-rw-r--r--bundles/org.eclipse.osgi/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/LocationManager.java31
-rw-r--r--bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/core/runtime/internal/adaptor/BasicLocation.java21
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/datalocation/Location.java25
6 files changed, 115 insertions, 21 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
index 6cc19fa79..5012f19ed 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -175,6 +175,59 @@ public class BasicLocationTests extends CoreTest {
}
}
+ private static final String INSTANCE_DATA_AREA_PREFIX = ".metadata/.plugins/"; //$NON-NLS-1$
+
+ public void testLocationDataArea01() {
+ Location instance = LocationManager.getInstanceLocation();
+ doAllTestLocationDataArea(instance, INSTANCE_DATA_AREA_PREFIX);
+
+ Location configuration = LocationManager.getConfigurationLocation();
+ doAllTestLocationDataArea(configuration, "");
+ }
+
+ private void doAllTestLocationDataArea(Location location, String dataAreaPrefix) {
+ doTestLocateDataArea(location, dataAreaPrefix, getName());
+ doTestLocateDataArea(location, dataAreaPrefix, "");
+ doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/paths");
+ doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/../paths");
+ doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
+
+ File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/" + getName());
+ Location createdLocation = location.createLocation(null, null, false);
+ try {
+ createdLocation.set(testLocationFile.toURL(), false);
+ } catch (Exception e) {
+ fail("Failed to set location", e);
+ }
+ doTestLocateDataArea(createdLocation, dataAreaPrefix, getName());
+ doTestLocateDataArea(createdLocation, dataAreaPrefix, "");
+ doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/paths");
+ doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/../paths");
+ doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
+
+ createdLocation = location.createLocation(null, null, false);
+ try {
+ createdLocation.getDataArea("shouldFail");
+ fail("expected failure when location is not set");
+ } catch (IOException e) {
+ // expected;
+ }
+ }
+
+ private void doTestLocateDataArea(Location location, String dataAreaPrefix, String namespace) {
+ assertTrue("Location is not set", location.isSet());
+ URL dataArea = null;
+ try {
+ dataArea = location.getDataArea(namespace);
+ } catch (IOException e) {
+ fail("Failed to get data area.", e);
+ }
+ assertNotNull("Data area is null.", dataArea);
+
+ namespace = namespace.replace('\\', '/');
+ assertTrue("Data area is not the expected value: " + dataArea.toExternalForm(), dataArea.toExternalForm().endsWith(dataAreaPrefix + namespace));
+ }
+
public void testSetLocationWithEmptyLockFile() {
Location configLocation = LocationManager.getConfigurationLocation();
File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testSetLocationWithEmptyLockFile"); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
index a651b5909..887526b03 100644
--- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
@@ -5,7 +5,7 @@ Export-Package: org.eclipse.osgi.event;version="1.0",
org.eclipse.osgi.framework.eventmgr;version="1.2",
org.eclipse.osgi.framework.log;version="1.0",
org.eclipse.osgi.launch; version="1.0",
- org.eclipse.osgi.service.datalocation;version="1.2",
+ org.eclipse.osgi.service.datalocation;version="1.3",
org.eclipse.osgi.service.debug;version="1.1",
org.eclipse.osgi.service.environment;version="1.3",
org.eclipse.osgi.service.localization;version="1.1",
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/LocationManager.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/LocationManager.java
index bfcb15802..354863e2c 100644
--- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/LocationManager.java
+++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/LocationManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -73,6 +73,8 @@ public class LocationManager {
private static final String USER_HOME = "@user.home"; //$NON-NLS-1$
private static final String USER_DIR = "@user.dir"; //$NON-NLS-1$
+ private static final String INSTANCE_DATA_AREA_PREFIX = ".metadata/.plugins/"; //$NON-NLS-1$
+
/**
* Builds a URL with the given specification
* @param spec the URL specification
@@ -103,34 +105,35 @@ public class LocationManager {
public static void initializeLocations() {
// do install location initialization first since others may depend on it
// assumes that the property is already set
- installLocation = buildLocation(PROP_INSTALL_AREA, null, "", true, false); //$NON-NLS-1$
+ installLocation = buildLocation(PROP_INSTALL_AREA, null, "", true, false, null); //$NON-NLS-1$
- Location temp = buildLocation(PROP_USER_AREA_DEFAULT, null, "", false, false); //$NON-NLS-1$
+ // TODO not sure what the data area prefix should be here for the user area
+ Location temp = buildLocation(PROP_USER_AREA_DEFAULT, null, "", false, false, null); //$NON-NLS-1$
URL defaultLocation = temp == null ? null : temp.getURL();
if (defaultLocation == null)
defaultLocation = buildURL(new File(FrameworkProperties.getProperty(PROP_USER_HOME), "user").getAbsolutePath(), true); //$NON-NLS-1$
- userLocation = buildLocation(PROP_USER_AREA, defaultLocation, "", false, false); //$NON-NLS-1$
+ userLocation = buildLocation(PROP_USER_AREA, defaultLocation, "", false, false, null); //$NON-NLS-1$
- temp = buildLocation(PROP_INSTANCE_AREA_DEFAULT, null, "", false, false); //$NON-NLS-1$
+ temp = buildLocation(PROP_INSTANCE_AREA_DEFAULT, null, "", false, false, INSTANCE_DATA_AREA_PREFIX); //$NON-NLS-1$
defaultLocation = temp == null ? null : temp.getURL();
if (defaultLocation == null)
defaultLocation = buildURL(new File(FrameworkProperties.getProperty(PROP_USER_DIR), "workspace").getAbsolutePath(), true); //$NON-NLS-1$
- instanceLocation = buildLocation(PROP_INSTANCE_AREA, defaultLocation, "", false, false); //$NON-NLS-1$
+ instanceLocation = buildLocation(PROP_INSTANCE_AREA, defaultLocation, "", false, false, INSTANCE_DATA_AREA_PREFIX); //$NON-NLS-1$
mungeConfigurationLocation();
// compute a default but it is very unlikely to be used since main will have computed everything
- temp = buildLocation(PROP_CONFIG_AREA_DEFAULT, null, "", false, false); //$NON-NLS-1$
+ temp = buildLocation(PROP_CONFIG_AREA_DEFAULT, null, "", false, false, null); //$NON-NLS-1$
defaultLocation = temp == null ? null : temp.getURL();
if (defaultLocation == null && FrameworkProperties.getProperty(PROP_CONFIG_AREA) == null)
// only compute the default if the configuration area property is not set
defaultLocation = buildURL(computeDefaultConfigurationLocation(), true);
- configurationLocation = buildLocation(PROP_CONFIG_AREA, defaultLocation, "", false, false); //$NON-NLS-1$
+ configurationLocation = buildLocation(PROP_CONFIG_AREA, defaultLocation, "", false, false, null); //$NON-NLS-1$
// get the parent location based on the system property. This will have been set on the
// way in either by the caller/user or by main. There will be no parent location if we are not
// cascaded.
URL parentLocation = computeSharedConfigurationLocation();
if (parentLocation != null && !parentLocation.equals(configurationLocation.getURL())) {
- Location parent = new BasicLocation(null, parentLocation, true);
+ Location parent = new BasicLocation(null, parentLocation, true, null);
((BasicLocation) configurationLocation).setParent(parent);
}
initializeDerivedConfigurationLocations();
@@ -144,7 +147,7 @@ public class LocationManager {
// if eclipse.home.location is not set then default to osgi.install.area
if (FrameworkProperties.getProperty(PROP_HOME_LOCATION_AREA) == null && FrameworkProperties.getProperty(PROP_INSTALL_AREA) != null)
FrameworkProperties.setProperty(PROP_HOME_LOCATION_AREA, FrameworkProperties.getProperty(PROP_INSTALL_AREA));
- eclipseHomeLocation = buildLocation(PROP_HOME_LOCATION_AREA, null, "", true, true); //$NON-NLS-1$
+ eclipseHomeLocation = buildLocation(PROP_HOME_LOCATION_AREA, null, "", true, true, null); //$NON-NLS-1$
}
private static String getEclipseHomeLocation(String launcher) {
@@ -174,7 +177,7 @@ public class LocationManager {
return launcherParent == null ? null : new File(launcherParent);
}
- private static Location buildLocation(String property, URL defaultLocation, String userDefaultAppendage, boolean readOnlyDefault, boolean computeReadOnly) {
+ private static Location buildLocation(String property, URL defaultLocation, String userDefaultAppendage, boolean readOnlyDefault, boolean computeReadOnly, String dataAreaPrefix) {
String location = FrameworkProperties.clearProperty(property);
// the user/product may specify a non-default readOnly setting
String userReadOnlySetting = FrameworkProperties.getProperty(property + READ_ONLY_AREA_SUFFIX);
@@ -182,12 +185,12 @@ public class LocationManager {
// if the instance location is not set, predict where the workspace will be and
// put the instance area inside the workspace meta area.
if (location == null)
- return new BasicLocation(property, defaultLocation, userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(defaultLocation));
+ return new BasicLocation(property, defaultLocation, userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(defaultLocation), dataAreaPrefix);
String trimmedLocation = location.trim();
if (trimmedLocation.equalsIgnoreCase(NONE))
return null;
if (trimmedLocation.equalsIgnoreCase(NO_DEFAULT))
- return new BasicLocation(property, null, readOnly);
+ return new BasicLocation(property, null, readOnly, dataAreaPrefix);
if (trimmedLocation.startsWith(USER_HOME)) {
String base = substituteVar(location, USER_HOME, PROP_USER_HOME);
location = new File(base, userDefaultAppendage).getAbsolutePath();
@@ -198,7 +201,7 @@ public class LocationManager {
URL url = buildURL(location, true);
BasicLocation result = null;
if (url != null) {
- result = new BasicLocation(property, null, userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(url));
+ result = new BasicLocation(property, null, userReadOnlySetting != null || !computeReadOnly ? readOnly : !canWrite(url), dataAreaPrefix);
result.setURL(url, false);
}
return result;
diff --git a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF
index fab062d9e..d8ff0dee5 100644
--- a/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi/supplement/META-INF/MANIFEST.MF
@@ -6,7 +6,7 @@ Bundle-Version: 1.3.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.osgi.framework.log;version="1.0",
- org.eclipse.osgi.service.datalocation;version="1.2",
+ org.eclipse.osgi.service.datalocation;version="1.3",
org.eclipse.osgi.service.debug;version="1.1",
org.eclipse.osgi.service.environment;version="1.3",
org.eclipse.osgi.service.localization;version="1.1",
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/core/runtime/internal/adaptor/BasicLocation.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/core/runtime/internal/adaptor/BasicLocation.java
index 7dba75f12..d73ef479a 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/core/runtime/internal/adaptor/BasicLocation.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/core/runtime/internal/adaptor/BasicLocation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -43,6 +43,7 @@ public class BasicLocation implements Location {
private Location parent;
final private URL defaultValue;
final private String property;
+ final private String dataAreaPrefix;
// locking related fields
private File lockFile;
@@ -84,11 +85,12 @@ public class BasicLocation implements Location {
}
- public BasicLocation(String property, URL defaultValue, boolean isReadOnly) {
+ public BasicLocation(String property, URL defaultValue, boolean isReadOnly, String dataAreaPrefix) {
super();
this.property = property;
this.defaultValue = defaultValue;
this.isReadOnly = isReadOnly;
+ this.dataAreaPrefix = dataAreaPrefix == null ? "" : dataAreaPrefix; //$NON-NLS-1$
}
public boolean allowsDefault() {
@@ -238,8 +240,21 @@ public class BasicLocation implements Location {
}
public Location createLocation(Location parentLocation, URL defaultLocation, boolean readonly) {
- BasicLocation result = new BasicLocation(null, defaultLocation, readonly);
+ BasicLocation result = new BasicLocation(null, defaultLocation, readonly, dataAreaPrefix);
result.setParent(parentLocation);
return result;
}
+
+ public URL getDataArea(String filename) throws IOException {
+ URL base = getURL();
+ if (base == null)
+ throw new IOException(EclipseAdaptorMsg.location_notSet);
+ String prefix = base.toExternalForm();
+ if (prefix.length() > 0 && prefix.charAt(prefix.length() - 1) != '/')
+ prefix += '/';
+ filename = filename.replace('\\', '/');
+ if (filename.length() > 0 && filename.charAt(0) == '/')
+ filename.substring(1);
+ return new URL(prefix + dataAreaPrefix + filename);
+ }
}
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/datalocation/Location.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/datalocation/Location.java
index 29e52360f..8ae36588f 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/datalocation/Location.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/service/datalocation/Location.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 IBM Corporation and others.
+ * Copyright (c) 2004, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -199,4 +199,27 @@ public interface Location {
* @since 3.4
*/
public Location createLocation(Location parent, URL defaultValue, boolean readonly);
+
+ /**
+ * Returns a URL to the specified path within this location. The path
+ * of the returned URL may not exist yet. It is the responsibility of the
+ * client to create the content of the data area returned if it does not exist.
+ * <p>
+ * This method can be used to obtain a private area within the given location.
+ * For example use the symbolic name of a bundle to obtain a data area specific
+ * to that bundle.
+ * </p>
+ * <p>
+ * Clients should check if the location is read only before writing anything
+ * to the returned data area. An <code>IOException</code> will be thrown if
+ * this method is called and the location URL has not been set and there is
+ * no default value for this location.
+ * </p>
+ *
+ * @param path the name of the path to get from this location
+ * @return the URL to the data area with the specified path.
+ * @throws IOException if the location URL is not already set
+ * @since 3.6
+ */
+ public URL getDataArea(String path) throws IOException;
}

Back to the top