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

Collapse All | Expand All

(-)src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java (-10 / +50 lines)
Lines 23-35 Link Here
23
import org.eclipse.core.internal.utils.*;
23
import org.eclipse.core.internal.utils.*;
24
import org.eclipse.core.resources.*;
24
import org.eclipse.core.resources.*;
25
import org.eclipse.core.runtime.*;
25
import org.eclipse.core.runtime.*;
26
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.osgi.util.NLS;
27
import org.xml.sax.InputSource;
28
import org.xml.sax.InputSource;
28
29
29
/**
30
/**
30
 * Manages the synchronization between the workspace's view and the file system.  
31
 * Manages the synchronization between the workspace's view and the file system.  
31
 */
32
 */
32
public class FileSystemResourceManager implements ICoreConstants, IManager {
33
public class FileSystemResourceManager implements ICoreConstants, IManager, Preferences.IPropertyChangeListener {
33
34
34
	/**
35
	/**
35
	 * The history store is initialized lazily - always use the accessor method
36
	 * The history store is initialized lazily - always use the accessor method
Lines 37-42 Link Here
37
	protected IHistoryStore _historyStore;
38
	protected IHistoryStore _historyStore;
38
	protected Workspace workspace;
39
	protected Workspace workspace;
39
40
41
	private volatile boolean autoRefreshEnabled;
42
40
	public FileSystemResourceManager(Workspace workspace) {
43
	public FileSystemResourceManager(Workspace workspace) {
41
		this.workspace = workspace;
44
		this.workspace = workspace;
42
	}
45
	}
Lines 124-129 Link Here
124
		return results;
127
		return results;
125
	}
128
	}
126
129
130
	/**
131
	 * Asynchronously auto-refresh the requested resource if Auto-Refresh is enabled
132
	 * @param target
133
	 */
134
	private void asyncRefresh(IResource target) {
135
		if (autoRefreshEnabled)
136
			workspace.getRefreshManager().refresh(target);
137
	}
138
127
	private void findLinkedResourcesPaths(URI inputLocation, final ArrayList<IPath> results) throws CoreException {
139
	private void findLinkedResourcesPaths(URI inputLocation, final ArrayList<IPath> results) throws CoreException {
128
		IPath suffix = null;
140
		IPath suffix = null;
129
		IFileStore fileStore = EFS.getStore(inputLocation);
141
		IFileStore fileStore = EFS.getStore(inputLocation);
Lines 621-630 Link Here
621
		return projectInfo.getLocalSyncInfo() == getStore(descriptionFile).fetchInfo().getLastModified();
633
		return projectInfo.getLocalSyncInfo() == getStore(descriptionFile).fetchInfo().getLastModified();
622
	}
634
	}
623
635
624
	/* (non-Javadoc)
636
	/**
625
	 * Returns true if the given resource is synchronized with the file system
637
	 * Returns true if the given resource is synchronized with the file system
626
	 * to the given depth.  Returns false otherwise.
638
	 * to the given depth.  Returns false otherwise.
627
	 * 
639
	 * 
640
	 * Any discovered out-of-sync resources are scheduled to be brought back in sync.
641
	 *
628
	 * @see IResource#isSynchronized(int)
642
	 * @see IResource#isSynchronized(int)
629
	 */
643
	 */
630
	public boolean isSynchronized(IResource target, int depth) {
644
	public boolean isSynchronized(IResource target, int depth) {
Lines 661-672 Link Here
661
			Policy.log(e);
675
			Policy.log(e);
662
			return false;
676
			return false;
663
		} catch (IsSynchronizedVisitor.ResourceChangedException e) {
677
		} catch (IsSynchronizedVisitor.ResourceChangedException e) {
678
			// Ask refresh manager to bring out-of-sync resource back into sync when convenient
679
			asyncRefresh(e.target);
664
			//visitor throws an exception if out of sync
680
			//visitor throws an exception if out of sync
665
			return false;
681
			return false;
666
		}
682
		}
667
		return true;
683
		return true;
668
	}
684
	}
669
685
686
	/**
687
	 * @return whether this FSRM is automatically refreshing discovered out-of-sync resources
688
	 */
689
	public boolean isAsyncAutoRefreshEnabled() {
690
		return autoRefreshEnabled;
691
	}
692
670
	public void link(Resource target, URI location, IFileInfo fileInfo) throws CoreException {
693
	public void link(Resource target, URI location, IFileInfo fileInfo) throws CoreException {
671
		initializeStore(target, location);
694
		initializeStore(target, location);
672
		ResourceInfo info = target.getResourceInfo(false, true);
695
		ResourceInfo info = target.getResourceInfo(false, true);
Lines 716-733 Link Here
716
		return null;
739
		return null;
717
	}
740
	}
718
741
742
	public void propertyChange(PropertyChangeEvent event) {
743
		String property = event.getProperty();
744
		if (ResourcesPlugin.PREF_REFRESH_ASYNC.equals(property)) {
745
			Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
746
			autoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_REFRESH_ASYNC);
747
		}
748
	}
