View | Details | Raw Unified | Return to bug 215299 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/resources/ResourceInfo.java (+14 lines)
Lines 190-195 Link Here
190
	}
190
	}
191
191
192
	/** 
192
	/** 
193
	 * Returns a copy of the map of this resource session properties.
194
	 * An empty map is returned if there are none.
195
	 */
196
	public Map getSessionProperties() {
197
		// thread safety: (Concurrency001)
198
		ObjectMap temp = sessionProperties;
199
		if (temp == null)
200
			temp = new ObjectMap(5);
201
		else
202
			temp = (ObjectMap) sessionProperties.clone();
203
		return temp;
204
	}
205
	
206
	/** 
193
	 * Returns the value of the identified session property
207
	 * Returns the value of the identified session property
194
	 */
208
	 */
195
	public Object getSessionProperty(QualifiedName name) {
209
	public Object getSessionProperty(QualifiedName name) {
(-)src/org/eclipse/core/internal/resources/Resource.java (-41 / +37 lines)
Lines 192-197 Link Here
192
		checkExists(flags, true);
192
		checkExists(flags, true);
193
	}
193
	}
194
194
195
	private ResourceInfo checkAccessibleAndLocal(int depth) throws CoreException {
196
		ResourceInfo info = getResourceInfo(false, false);
197
		int flags = getFlags(info);
198
		checkAccessible(flags);
199
		checkLocal(flags, depth);
200
		return info;
201
	}
202
	
195
	/**
203
	/**
196
	 * This method reports errors in two different ways. It can throw a
204
	 * This method reports errors in two different ways. It can throw a
197
	 * CoreException or return a status. CoreExceptions are used according to the
205
	 * CoreException or return a status. CoreExceptions are used according to the
Lines 218-228 Link Here
218
		}
226
		}
219
		checkValidPath(destination, destinationType, false);
227
		checkValidPath(destination, destinationType, false);
220
228
221
		ResourceInfo info = getResourceInfo(false, false);
229
		ResourceInfo info;
222
		int flags = getFlags(info);
230
		checkAccessibleAndLocal(DEPTH_INFINITE);
223
		checkAccessible(flags);
231
		
224
		checkLocal(flags, DEPTH_INFINITE);
225
226
		Resource dest = workspace.newResource(destination, destinationType);
232
		Resource dest = workspace.newResource(destination, destinationType);
227
		dest.checkDoesNotExist();
233
		dest.checkDoesNotExist();
228
234
Lines 350-359 Link Here
350
		}
356
		}
351
		checkValidPath(destination, destinationType, false);
357
		checkValidPath(destination, destinationType, false);
352
358
353
		ResourceInfo info = getResourceInfo(false, false);
359
		ResourceInfo info;
354
		int flags = getFlags(info);
360
		checkAccessibleAndLocal(DEPTH_INFINITE);
355
		checkAccessible(flags);
356
		checkLocal(flags, DEPTH_INFINITE);
357
361
358
		Resource dest = workspace.newResource(destination, destinationType);
362
		Resource dest = workspace.newResource(destination, destinationType);
359
363
Lines 1032-1045 Link Here
1032
	 * @see IResource#getPersistentProperty(QualifiedName)
1036
	 * @see IResource#getPersistentProperty(QualifiedName)
1033
	 */
1037
	 */
1034
	public String getPersistentProperty(QualifiedName key) throws CoreException {
1038
	public String getPersistentProperty(QualifiedName key) throws CoreException {
1035
		ResourceInfo info = getResourceInfo(false, false);
1039
		checkAccessibleAndLocal(DEPTH_ZERO);
1036
		int flags = getFlags(info);
1037
		checkAccessible(flags);
1038
		checkLocal(flags, DEPTH_ZERO);
1039
		return getPropertyManager().getProperty(this, key);
1040
		return getPropertyManager().getProperty(this, key);
1040
	}
1041
	}
1041
1042
1042
	/* (non-Javadoc)
1043
	/* (non-Javadoc)
1044
	 * @see IResource#getPersistentProperties()
1045
	 */
1046
	public Map getPersistentProperties() throws CoreException {
1047
		checkAccessibleAndLocal(DEPTH_ZERO);
1048
		return getPropertyManager().getProperties(this);
1049
	}
