### Eclipse Workspace Patch 1.0 #P org.eclipse.core.resources Index: src/org/eclipse/core/internal/resources/ResourceInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/ResourceInfo.java,v retrieving revision 1.25 diff -u -r1.25 ResourceInfo.java --- src/org/eclipse/core/internal/resources/ResourceInfo.java 23 Jan 2007 22:45:37 -0000 1.25 +++ src/org/eclipse/core/internal/resources/ResourceInfo.java 26 Mar 2008 14:50:40 -0000 @@ -190,6 +190,20 @@ } /** + * Returns a copy of the map of this resource session properties. + * An empty map is returned if there are none. + */ + public Map getSessionProperties() { + // thread safety: (Concurrency001) + ObjectMap temp = sessionProperties; + if (temp == null) + temp = new ObjectMap(5); + else + temp = (ObjectMap) sessionProperties.clone(); + return temp; + } + + /** * Returns the value of the identified session property */ public Object getSessionProperty(QualifiedName name) { Index: src/org/eclipse/core/internal/resources/Resource.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Resource.java,v retrieving revision 1.158 diff -u -r1.158 Resource.java --- src/org/eclipse/core/internal/resources/Resource.java 13 Mar 2008 20:14:40 -0000 1.158 +++ src/org/eclipse/core/internal/resources/Resource.java 26 Mar 2008 14:50:39 -0000 @@ -192,6 +192,14 @@ checkExists(flags, true); } + private ResourceInfo checkAccessibleAndLocal(int depth) throws CoreException { + ResourceInfo info = getResourceInfo(false, false); + int flags = getFlags(info); + checkAccessible(flags); + checkLocal(flags, depth); + return info; + } + /** * This method reports errors in two different ways. It can throw a * CoreException or return a status. CoreExceptions are used according to the @@ -218,11 +226,9 @@ } checkValidPath(destination, destinationType, false); - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_INFINITE); - + ResourceInfo info; + checkAccessibleAndLocal(DEPTH_INFINITE); + Resource dest = workspace.newResource(destination, destinationType); dest.checkDoesNotExist(); @@ -350,10 +356,8 @@ } checkValidPath(destination, destinationType, false); - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_INFINITE); + ResourceInfo info; + checkAccessibleAndLocal(DEPTH_INFINITE); Resource dest = workspace.newResource(destination, destinationType); @@ -1032,14 +1036,19 @@ * @see IResource#getPersistentProperty(QualifiedName) */ public String getPersistentProperty(QualifiedName key) throws CoreException { - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + checkAccessibleAndLocal(DEPTH_ZERO); return getPropertyManager().getProperty(this, key); } /* (non-Javadoc) + * @see IResource#getPersistentProperties() + */ + public Map getPersistentProperties() throws CoreException { + checkAccessibleAndLocal(DEPTH_ZERO); + return getPropertyManager().getProperties(this); + } + + /* (non-Javadoc) * @see IResource#getProject() */ public IProject getProject() { @@ -1097,13 +1106,18 @@ * @see IResource#getSessionProperty(QualifiedName) */ public Object getSessionProperty(QualifiedName key) throws CoreException { - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); return info.getSessionProperty(key); } + /* (non-Javadoc) + * @see IResource#getSessionProperties() + */ + public Map getSessionProperties() throws CoreException { + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); + return info.getSessionProperties(); + } + public IFileStore getStore() { return getLocalManager().getStore(this); } @@ -1497,10 +1511,7 @@ throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$ // fetch the info but don't bother making it mutable even though we are going // to modify it. It really doesn't matter as the change we are doing does not show up in deltas. - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); info.setModificationStamp(value); } @@ -1571,10 +1582,7 @@ throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$ // fetch the info but don't bother making it mutable even though we are going // to modify it. It really doesn't matter as the change we are doing does not show up in deltas. - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); return getLocalManager().setLocalTimeStamp(this, info, value); } @@ -1582,10 +1590,7 @@ * @see IResource#setPersistentProperty(QualifiedName, String) */ public void setPersistentProperty(QualifiedName key, String value) throws CoreException { - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + checkAccessibleAndLocal(DEPTH_ZERO); getPropertyManager().setProperty(this, key, value); } @@ -1609,10 +1614,7 @@ * @see org.eclipse.core.resources.IResource#setResourceAttributes(org.eclipse.core.resources.ResourceAttributes) */ public void setResourceAttributes(ResourceAttributes attributes) throws CoreException { - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + checkAccessibleAndLocal(DEPTH_ZERO); getLocalManager().setResourceAttributes(this, attributes); } @@ -1623,10 +1625,7 @@ // fetch the info but don't bother making it mutable even though we are going // to modify it. We don't know whether or not the tree is open and it really doesn't // matter as the change we are doing does not show up in deltas. - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); info.setSessionProperty(key, value); } @@ -1676,10 +1675,7 @@ final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this); try { workspace.prepareOperation(rule, monitor); - ResourceInfo info = getResourceInfo(false, false); - int flags = getFlags(info); - checkAccessible(flags); - checkLocal(flags, DEPTH_ZERO); + ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO); workspace.beginOperation(true); // fake a change by incrementing the content ID Index: src/org/eclipse/core/resources/IResource.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IResource.java,v retrieving revision 1.97 diff -u -r1.97 IResource.java --- src/org/eclipse/core/resources/IResource.java 6 Dec 2007 20:38:15 -0000 1.97 +++ src/org/eclipse/core/resources/IResource.java 26 Mar 2008 14:50:41 -0000 @@ -12,6 +12,7 @@ package org.eclipse.core.resources; import java.net.URI; +import java.util.Map; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.ISchedulingRule; @@ -1362,6 +1363,23 @@ public IContainer getParent(); /** + * Returns a copy of the map of this resource persistent properties. + * Returns an empty map if there are none. + * + * @return the map containing the persistent properties where the key is + * the qualified name of the property and the value is the string value of the property. + * @exception CoreException if this method fails. Reasons include: + *
null
if this resource has no such property.
*
@@ -1502,6 +1520,23 @@
public ResourceAttributes getResourceAttributes();
/**
+ * Returns a copy of the map of this resource session properties.
+ * Returns an empty map if there are none.
+ *
+ * @return the map containing the session properties where the key is
+ * the qualified name of the property and the value is the value of the property.
+ * @exception CoreException if this method fails. Reasons include:
+ * null
if this resource has no such property.
*
#P org.eclipse.core.tests.resources
Index: src/org/eclipse/core/tests/resources/IResourceTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IResourceTest.java,v
retrieving revision 1.43
diff -u -r1.43 IResourceTest.java
--- src/org/eclipse/core/tests/resources/IResourceTest.java 6 Dec 2007 20:38:14 -0000 1.43
+++ src/org/eclipse/core/tests/resources/IResourceTest.java 26 Mar 2008 14:50:46 -0000
@@ -1698,6 +1698,84 @@
project.open(null);
assertEquals(stamp, file.getModificationStamp());
}
+
+ /**
+ * Tests IResource#getPersistentProperties and IResource#getSessionProperties
+ */
+ public void testProperties() throws CoreException {
+ QualifiedName qn1 = new QualifiedName("package", "property1");
+ QualifiedName qn2 = new QualifiedName("package", "property2");
+
+ IProject project = getWorkspace().getRoot().getProject("P1");
+ IProject project2 = getWorkspace().getRoot().getProject("P2");
+ project.create(null);
+ project.open(null);
+ project.setPersistentProperty(qn1, "value1");
+ project.setPersistentProperty(qn2, "value2");
+ project.setSessionProperty(qn1, "value1");
+ project.setSessionProperty(qn2, "value2");
+
+ assertEquals("value1", project.getPersistentProperty(qn1));
+ assertEquals("value2", project.getPersistentProperty(qn2));
+ assertEquals("value1", project.getSessionProperty(qn1));
+ assertEquals("value2", project.getSessionProperty(qn2));
+
+ Map props = project.getPersistentProperties();
+ assertEquals(2, props.size());
+ assertEquals("value1",props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ props = project.getSessionProperties();
+ // Don't check the size, because other plugins (like team) may add
+ // a property depending on if they are present or not
+ assertEquals("value1",props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ project.setPersistentProperty(qn1, null);
+ project.setSessionProperty(qn1, null);
+
+ props = project.getPersistentProperties();
+ assertEquals(1, props.size());
+ assertNull(props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ props = project.getSessionProperties();
+ assertNull(props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ // Copy
+ project.copy(project2.getFullPath(), true, null);
+
+ // Persistent properties go with the copy
+ props = project2.getPersistentProperties();
+ assertEquals(1, props.size());
+ assertNull(props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ // Session properties don't
+ props = project2.getSessionProperties();
+ // Don't check size (see above)
+ assertNull(props.get(qn1));
+ assertNull(props.get(qn2));
+
+
+ // Test persistence
+ project.close(null);
+ project.open(null);
+
+ // Make sure they are really persistent
+ props = project.getPersistentProperties();
+ assertEquals(1, props.size());
+ assertNull(props.get(qn1));
+ assertEquals("value2",props.get(qn2));
+
+ // Make sure they don't persist
+ props = project.getSessionProperties();
+ // Don't check size (see above)
+ assertNull(props.get(qn1));
+ assertNull(props.get(qn2));
+
+ }
/**
* Tests IResource.isReadOnly and setReadOnly