749
719
	public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException {
750
	public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException {
720
		IFileStore store = getStore(target);
751
		IFileStore store = getStore(target);
721
		if (!force) {
752
		final IFileInfo fileInfo = store.fetchInfo();
722
			final IFileInfo fileInfo = store.fetchInfo();
753
		if (!fileInfo.exists()) {
723
			if (!fileInfo.exists()) {
754
			asyncRefresh(target);
755
			if (!force) {
724
				String message = NLS.bind(Messages.localstore_fileNotFound, store.toString());
756
				String message = NLS.bind(Messages.localstore_fileNotFound, store.toString());
725
				throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null);
757
				throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null);
726
			}
758
			}
727
			ResourceInfo info = ((Resource) target).getResourceInfo(true, false);
759
		}
728
			int flags = ((Resource) target).getFlags(info);
760
		ResourceInfo info = ((Resource) target).getResourceInfo(true, false);
729
			((Resource) target).checkExists(flags, true);
761
		int flags = ((Resource) target).getFlags(info);
730
			if (fileInfo.getLastModified() != info.getLocalSyncInfo()) {
762
		((Resource) target).checkExists(flags, true);
763
		if (fileInfo.getLastModified() != info.getLocalSyncInfo()) {
764
			asyncRefresh(target);
765
			if (!force) {
731
				String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
766
				String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
732
				throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
767
				throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
733
			}
768
			}
Lines 962-971 Link Here
962
	public void shutdown(IProgressMonitor monitor) throws CoreException {
997
	public void shutdown(IProgressMonitor monitor) throws CoreException {
963
		if (_historyStore != null)
998
		if (_historyStore != null)
964
			_historyStore.shutdown(monitor);
999
			_historyStore.shutdown(monitor);
1000
		ResourcesPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this);
965
	}
1001
	}
966
1002
967
	public void startup(IProgressMonitor monitor) throws CoreException {
1003
	public void startup(IProgressMonitor monitor) throws CoreException {
968
		//nothing to do
1004
		Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
1005
		preferences.addPropertyChangeListener(this);
1006
		autoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_REFRESH_ASYNC);
969
	}
1007
	}
970
1008
971
	/**
1009
	/**
Lines 1006-1015 Link Here
1006
					ResourceInfo info = ((Resource) target).getResourceInfo(true, false);
1044
					ResourceInfo info = ((Resource) target).getResourceInfo(true, false);
1007
					// test if timestamp is the same since last synchronization
1045
					// test if timestamp is the same since last synchronization
1008
					if (lastModified != info.getLocalSyncInfo()) {
1046
					if (lastModified != info.getLocalSyncInfo()) {
1047
						asyncRefresh(target);
1009
						String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
1048
						String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
1010
						throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
1049
						throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
1011
					}
1050
					}
1012
					if (!fileInfo.exists()) {
1051
					if (!fileInfo.exists()) {
1052
						asyncRefresh(target);
1013
						String message = NLS.bind(Messages.localstore_resourceDoesNotExist, target.getFullPath());
1053
						String message = NLS.bind(Messages.localstore_resourceDoesNotExist, target.getFullPath());
1014
						throw new ResourceException(IResourceStatus.NOT_FOUND_LOCAL, target.getFullPath(), message, null);
1054
						throw new ResourceException(IResourceStatus.NOT_FOUND_LOCAL, target.getFullPath(), message, null);
1015
					}
1055
					}
(-)src/org/eclipse/core/internal/localstore/IsSynchronizedVisitor.java (-6 / +23 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-31 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     James Blackburn (Broadcom Corp.) - ongoing development
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.localstore;
12
package org.eclipse.core.internal.localstore;
12
13
13
import org.eclipse.core.internal.resources.Resource;
14
import org.eclipse.core.internal.resources.Resource;
15
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
15
17
16
/**
18
/**
17
 * Visits a unified tree, and throws a ResourceChangedException on the first 
19
 * Visits a unified tree, and throws a ResourceChangedException on the first 
18
 * node that is discovered to be out of sync.  The exception that is thrown 
20
 * node that is discovered to be out of sync.  The exception that is thrown 
19
 * will not have any meaningful status, message, or stack trace.  Nodes 
21
 * will not have any meaningful status, message, or stack trace. However it
20
 * discovered to be out of sync are not brought to be in sync with the workspace.
22
 * does contain the target resource which can be used to bring the Resource
23
 * back into sync.
21
 */
24
 */
22
public class IsSynchronizedVisitor extends CollectSyncStatusVisitor {
25
public class IsSynchronizedVisitor extends CollectSyncStatusVisitor {
23
	static class ResourceChangedException extends RuntimeException {
26
	static class ResourceChangedException extends RuntimeException {
24
		private static final long serialVersionUID = 1L;
27
		private static final long serialVersionUID = 1L;
28
		public final IResource target;
29
		public ResourceChangedException(IResource target) {
30
			this.target = target;
31
		}
25
	}
32
	}
26
33
27
	protected static ResourceChangedException exception = new ResourceChangedException();
28
29
	/**
34
	/**
30
	 * Creates a new IsSynchronizedVisitor.
35
	 * Creates a new IsSynchronizedVisitor.
31
	 */
36
	 */
Lines 36-42 Link Here
36
	/**
41
	/**
37
	 * @see CollectSyncStatusVisitor#changed(Resource)
42
	 * @see CollectSyncStatusVisitor#changed(Resource)
38
	 */
43
	 */
44
	@Override
39
	protected void changed(Resource target) {
45
	protected void changed(Resource target) {
40
		throw exception;
46
		throw new ResourceChangedException(target);
47
	}
48
49
	@Override
50
	protected void fileToFolder(UnifiedTreeNode node, Resource target) {
51
		changed((Resource)workspace.getRoot().getFolder(target.getFullPath()));
52
	}
53
54
	@Override
55
	protected void folderToFile(UnifiedTreeNode node, Resource target) {
56
		// Pass correct gender to changed for notification and async-refresh
57
		changed((Resource)workspace.getRoot().getFile(target.getFullPath()));
41
	}
58
	}
42
}
59
}
(-)src/org/eclipse/core/internal/resources/ContentDescriptionManager.java (-9 / +19 lines)
Lines 300-306 Link Here
300
		return projectContentTypes.getMatcherFor(project);
300
		return projectContentTypes.getMatcherFor(project);
301
	}
301
	}