1050
1051
	/* (non-Javadoc)
1043
	 * @see IResource#getProject()
1052
	 * @see IResource#getProject()
1044
	 */
1053
	 */
1045
	public IProject getProject() {
1054
	public IProject getProject() {
Lines 1097-1109 Link Here
1097
	 * @see IResource#getSessionProperty(QualifiedName)
1106
	 * @see IResource#getSessionProperty(QualifiedName)
1098
	 */
1107
	 */
1099
	public Object getSessionProperty(QualifiedName key) throws CoreException {
1108
	public Object getSessionProperty(QualifiedName key) throws CoreException {
1100
		ResourceInfo info = getResourceInfo(false, false);
1109
		ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1101
		int flags = getFlags(info);
1102
		checkAccessible(flags);
1103
		checkLocal(flags, DEPTH_ZERO);
1104
		return info.getSessionProperty(key);
1110
		return info.getSessionProperty(key);
1105
	}
1111
	}
1106
1112
1113
	/* (non-Javadoc)
1114
	 * @see IResource#getSessionProperties()
1115
	 */
1116
	public Map getSessionProperties() throws CoreException {
1117
		ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1118
		return info.getSessionProperties();
1119
	}
1120
1107
	public IFileStore getStore() {
1121
	public IFileStore getStore() {
1108
		return getLocalManager().getStore(this);
1122
		return getLocalManager().getStore(this);
1109
	}
1123
	}
Lines 1497-1506 Link Here
1497
			throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$
1511
			throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$
1498
		// fetch the info but don't bother making it mutable even though we are going
1512
		// fetch the info but don't bother making it mutable even though we are going
1499
		// to modify it. It really doesn't matter as the change we are doing does not show up in deltas.
1513
		// to modify it. It really doesn't matter as the change we are doing does not show up in deltas.
1500
		ResourceInfo info = getResourceInfo(false, false);
1514
		ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1501
		int flags = getFlags(info);
1502
		checkAccessible(flags);
1503
		checkLocal(flags, DEPTH_ZERO);
1504
		info.setModificationStamp(value);
1515
		info.setModificationStamp(value);
1505
	}
1516
	}
1506
1517
Lines 1571-1580 Link Here
1571
			throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$
1582
			throw new IllegalArgumentException("Illegal value: " + value); //$NON-NLS-1$
1572
		// fetch the info but don't bother making it mutable even though we are going
1583
		// fetch the info but don't bother making it mutable even though we are going
1573
		// to modify it. It really doesn't matter as the change we are doing does not show up in deltas.
1584
		// to modify it. It really doesn't matter as the change we are doing does not show up in deltas.
1574
		ResourceInfo info = getResourceInfo(false, false);
1585
		ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1575
		int flags = getFlags(info);
1576
		checkAccessible(flags);
1577
		checkLocal(flags, DEPTH_ZERO);
1578
		return getLocalManager().setLocalTimeStamp(this, info, value);
1586
		return getLocalManager().setLocalTimeStamp(this, info, value);
1579
	}
1587
	}
1580
1588
Lines 1582-1591 Link Here
1582
	 * @see IResource#setPersistentProperty(QualifiedName, String)
1590
	 * @see IResource#setPersistentProperty(QualifiedName, String)
1583
	 */
1591
	 */
1584
	public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
1592
	public void setPersistentProperty(QualifiedName key, String value) throws CoreException {
1585
		ResourceInfo info = getResourceInfo(false, false);
1593
		checkAccessibleAndLocal(DEPTH_ZERO);
1586
		int flags = getFlags(info);
1587
		checkAccessible(flags);
1588
		checkLocal(flags, DEPTH_ZERO);
1589
		getPropertyManager().setProperty(this, key, value);
1594
		getPropertyManager().setProperty(this, key, value);
1590
	}
1595
	}
1591
1596
Lines 1609-1618 Link Here
1609
	 * @see org.eclipse.core.resources.IResource#setResourceAttributes(org.eclipse.core.resources.ResourceAttributes)
1614
	 * @see org.eclipse.core.resources.IResource#setResourceAttributes(org.eclipse.core.resources.ResourceAttributes)
1610
	 */
1615
	 */