302
302
303
	public IContentDescription getDescriptionFor(File file, ResourceInfo info) throws CoreException {
303
	/**
304
	 * Discovers, and caches, the content description of the requested File.
305
	 * @param file to discover the content description for; result cached
306
	 * @param info ResourceInfo for the passed in file
307
	 * @param in_sync boolean flag which indicates if cache can be trusted. If false false don't trust the cache
308
	 * @return IContentDescription for the file
309
	 * @throws CoreException
310
	 */
311
	public IContentDescription getDescriptionFor(File file, ResourceInfo info, boolean in_sync) throws CoreException {
304
		if (ProjectContentTypes.usesContentTypePreferences(file.getFullPath().segment(0)))
312
		if (ProjectContentTypes.usesContentTypePreferences(file.getFullPath().segment(0)))
305
			// caching for project containing project specific settings is not supported
313
			// caching for project containing project specific settings is not supported
306
			return readDescription(file);
314
			return readDescription(file);
Lines 311-317 Link Here
311
			// the cache is not good, flush it
319
			// the cache is not good, flush it
312
			flushJob.schedule(1000);
320
			flushJob.schedule(1000);
313
		}
321
		}
314
		if (getCacheState() != ABOUT_TO_FLUSH) {
322
		if (in_sync && getCacheState() != ABOUT_TO_FLUSH) {
315
			// first look for the flags in the resource info to avoid looking in the cache
323
			// first look for the flags in the resource info to avoid looking in the cache
316
			// don't need to copy the info because the modified bits are not in the deltas
324
			// don't need to copy the info because the modified bits are not in the deltas
317
			if (info == null)
325
			if (info == null)
Lines 332-343 Link Here
332
				info.clear(ICoreConstants.M_CONTENT_CACHE);
340
				info.clear(ICoreConstants.M_CONTENT_CACHE);
333
			}
341
			}
334
		}
342
		}
335
		synchronized (this) {
343
		if (in_sync) {
336
			// tries to get a description from the cache	
344
			// tries to get a description from the cache	
337
			Cache.Entry entry = cache.getEntry(file.getFullPath());
345
			synchronized (this) {
338
			if (entry != null && entry.getTimestamp() == getTimestamp(info))
346
				Cache.Entry entry = cache.getEntry(file.getFullPath());
339
				// there was a description in the cache, and it was up to date
347
				if (entry != null && entry.getTimestamp() == getTimestamp(info))
340
				return (IContentDescription) entry.getCached();
348
					// there was a description in the cache, and it was up to date
349
					return (IContentDescription) entry.getCached();
350
			}
341
		}
351
		}
342
			
352
			
343
			// either we didn't find a description in the cache, or it was not up-to-date - has to be read again
353
			// either we didn't find a description in the cache, or it was not up-to-date - has to be read again
Lines 347-353 Link Here
347
		synchronized (this) {
357
		synchronized (this) {
348
			// tries to get a description from the cache
358
			// tries to get a description from the cache
349
			Cache.Entry entry = cache.getEntry(file.getFullPath());
359
			Cache.Entry entry = cache.getEntry(file.getFullPath());
350
			if (entry != null && entry.getTimestamp() == getTimestamp(info))
360
			if (entry != null && in_sync && entry.getTimestamp() == getTimestamp(info))
351
				// there was a description in the cache, and it was up to date
361
				// there was a description in the cache, and it was up to date
352
				return (IContentDescription) entry.getCached();
362
				return (IContentDescription) entry.getCached();
353
			
363
			
Lines 375-381 Link Here
375
				entry = cache.addEntry(file.getFullPath(), newDescription, getTimestamp(info));
385
				entry = cache.addEntry(file.getFullPath(), newDescription, getTimestamp(info));
376
			else {
386
			else {
377
				// just update the existing entry
387
				// just update the existing entry
378
				entry.setTimestamp(info.getContentId());
388
				entry.setTimestamp(getTimestamp(info));
379
				entry.setCached(newDescription);
389
				entry.setCached(newDescription);
380
			}
390
			}
381
			return newDescription;
391
			return newDescription;
(-)src/org/eclipse/core/internal/resources/File.java (-14 / +9 lines)
Lines 94-109 Link Here
94
		return result;
94
		return result;
95
	}
95
	}
96
96
97
	/**
98
	 * Checks that this resource is synchronized with the local file system.
99
	 */
100
	private void checkSynchronized() throws CoreException {
101
		if (!isSynchronized(IResource.DEPTH_ZERO)) {
102
			String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, getFullPath());
103
			throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, getFullPath(), message, null);
104
		}
105
	}
106
107
	/* (non-Javadoc)
97
	/* (non-Javadoc)
108
	 * @see IFile#create(InputStream, int, IProgressMonitor)
98
	 * @see IFile#create(InputStream, int, IProgressMonitor)
109
	 */
99
	 */
Lines 252-258 Link Here
252
		if (charset != null || !checkImplicit)
242
		if (charset != null || !checkImplicit)
253
			return charset;
243
			return charset;
254
		// tries to obtain a description for the file contents
244
		// tries to obtain a description for the file contents
255
		IContentDescription description = workspace.getContentDescriptionManager().getDescriptionFor(this, info);
245
		IContentDescription description = workspace.getContentDescriptionManager().getDescriptionFor(this, info, true);
256
		if (description != null) {
246
		if (description != null) {
257
			String contentCharset = description.getCharset();
247
			String contentCharset = description.getCharset();
258
			if (contentCharset != null)
248
			if (contentCharset != null)
Lines 270-285 Link Here
270
		ResourceInfo info = getResourceInfo(false, false);
260
		ResourceInfo info = getResourceInfo(false, false);
271
		int flags = getFlags(info);
261
		int flags = getFlags(info);
272
		checkAccessible(flags);
262
		checkAccessible(flags);
273
		checkSynchronized();
274
		checkLocal(flags, DEPTH_ZERO);
263
		checkLocal(flags, DEPTH_ZERO);
275
		return workspace.getContentDescriptionManager().getDescriptionFor(this, info);
264
		boolean isSynchronized = isSynchronized(IResource.DEPTH_ZERO);
265
		// Throw an exception if out-of-sync and not auto-refresh enabled
266
		if (!isSynchronized && !getLocalManager().isAsyncAutoRefreshEnabled()) {
267
			String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, getFullPath());
268
			throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, getFullPath(), message, null);
269
		}
270
		return workspace.getContentDescriptionManager().getDescriptionFor(this, info, isSynchronized);
276
	}
271
	}
277
272
278
	/* (non-Javadoc)
273
	/* (non-Javadoc)
279
	 * @see IFile#getContents()
274
	 * @see IFile#getContents()
280
	 */
275
	 */
281
	public InputStream getContents() throws CoreException {
276
	public InputStream getContents() throws CoreException {
282
		return getContents(false);
277
		return getContents(getLocalManager().isAsyncAutoRefreshEnabled());
283
	}
278
	}
284
279
285
	/* (non-Javadoc)
280
	/* (non-Javadoc)
(-)src/org/eclipse/core/internal/resources/PreferenceInitializer.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     James Blackburn (Broadcom Corp.) - ongoing development
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.resources;
12
package org.eclipse.core.internal.resources;
12
13
Lines 23-28 Link Here
23
	public static final String PREF_DELTA_EXPIRATION = "delta.expiration";  //$NON-NLS-1$
24
	public static final String PREF_DELTA_EXPIRATION = "delta.expiration";  //$NON-NLS-1$
24
25
25
	// DEFAULTS
26
	// DEFAULTS
27
	public static final boolean PREF_ASYNC_REFRESH_DEFAULT = true;
26
	public static final boolean PREF_AUTO_REFRESH_DEFAULT = false;
28
	public static final boolean PREF_AUTO_REFRESH_DEFAULT = false;
27
	public static final boolean PREF_DISABLE_LINKING_DEFAULT = false;
29
	public static final boolean PREF_DISABLE_LINKING_DEFAULT = false;
28
	public static final String PREF_ENCODING_DEFAULT = ""; //$NON-NLS-1$
30
	public static final String PREF_ENCODING_DEFAULT = ""; //$NON-NLS-1$
Lines 49-54 Link Here
49
		IEclipsePreferences node = new DefaultScope().getNode(ResourcesPlugin.PI_RESOURCES);
51
		IEclipsePreferences node = new DefaultScope().getNode(ResourcesPlugin.PI_RESOURCES);
50
		// auto-refresh default
52
		// auto-refresh default
51
		node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, PREF_AUTO_REFRESH_DEFAULT);
53
		node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, PREF_AUTO_REFRESH_DEFAULT);
54
		node.putBoolean(ResourcesPlugin.PREF_REFRESH_ASYNC, PREF_ASYNC_REFRESH_DEFAULT);
52
55
53
		// linked resources default
56
		// linked resources default
54
		node.putBoolean(ResourcesPlugin.PREF_DISABLE_LINKING, PREF_DISABLE_LINKING_DEFAULT);
57
		node.putBoolean(ResourcesPlugin.PREF_DISABLE_LINKING, PREF_DISABLE_LINKING_DEFAULT);
(-)src/org/eclipse/core/resources/IFile.java (-5 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2010 IBM Corporation and others.
2
 *  Copyright (c) 2000, 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 *  Contributors:
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     James Blackburn (Broadcom Corp.) - ongoing development
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.resources;
12
package org.eclipse.core.resources;
12
13
Lines 669-675 Link Here
669
	 * <li> This resource could not be read.</li>
670
	 * <li> This resource could not be read.</li>
670
	 * <li> This resource is not local.</li>
671
	 * <li> This resource is not local.</li>
671
	 * <li> The workspace is not in sync with the corresponding location
672
	 * <li> The workspace is not in sync with the corresponding location
672
	 *       in the local file system.</li>
673
	 *       in the local file system and {@link ResourcesPlugin#PREF_REFRESH_ASYNC} is
674
	 *       disabled.</li>
673
	 * <li> The corresponding location in the local file system
675
	 * <li> The corresponding location in the local file system
674
	 *       is occupied by a directory.</li>
676
	 *       is occupied by a directory.</li>
675
	 * </ul> 
677
	 * </ul> 
Lines 681-688 Link Here
681
683
682
	/**
684
	/**
683
	 * Returns an open input stream on the contents of this file.
685
	 * Returns an open input stream on the contents of this file.
684
	 * This refinement of the corresponding <code>IStorage</code> method 
686
	 * <p>
685
	 * returns an open input stream on the contents of this file.
687
	 * This refinement of the corresponding {@link IStorage} method
688
	 * is a convenience method returning an open input stream.  It's equivalent to:
689
	 * <pre>
690
	 *   getContents(auto_refresh enabled);
691
	 * </pre>
692
	 * </p>
686
	 * The client is responsible for closing the stream when finished.
693
	 * The client is responsible for closing the stream when finished.
687
	 *
694
	 *
688
	 * @return an input stream containing the contents of the file
695
	 * @return an input stream containing the contents of the file
Lines 690-697 Link Here
690
	 * <ul>
697
	 * <ul>
691
	 * <li> This resource does not exist.</li>
698
	 * <li> This resource does not exist.</li>
692
	 * <li> This resource is not local.</li>
699
	 * <li> This resource is not local.</li>
700
	 * <li> The file-system resource is not a file.</li>
693
	 * <li> The workspace is not in sync with the corresponding location
701
	 * <li> The workspace is not in sync with the corresponding location
694
	 *       in the local file system.</li>
702
	 *       in the local file system (and {@link ResourcesPlugin#PREF_REFRESH_ASYNC} 
703
	 *       is disabled).</li>
695
	 * </ul>
704
	 * </ul>
696
	 */