1611
	public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
1616
	public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {
1612
		ResourceInfo info = getResourceInfo(false, false);
1617
		checkAccessibleAndLocal(DEPTH_ZERO);
1613
		int flags = getFlags(info);
1614
		checkAccessible(flags);
1615
		checkLocal(flags, DEPTH_ZERO);
1616
		getLocalManager().setResourceAttributes(this, attributes);
1618
		getLocalManager().setResourceAttributes(this, attributes);
1617
	}
1619
	}
1618
1620
Lines 1623-1632 Link Here
1623
		// fetch the info but don't bother making it mutable even though we are going
1625
		// fetch the info but don't bother making it mutable even though we are going
1624
		// to modify it.  We don't know whether or not the tree is open and it really doesn't
1626
		// to modify it.  We don't know whether or not the tree is open and it really doesn't
1625
		// matter as the change we are doing does not show up in deltas.
1627
		// matter as the change we are doing does not show up in deltas.
1626
		ResourceInfo info = getResourceInfo(false, false);
1628
		ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1627
		int flags = getFlags(info);
1628
		checkAccessible(flags);
1629
		checkLocal(flags, DEPTH_ZERO);
1630
		info.setSessionProperty(key, value);
1629
		info.setSessionProperty(key, value);
1631
	}
1630
	}
1632
1631
Lines 1676-1685 Link Here
1676
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1675
			final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