705
	 */
697
	public InputStream getContents() throws CoreException;
706
	public InputStream getContents() throws CoreException;
(-)src/org/eclipse/core/resources/ResourcesPlugin.java (-1 / +17 lines)
Lines 280-291 Link Here
280
280
281
	/**
281
	/**
282
	 * Name of a preference for configuring whether the workspace performs auto-
282
	 * Name of a preference for configuring whether the workspace performs auto-
283
	 * refresh.
283
	 * refresh.  Auto-refresh installs a file-system listener, or performs
284
	 * periodic file-system polling to actively discover changes in the resource
285
	 * hierarchy.
284
	 * @since 3.0
286
	 * @since 3.0
285
	 */
287
	 */
286
	public static final String PREF_AUTO_REFRESH = "refresh.enabled"; //$NON-NLS-1$
288
	public static final String PREF_AUTO_REFRESH = "refresh.enabled"; //$NON-NLS-1$
287
289
288
	/**
290
	/**
291
	 * Name of a preference for configuring whether out-of-sync resources are automatically
292
	 * asynchronously refreshed, when discovered to be out-of-sync by the workspace.
293
	 * <p>
294
	 * This preference suppresses out-of-sync CoreException for some read methods, including:
295
	 * {@link IFile#getContents()} & {@link IFile#getContentDescription()}. 
296
	 * </p>
297
	 * This is a hidden preference; true by default.  It is provided so products can 
298
	 * restore WS refresh to pre-3.7 behaviour.  Integrators should take care if
299
	 * changing this from the default. See: https://bugs.eclipse.org/303517
300
	 * @since 3.7
301
	 */
302
	public static final String PREF_REFRESH_ASYNC = "refresh.async.enabled"; //$NON-NLS-1$
303
304
	/**
289
	 * Name of a preference for configuring whether encodings for derived
305
	 * Name of a preference for configuring whether encodings for derived
290
	 * resources within the project should be stored in a separate derived
306
	 * resources within the project should be stored in a separate derived
291
	 * preference file.
307
	 * preference file.
(-)src/org/eclipse/core/tests/internal/resources/ProjectPreferencesTest.java (-12 lines)
Lines 546-563 Link Here
546
		assertEquals("2.2", value2, node.get(emptyKey, null));
546
		assertEquals("2.2", value2, node.get(emptyKey, null));
547
	}
547
	}
548
548
549
	private void touchInFilesystem(IFile file) {
550
		for (int count = 0; count < 30 && file.isSynchronized(IResource.DEPTH_ZERO); count++) {
551
			try {
552
				Thread.sleep(100);
553
			} catch (InterruptedException e) {
554
				// ignore
555
			}
556
			file.getLocation().toFile().setLastModified(System.currentTimeMillis());
557
		}
558
		assertTrue("File not out of sync: " + file.getLocation().toOSString(), !file.isSynchronized(IResource.DEPTH_ZERO));
559
	}
560
561
	/*
549
	/*
562
	 * Bug 61843 - Saving project preferences failed
550
	 * Bug 61843 - Saving project preferences failed
563
	 * 
551
	 * 
(-)src/org/eclipse/core/tests/resources/CharsetTest.java (-16 / +57 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2004, 2010 IBM Corporation and others.
2
 *  Copyright (c) 2004, 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 *  Contributors:
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     James Blackburn (Broadcom Corp.) - ongoing development
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.tests.resources;
12
package org.eclipse.core.tests.resources;
12
13
Lines 17-22 Link Here
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.resources.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.content.*;
20
import org.eclipse.core.runtime.content.*;
21
import org.eclipse.core.runtime.jobs.Job;
20
import org.osgi.service.prefs.BackingStoreException;
22
import org.osgi.service.prefs.BackingStoreException;
21
23
22
public class CharsetTest extends ResourceTest {
24
public class CharsetTest extends ResourceTest {
Lines 359-369 Link Here
359
		}
361
		}
360
	}
362
	}
361
363
362
	public void testBug186984() {
364
	/**
365
	 * Test for getting charset on an IFile:
366
	 * #getContentDescription() checks file sync state(), always returning the
367
	 * correct content description, whereas getCharset() uses the cached charset if available.
368
	 * @throws Exception
369
	 */
370
	public void testBug186984() throws Exception {
363
		IWorkspace workspace = getWorkspace();
371
		IWorkspace workspace = getWorkspace();
364
		IProject project = workspace.getRoot().getProject(getUniqueString());
372
		IProject project = workspace.getRoot().getProject(getUniqueString());
365
		IFile file = project.getFile("file.xml");
373
		IFile file = project.getFile("file.xml");
366
374
375
		// Test changing content types externally as per bug 186984 Comment 8
376
		String ascii = "<?xml version=\"1.0\" encoding=\"ascii\"?>";
377
		String utf = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
378
367
		// test if we can get the charset, when the file doesn't exist in a file system
379
		// test if we can get the charset, when the file doesn't exist in a file system
368
		try {
380
		try {
369
			file.getCharset(true);
381
			file.getCharset(true);
Lines 389-409 Link Here
389
		} catch (CoreException ex) {
401
		} catch (CoreException ex) {
390
			fail("3.0");
402
			fail("3.0");
391
		}
403
		}
392
		//getContentDescription checks synchronization state, so it should fail
393
		try {
394
			file.getContentDescription();
395
			fail("3.1");
396
		} catch (CoreException ex) {
397
			assertEquals("3.2", IResourceStatus.OUT_OF_SYNC_LOCAL, ex.getStatus().getCode());
398
		}
399
404
400
		// test if we can get the charset, when the file is refreshed
405
		// set the content type within the XML file, ensure that #getContentDescription (which respects sync state)
401
		try {
406
		// returns the correct value.
402
			file.refreshLocal(IResource.DEPTH_ZERO, null);
407
403
			file.getCharset(true);
408
		// 1) first set the content type to ascii
404
		} catch (CoreException ex) {
409
		file.setContents(new ByteArrayInputStream(ascii.getBytes("ascii")), IResource.FORCE, getMonitor());
405
			fail("4.0");
410
		assertTrue("4.0", file.getCharset().equals("ascii"));
406
		}
411
		assertTrue("4.1", file.getContentDescription().getCharset().equals("ascii"));
412
413
		// 2) Make out of sync - Methods should still work, giving the previous value
414
		touchInFilesystem(file);
415
		assertTrue("4.2", file.getCharset().equals("ascii"));
416
		assertTrue("4.3", file.getContentDescription().getCharset().equals("ascii"));
417
		// getContentDescription will have noticed out-of-sync
418
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
419
		// Prime the cache...
420
		assertTrue("4.3", file.getCharset().equals("ascii"));
421
422
		// 3) Change the content type of the file under eclipse's feet
423
		FileWriter writer = new FileWriter(file.getLocation().toFile());
424
		writer.write(utf);
425
		writer.close();
426
		touchInFilesystem(file);
427
		// #getCharset uses the cached value (bug 209167) - doesn't check sync state
428
		assertTrue("4.4", file.getCharset().equals("ascii"));
429
		// #getContentDescription checks sync and discovers the real content type
430
		assertTrue("4.5", file.getContentDescription().getCharset().equals("UTF-8"));
431
		// getContentDescription will have noticed out-of-sync
432
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
433
		// #getCharset will now have noticed that the file has changed.
434
		assertTrue("4.6", file.getCharset().equals("UTF-8"));
435
436
		// 4) Change the content type of the file under eclipse's feet once more (to non-default).
437
		writer = new FileWriter(file.getLocation().toFile());
438
		writer.write(ascii);
439
		writer.close();
440
		touchInFilesystem(file);
441
		// #getCharset uses the cached value (bug 209167) - doesn't check sync state
442
		assertTrue("4.7", file.getCharset().equals("UTF-8"));
443
		// #getContentDescription checks sync and discovers the real content type
444
		assertTrue("4.8", file.getContentDescription().getCharset().equals("ascii"));
445
		// getContentDescription will have noticed out-of-sync
446
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
447
		assertTrue("4.9", file.getCharset().equals("ascii"));
407
	}
448
	}