1677
			try {
1676
			try {
1678
				workspace.prepareOperation(rule, monitor);
1677
				workspace.prepareOperation(rule, monitor);
1679
				ResourceInfo info = getResourceInfo(false, false);
1678
				ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
1680
				int flags = getFlags(info);
1681
				checkAccessible(flags);
1682
				checkLocal(flags, DEPTH_ZERO);
1683
1679
1684
				workspace.beginOperation(true);
1680
				workspace.beginOperation(true);
1685
				// fake a change by incrementing the content ID
1681
				// fake a change by incrementing the content ID
(-)src/org/eclipse/core/resources/IResource.java (+35 lines)
Lines 12-17 Link Here
12
package org.eclipse.core.resources;
12
package org.eclipse.core.resources;
13
13
14
import java.net.URI;
14
import java.net.URI;
15
import java.util.Map;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.jobs.ISchedulingRule;
17
import org.eclipse.core.runtime.jobs.ISchedulingRule;
17
18
Lines 1362-1367 Link Here
1362
	public IContainer getParent();
1363
	public IContainer getParent();
1363
1364
1364
	/**
1365
	/**
1366
	 * Returns a copy of the map of this resource persistent properties.
1367
	 * Returns an empty map if there are none.
1368
	 *
1369
	 * @return the map containing the persistent properties where the key is
1370
	 * 	   the qualified name of the property and the value is the string value of the property.
1371
	 * @exception CoreException if this method fails. Reasons include:
1372
	 * <ul>
1373
	 * <li> This resource does not exist.</li>
1374
	 * <li> This resource is not local.</li>
1375
	 * <li> This resource is a project that is not open.</li>
1376
	 * </ul>
1377
	 * 
1378
	 * @since 3.4
1379
	 */
1380
	public Map getPersistentProperties() throws CoreException;
1381
1382
	/**
1365
	 * Returns the value of the persistent property of this resource identified
1383
	 * Returns the value of the persistent property of this resource identified
1366
	 * by the given key, or <code>null</code> if this resource has no such property.
1384
	 * by the given key, or <code>null</code> if this resource has no such property.
1367
	 *
1385
	 *
Lines 1502-1507 Link Here
1502
	public ResourceAttributes getResourceAttributes();
1520
	public ResourceAttributes getResourceAttributes();
1503
1521
1504
	/**
1522
	/**
1523
	 * Returns a copy of the map of this resource session properties.
1524
	 * Returns an empty map if there are none.
1525
	 *
1526
	 * @return the map containing the session properties where the key is
1527
	 * 	   the qualified name of the property and the value is the value of the property.
1528
	 * @exception CoreException if this method fails. Reasons include:
1529
	 * <ul>
1530
	 * <li> This resource does not exist.</li>
1531
	 * <li> This resource is not local.</li>
1532
	 * <li> This resource is a project that is not open.</li>
1533
	 * </ul>
1534
	 * 
1535
	 * @since 3.4
1536
	 */
1537
	public Map getSessionProperties() throws CoreException;
1538
1539
	/**
1505
	 * Returns the value of the session property of this resource identified
1540
	 * Returns the value of the session property of this resource identified
1506
	 * by the given key, or <code>null</code> if this resource has no such property.
1541
	 * by the given key, or <code>null</code> if this resource has no such property.
1507
	 *
1542
	 *
(-)src/org/eclipse/core/tests/resources/IResourceTest.java (+78 lines)
Lines 1698-1703 Link Here
1698
		project.open(null);
1698
		project.open(null);
1699
		assertEquals(stamp, file.getModificationStamp());
1699
		assertEquals(stamp, file.getModificationStamp());
1700
	}
1700
	}
1701
	
1702
	/**
1703
	 * Tests IResource#getPersistentProperties and IResource#getSessionProperties
1704
	 */
1705
	public void testProperties() throws CoreException {
1706
		QualifiedName qn1 = new QualifiedName("package", "property1");
1707
		QualifiedName qn2 = new QualifiedName("package", "property2");
1708
		
1709
		IProject project = getWorkspace().getRoot().getProject("P1");
1710
		IProject project2 = getWorkspace().getRoot().getProject("P2");
1711
		project.create(null);
1712
		project.open(null);
1713
		project.setPersistentProperty(qn1, "value1");
1714
		project.setPersistentProperty(qn2, "value2");
1715
		project.setSessionProperty(qn1, "value1");
1716
		project.setSessionProperty(qn2, "value2");
1717
		
1718
		assertEquals("value1", project.getPersistentProperty(qn1));
1719
		assertEquals("value2", project.getPersistentProperty(qn2));
1720
		assertEquals("value1", project.getSessionProperty(qn1));
1721
		assertEquals("value2", project.getSessionProperty(qn2));
1722
		
1723
		Map props = project.getPersistentProperties();
1724
		assertEquals(2, props.size());
1725
		assertEquals("value1",props.get(qn1));
1726
		assertEquals("value2",props.get(qn2));
1727
		
1728
		props = project.getSessionProperties();
1729
		// Don't check the size, because other plugins (like team) may add
1730
		// a property depending on if they are present or not
1731
		assertEquals("value1",props.get(qn1));
1732
		assertEquals("value2",props.get(qn2));
1733
		
1734
		project.setPersistentProperty(qn1, null);
1735
		project.setSessionProperty(qn1, null);
1736
1737
		props = project.getPersistentProperties();
1738
		assertEquals(1, props.size());
1739
		assertNull(props.get(qn1));
1740
		assertEquals("value2",props.get(qn2));
1741
		
1742
		props = project.getSessionProperties();
1743
		assertNull(props.get(qn1));
1744
		assertEquals("value2",props.get(qn2));
1745
1746
		// Copy
1747
		project.copy(project2.getFullPath(), true, null);
1748
1749
		// Persistent properties go with the copy
1750
		props = project2.getPersistentProperties();
1751
		assertEquals(1, props.size());
1752
		assertNull(props.get(qn1));
1753
		assertEquals("value2",props.get(qn2));
1754
1755
		// Session properties don't
1756
		props = project2.getSessionProperties();
1757
		// Don't check size (see above)
1758
		assertNull(props.get(qn1));
1759
		assertNull(props.get(qn2));
1760
		
1761
		
1762
		// Test persistence
1763
		project.close(null);
1764
		project.open(null);
1765
1766
		// Make sure they are really persistent
1767
		props = project.getPersistentProperties();
1768
		assertEquals(1, props.size());
1769
		assertNull(props.get(qn1));
1770
		assertEquals("value2",props.get(qn2));
1771
1772
		// Make sure they don't persist
1773
		props = project.getSessionProperties();
1774
		// Don't check size (see above)
1775
		assertNull(props.get(qn1));
1776
		assertNull(props.get(qn2));
1777
		
1778
	}
1701
1779
1702
	/**
1780
	/**
1703
	 * Tests IResource.isReadOnly and setReadOnly
1781
	 * Tests IResource.isReadOnly and setReadOnly

Return to bug 215299