408
449
409
	public void testBug207510() {
450
	public void testBug207510() {
(-)src/org/eclipse/core/tests/resources/IResourceTest.java (-3 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2009 IBM Corporation and others.
2
 *  Copyright (c) 2000, 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
import org.eclipse.core.internal.resources.Workspace;
18
import org.eclipse.core.internal.resources.Workspace;
19
import org.eclipse.core.resources.*;
19
import org.eclipse.core.resources.*;
20
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.tests.harness.CancelingProgressMonitor;
22
import org.eclipse.core.tests.harness.CancelingProgressMonitor;
22
import org.eclipse.core.tests.harness.FussyProgressMonitor;
23
import org.eclipse.core.tests.harness.FussyProgressMonitor;
23
24
Lines 192-198 Link Here
192
		}
193
		}
193
		//out of sync
194
		//out of sync
194
		IResource[] unsynchronized = buildResources(root, new String[] {"1/2/3/3"});
195
		IResource[] unsynchronized = buildResources(root, new String[] {"1/2/3/3"});
195
		ensureOutOfSync(unsynchronized[0]);
196
		ensureOutOfSync((IFile) unsynchronized[0]);
196
		unsynchronizedResources.add(unsynchronized[0]);
197
		unsynchronizedResources.add(unsynchronized[0]);
197
198
198
		//file system only
199
		//file system only
Lines 424-429 Link Here
424
	/**
425
	/**
425
	 * Sets up the workspace and file system for this test. */
426
	 * Sets up the workspace and file system for this test. */
426
	protected void setupBeforeState(IResource receiver, IResource target, int state, int depth, boolean addVerifier) throws CoreException {
427
	protected void setupBeforeState(IResource receiver, IResource target, int state, int depth, boolean addVerifier) throws CoreException {
428
		// Wait for any outstanding refresh to finish
429
		try {
430
			Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
431
		} catch (InterruptedException e) {
432
			fail("interrupted unexpectedly");
433
		}
434
427
		if (addVerifier) {
435
		if (addVerifier) {
428
			/* install the verifier */
436
			/* install the verifier */
429
			if (verifier == null) {
437
			if (verifier == null) {
Lines 466-472 Link Here
466
				break;
474
				break;
467
			case S_CHANGED :
475
			case S_CHANGED :
468
				ensureExistsInWorkspace(target, true);
476
				ensureExistsInWorkspace(target, true);
469
				ensureOutOfSync(target);
477
				touchInFilesystem(target);
470
				if (addVerifier) {
478
				if (addVerifier) {
471
					verifier.reset();
479
					verifier.reset();
472
					// we only get a delta if the receiver of refreshLocal
480
					// we only get a delta if the receiver of refreshLocal
(-)src/org/eclipse/core/tests/resources/ResourceTest.java (-10 / +24 lines)
Lines 71-77 Link Here
71
	 * test is complete
71
	 * test is complete
72
	 * @see #getTempStore
72
	 * @see #getTempStore
73
	 */
73
	 */
74
	private final Set storesToDelete = new HashSet();
74
	private final Set<IFileStore> storesToDelete = new HashSet<IFileStore>();
75
75
76
	/**
76
	/**
77
	 * Does some garbage collections to free unused resources
77
	 * Does some garbage collections to free unused resources
Lines 373-379 Link Here
373
	}
373
	}
374
374
375
	protected void cleanup() throws CoreException {
375
	protected void cleanup() throws CoreException {
376
		final IFileStore[] toDelete = (IFileStore[]) storesToDelete.toArray(new IFileStore[0]);
376
		final IFileStore[] toDelete = storesToDelete.toArray(new IFileStore[0]);
377
		storesToDelete.clear();
377
		storesToDelete.clear();
378
		getWorkspace().run(new IWorkspaceRunnable() {
378
		getWorkspace().run(new IWorkspaceRunnable() {
379
			public void run(IProgressMonitor monitor) throws CoreException {
379
			public void run(IProgressMonitor monitor) throws CoreException {
Lines 658-679 Link Here
658
	}
658
	}
659
659
660
	/**
660
	/**
661
	 * Modifies the resource in the file system so that it is out of sync
661
	 * Modifies the passed in IFile in the file system so that it is out of sync
662
	 * with the workspace.
662
	 * with the workspace.
663
	 */
663
	 */
664
	public void ensureOutOfSync(final IResource resource) {
664
	public void ensureOutOfSync(final IFile file) {
665
		if (resource.getType() != IResource.FILE)
665
		touchInFilesystem(file);
666
			return;
666
		modifyInFileSystem(file);
667
		IFile file = (IFile) resource;
667
		assertTrue("File not out of sync: " + file.getLocation().toOSString(), file.getLocation().toFile().lastModified() != file.getLocalTimeStamp());
668
		ensureExistsInWorkspace(file, true);
668
	}
669
		while (file.isSynchronized(IResource.DEPTH_ZERO)) {
669
670
			modifyInFileSystem(file);
670
	/**
671
	 * Touch (but don't modify) the resource in the filesystem so that it's modification stamp is newer than 
672
	 * the cached value in the Workspace. 
673
	 */
674
	public void touchInFilesystem(IResource resource) {
675
		java.io.File osFile = resource.getLocation().toFile();
676
		// Ensure the resource exists in the filesystem
677
		if (!osFile.exists())
678
			ensureExistsInFileSystem(resource);
679
		// Manually check that the core.resource time-stamp is out-of-sync
680
		// with the java.io.File last modified. #isSynchronized() will schedule
681
		// out-of-sync resources for refresh, so we don't use that here.
682
		for (int count = 0; count < 30 && osFile.lastModified() == resource.getLocalTimeStamp(); count++) {
671
			try {
683
			try {
672
				Thread.sleep(100);
684
				Thread.sleep(100);
673
			} catch (InterruptedException e) {
685
			} catch (InterruptedException e) {
674
				// ignore
686
				// ignore
675
			}
687
			}
688
			resource.getLocation().toFile().setLastModified(System.currentTimeMillis());
676
		}
689
		}
690
		assertTrue("File not out of sync: " + resource.getLocation().toOSString(), osFile.lastModified() != resource.getLocalTimeStamp());
677
	}
691
	}
678
692
679
	private boolean existsInFileSystem(IResource resource) {
693
	private boolean existsInFileSystem(IResource resource) {
(-)src/org/eclipse/core/tests/resources/regression/AllTests.java (+1 lines)
Lines 58-63 Link Here
58
		suite.addTest(Bug_265810.suite());
58
		suite.addTest(Bug_265810.suite());
59
		suite.addTest(Bug_264182.suite());
59
		suite.addTest(Bug_264182.suite());
60
		suite.addTest(Bug_288315.suite());
60
		suite.addTest(Bug_288315.suite());
61
		suite.addTest(Bug_303517.suite());
61
		suite.addTest(Bug_329836.suite());
62
		suite.addTest(Bug_329836.suite());
62
		suite.addTest(Bug_331445.suite());
63
		suite.addTest(Bug_331445.suite());
63
		suite.addTest(Bug_332543.suite());
64
		suite.addTest(Bug_332543.suite());
(-)src/org/eclipse/core/tests/resources/regression/Bug_303517.java (+195 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2011 Broadcom Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *  Contributors:
9
 *     James Blackburn (Broadcom Corp.) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.tests.resources.regression;
12
13
import java.io.File;
14
import java.io.InputStream;
15
import junit.framework.Test;
16
import junit.framework.TestSuite;
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.tests.resources.ResourceTest;
22
23
/**
24
 * Tests that, when the workspace discovery a resource is out-of-sync
25
 * it brings the resource back into sync in a timely manner.
26
 */
27
public class Bug_303517 extends ResourceTest {
28
29
	public static Test suite() {
30
		return new TestSuite(Bug_303517.class);
31
	}
32
33
	String[] resources = new String[] {"/", "/Bug303517/", "/Bug303517/Folder/", "/Bug303517/Folder/Resource",};
34
35
	public String[] defineHierarchy() {
36
		return resources;
37
	}
38
39
	/**
40
	 * Tests that file deleted is udpated after #getContents
41
	 * @throws Exception
42
	 */
43
	public void testExists() throws Exception {
44
		createHierarchy();
45
		IFile f = getWorkspace().getRoot().getFile(new Path(resources[resources.length - 1]));
46
		assertTrue("1.0", f.exists());
47
		assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE));
48
49
		// Touch on file-system
50
		boolean fail = true;
51
		f.getLocation().toFile().delete();
52
		// Core.resources still thinks the file exists
53
		assertTrue("1.2", f.exists());
54
		try {
55
			InputStream in = f.getContents();
56
			in.close();
57
		} catch (CoreException e) {
58
			// File doesn't exist
59
			fail = false;
60
		}
61
		assertFalse("1.3", fail);
62
63
		// Wait for auto-refresh to happen
64
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
65
66
		// Core.resources should be aware that the file no longer exists...
67
		assertFalse("1.4", f.exists());
68
	}
69
70
	/**
71
	 * Tests that file discovered out-of-sync during #getContents is updated
72
	 * @throws Exception
73
	 */
74
	public void testGetContents() throws Exception {
75
		createHierarchy();
76
		IFile f = getWorkspace().getRoot().getFile(new Path(resources[resources.length - 1]));
77
		assertTrue("1.0", f.exists());
78
		assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE));
79
80
		// Touch on file-system
81
		boolean fail = true;
82
		touchInFilesystem(f);
83
		try {
84
			InputStream in = f.getContents(false);
85
			in.close();
86
		} catch (CoreException e) {
87
			// File is out-of-sync, so this is good
88
			fail = false;
89
		}
90
		assertFalse("1.2", fail);
91
92
		// Wait for auto-refresh to happen
93
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
94
95
		// File is now in sync.
96
		try {
97
			InputStream in = f.getContents(false);
98
			in.close();
99
		} catch (CoreException e) {
100
			// Bad, file shouldn't be out-of-sync
101
			fail = true;
102
		}
103
		assertFalse("1.3", fail);
104
	}
105
106
	/**
107
	 * Tests that file discovered out-of-sync during #getContents is updated
108
	 * @throws Exception
109
	 */
110
	public void testGetContentsTrue() throws Exception {
111
		createHierarchy();
112
		IFile f = getWorkspace().getRoot().getFile(new Path(resources[resources.length - 1]));
113
		assertTrue("1.0", f.exists());
114
		assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE));
115
116
		// Touch on file-system
117
		boolean fail = false;
118
		touchInFilesystem(f);
119
		try {
120
			InputStream in = f.getContents(true);
121
			in.close();
122
		} catch (CoreException e) {
123
			// File is out-of-sync, so this is good
124
			fail = true;
125
		}
126
		assertFalse("1.2", fail);
127
128
		// Wait for auto-refresh to happen
129
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
130
131
		// File is now in sync.
132
		try {
133
			InputStream in = f.getContents();
134
			in.close();
135
		} catch (CoreException e) {
136
			// Bad, file shouldn't be out-of-sync
137
			fail = true;
138
		}
139
		assertFalse("1.3", fail);
140
	}
141
142
	/**
143
	 * Tests that resource discovered out-of-sync during #isSynchronized is updated
144
	 * @throws Exception
145
	 */
146
	public void testIsSynchronized() throws Exception {
147
		createHierarchy();
148
		IFile f = getWorkspace().getRoot().getFile(new Path(resources[resources.length - 1]));
149
		assertTrue("1.0", f.exists());
150
		assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE));
151
152
		// Touch on file-system
153
		touchInFilesystem(f);
154
		assertFalse("1.2", f.isSynchronized(IResource.DEPTH_ONE));
155
156
		// Wait for auto-refresh to happen
157
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
158
159
		// File is now in sync.
160
		assertTrue("1.3", f.isSynchronized(IResource.DEPTH_ONE));
161
	}
162
163
	/**
164
	 * Tests that when changing resource gender is correctly picked up.
165
	 * @throws Exception
166
	 */
167
	public void testChangeResourceGender() throws Exception {
168
		createHierarchy();
169
		IResource f = getWorkspace().getRoot().getFile(new Path(resources[resources.length - 1]));
170
		assertTrue("1.0", f.exists());
171
		assertTrue("1.1", f.isSynchronized(IResource.DEPTH_ONE));
172
173
		// Replace the file with a folder
174
		File osResource = f.getLocation().toFile();
175
		osResource.delete();
176
		osResource.mkdir();
177
		assertTrue(osResource.exists());
178
		File osChild = new File(osResource, "child");
179
		osChild.createNewFile();
180
		assertTrue(osChild.exists());
181
182
		assertFalse("1.2", f.isSynchronized(IResource.DEPTH_ONE));
183
184
		// Wait for auto-refresh to happen
185
		Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, getMonitor());
186
187
		// File is no longer a file - i.e. still out-of-sync
188
		assertFalse("1.3", f.exists());
189
		assertFalse("1.4", f.isSynchronized(IResource.DEPTH_ONE));
190
		// Folder + child are now in-sync
191
		f = getWorkspace().getRoot().getFolder(new Path(resources[resources.length - 1]));
192
		assertTrue("1.5", f.exists());
193
		assertTrue("1.6", f.isSynchronized(IResource.DEPTH_INFINITE));
194
	}
195
}
(-)src/org/eclipse/core/tests/resources/regression/IProjectTest.java (-8 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2008 IBM Corporation and others.
2
 *  Copyright (c) 2000, 2011 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 241-253 Link Here
241
		try {
241
		try {
242
			project.create(null);
242
			project.create(null);
243
			project.open(null);
243
			project.open(null);
244
			while (dotProject.isSynchronized(IResource.DEPTH_ZERO)) {
244
			touchInFilesystem(dotProject);
245
				try {
246
					Thread.sleep(100);
247
				} catch (InterruptedException e) {
248
				}
249
				dotProject.getLocation().toFile().setLastModified(System.currentTimeMillis());
250
			}
251
			project.refreshLocal(IResource.DEPTH_INFINITE, null);
245
			project.refreshLocal(IResource.DEPTH_INFINITE, null);
252
		} catch (CoreException e) {
246
		} catch (CoreException e) {
253
			fail("0.99", e);
247
			fail("0.99", e);

Return to bug 303517