author | dadubrow |
Tue, 02 Jun 2009 09:59:27 -0500 | |
changeset 16 | 06d88bb6aac0 |
parent 12 | 063eb66097dc |
permissions | -rw-r--r-- |
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
7 |
* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
8 |
* Contributors: |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
9 |
* IBM Corporation - initial API and implementation |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
10 |
* Martin Oberhuber (Wind River) - [210664] descriptionChanged(): ignore LF style |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
11 |
*******************************************************************************/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
12 |
package org.eclipse.core.internal.localstore; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
13 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
14 |
import java.io.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
15 |
import java.net.URI; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
16 |
import java.util.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
17 |
import org.eclipse.core.filesystem.*; |
16 | 18 |
import org.eclipse.core.internal.refresh.RefreshJob; |
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
19 |
import org.eclipse.core.internal.resources.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
20 |
import org.eclipse.core.internal.resources.File; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
21 |
import org.eclipse.core.internal.utils.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
22 |
import org.eclipse.core.resources.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
23 |
import org.eclipse.core.runtime.*; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
24 |
import org.eclipse.osgi.util.NLS; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
25 |
import org.xml.sax.InputSource; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
26 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
27 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
28 |
* Manages the synchronization between the workspace's view and the file system. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
29 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
30 |
public class FileSystemResourceManager implements ICoreConstants, IManager { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
31 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
32 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
33 |
* The history store is initialized lazily - always use the accessor method |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
34 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
35 |
protected IHistoryStore _historyStore; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
36 |
protected Workspace workspace; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
37 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
38 |
public FileSystemResourceManager(Workspace workspace) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
39 |
this.workspace = workspace; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
40 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
41 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
42 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
43 |
* Returns the workspace paths of all resources that may correspond to |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
44 |
* the given file system location. Returns an empty ArrayList if there are no |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
45 |
* such paths. This method does not consider whether resources actually |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
46 |
* exist at the given locations. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
47 |
* <p> |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
48 |
* The workspace paths of {@link IResource#HIDDEN} project and resources |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
49 |
* located in {@link IResource#HIDDEN} projects won't be added to the result. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
50 |
* </p> |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
51 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
52 |
protected ArrayList allPathsForLocation(URI inputLocation) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
53 |
URI location = FileUtil.canonicalURI(inputLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
54 |
final boolean isFileLocation = EFS.SCHEME_FILE.equals(inputLocation.getScheme()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
55 |
final IWorkspaceRoot root = getWorkspace().getRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
56 |
final ArrayList results = new ArrayList(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
57 |
if (URIUtil.equals(location, root.getLocationURI())) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
58 |
//there can only be one resource at the workspace root's location |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
59 |
results.add(Path.ROOT); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
60 |
return results; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
61 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
62 |
IPathVariableManager varMan = workspace.getPathVariableManager(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
63 |
IProject[] projects = root.getProjects(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
64 |
for (int i = 0; i < projects.length; i++) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
65 |
IProject project = projects[i]; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
66 |
//check the project location |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
67 |
URI testLocation = project.getLocationURI(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
68 |
if (testLocation == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
69 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
70 |
// if we are looking for file: locations try to get a file: location for this project |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
71 |
if (isFileLocation && !EFS.SCHEME_FILE.equals(testLocation.getScheme())) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
72 |
testLocation = getFileURI(testLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
73 |
if (testLocation == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
74 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
75 |
URI relative = testLocation.relativize(location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
76 |
if (!relative.isAbsolute() && !relative.equals(testLocation)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
77 |
IPath suffix = new Path(relative.getPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
78 |
results.add(project.getFullPath().append(suffix)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
79 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
80 |
ProjectDescription description = ((Project) project).internalGetDescription(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
81 |
if (description == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
82 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
83 |
HashMap links = description.getLinks(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
84 |
if (links == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
85 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
86 |
for (Iterator it = links.values().iterator(); it.hasNext();) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
87 |
LinkDescription link = (LinkDescription) it.next(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
88 |
testLocation = varMan.resolveURI(link.getLocationURI()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
89 |
// if we are looking for file: locations try to get a file: location for this link |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
90 |
if (isFileLocation && !EFS.SCHEME_FILE.equals(testLocation.getScheme())) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
91 |
testLocation = getFileURI(testLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
92 |
if (testLocation == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
93 |
continue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
94 |
relative = testLocation.relativize(location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
95 |
if (!relative.isAbsolute() && !relative.equals(testLocation)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
96 |
IPath suffix = new Path(relative.getPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
97 |
results.add(project.getFullPath().append(link.getProjectRelativePath()).append(suffix)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
98 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
99 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
100 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
101 |
return results; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
102 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
103 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
104 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
105 |
* Tries to obtain a file URI for the given URI. Returns <code>null</code> if the file system associated |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
106 |
* to the URI scheme does not map to the local file system. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
107 |
* @param locationURI the URI to convert |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
108 |
* @return a file URI or <code>null</code> |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
109 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
110 |
private URI getFileURI(URI locationURI) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
111 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
112 |
IFileStore testLocationStore = EFS.getStore(locationURI); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
113 |
java.io.File storeAsFile = testLocationStore.toLocalFile(EFS.NONE, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
114 |
if (storeAsFile != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
115 |
return URIUtil.toURI(storeAsFile.getAbsolutePath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
116 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
117 |
// we don't know such file system or some other failure, just return null |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
118 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
119 |
return null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
120 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
121 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
122 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
123 |
* Returns all resources that correspond to the given file system location, |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
124 |
* including resources under linked resources. Returns an empty array |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
125 |
* if there are no corresponding resources. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
126 |
* @param location the file system location |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
127 |
* @param files resources that may exist below the project level can |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
128 |
* be either files or folders. If this parameter is true, files will be returned, |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
129 |
* otherwise containers will be returned. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
130 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
131 |
public IResource[] allResourcesFor(URI location, boolean files) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
132 |
ArrayList result = allPathsForLocation(location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
133 |
int count = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
134 |
for (int i = 0, imax = result.size(); i < imax; i++) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
135 |
//replace the path in the list with the appropriate resource type |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
136 |
IResource resource = resourceFor((IPath) result.get(i), files); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
137 |
result.set(i, resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
138 |
//count actual resources - some paths won't have a corresponding resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
139 |
if (resource != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
140 |
count++; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
141 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
142 |
//convert to array and remove null elements |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
143 |
IResource[] toReturn = files ? (IResource[]) new IFile[count] : (IResource[]) new IContainer[count]; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
144 |
count = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
145 |
for (Iterator it = result.iterator(); it.hasNext();) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
146 |
IResource resource = (IResource) it.next(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
147 |
if (resource != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
148 |
toReturn[count++] = resource; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
149 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
150 |
return toReturn; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
151 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
152 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
153 |
/* (non-javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
154 |
* @see IResource.getResourceAttributes |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
155 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
156 |
public ResourceAttributes attributes(IResource resource) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
157 |
IFileStore store = getStore(resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
158 |
IFileInfo fileInfo = store.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
159 |
if (!fileInfo.exists()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
160 |
return null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
161 |
return FileUtil.fileInfoToAttributes(fileInfo); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
162 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
163 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
164 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
165 |
* Returns a container for the given file system location or null if there |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
166 |
* is no mapping for this path. If the path has only one segment, then an |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
167 |
* <code>IProject</code> is returned. Otherwise, the returned object |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
168 |
* is a <code>IFolder</code>. This method does NOT check the existence |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
169 |
* of a folder in the given location. Location cannot be null. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
170 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
171 |
public IContainer containerForLocation(IPath location) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
172 |
IPath path = pathForLocation(location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
173 |
return path == null ? null : (IContainer) resourceFor(path, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
174 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
175 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
176 |
public void copy(IResource target, IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
177 |
monitor = Policy.monitorFor(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
178 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
179 |
int totalWork = ((Resource) target).countResources(IResource.DEPTH_INFINITE, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
180 |
String title = NLS.bind(Messages.localstore_copying, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
181 |
monitor.beginTask(title, totalWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
182 |
IFileStore destinationStore = getStore(destination); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
183 |
if (destinationStore.fetchInfo().exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
184 |
String message = NLS.bind(Messages.localstore_resourceExists, destination.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
185 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, destination.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
186 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
187 |
getHistoryStore().copyHistory(target, destination, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
188 |
CopyVisitor visitor = new CopyVisitor(target, destination, updateFlags, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
189 |
UnifiedTree tree = new UnifiedTree(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
190 |
tree.accept(visitor, IResource.DEPTH_INFINITE); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
191 |
IStatus status = visitor.getStatus(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
192 |
if (!status.isOK()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
193 |
throw new ResourceException(status); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
194 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
195 |
monitor.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
196 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
197 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
198 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
199 |
public void delete(IResource target, int flags, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
200 |
monitor = Policy.monitorFor(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
201 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
202 |
Resource resource = (Resource) target; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
203 |
final int deleteWork = resource.countResources(IResource.DEPTH_INFINITE, false) * 2; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
204 |
boolean force = (flags & IResource.FORCE) != 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
205 |
int refreshWork = 0; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
206 |
if (!force) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
207 |
refreshWork = Math.min(deleteWork, 100); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
208 |
String title = NLS.bind(Messages.localstore_deleting, resource.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
209 |
monitor.beginTask(title, deleteWork + refreshWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
210 |
monitor.subTask(""); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
211 |
MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, Messages.localstore_deleteProblem, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
212 |
List skipList = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
213 |
UnifiedTree tree = new UnifiedTree(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
214 |
if (!force) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
215 |
IProgressMonitor sub = Policy.subMonitorFor(monitor, refreshWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
216 |
sub.beginTask("", 1000); //$NON-NLS-1$ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
217 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
218 |
CollectSyncStatusVisitor refreshVisitor = new CollectSyncStatusVisitor(Messages.localstore_deleteProblem, sub); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
219 |
refreshVisitor.setIgnoreLocalDeletions(true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
220 |
tree.accept(refreshVisitor, IResource.DEPTH_INFINITE); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
221 |
status.merge(refreshVisitor.getSyncStatus()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
222 |
skipList = refreshVisitor.getAffectedResources(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
223 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
224 |
sub.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
225 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
226 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
227 |
DeleteVisitor deleteVisitor = new DeleteVisitor(skipList, flags, monitor, deleteWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
228 |
tree.accept(deleteVisitor, IResource.DEPTH_INFINITE); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
229 |
status.merge(deleteVisitor.getStatus()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
230 |
if (!status.isOK()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
231 |
throw new ResourceException(status); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
232 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
233 |
monitor.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
234 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
235 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
236 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
237 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
238 |
* Returns true if the description on disk is different from the given byte array, |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
239 |
* and false otherwise. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
240 |
* Since org.eclipse.core.resources 3.4.1 differences in line endings (CR, LF, CRLF) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
241 |
* are not considered. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
242 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
243 |
private boolean descriptionChanged(IFile descriptionFile, byte[] newContents) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
244 |
InputStream oldStream = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
245 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
246 |
//buffer size: twice the description length, but maximum 8KB |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
247 |
int bufsize = newContents.length > 4096 ? 8192 : newContents.length * 2; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
248 |
oldStream = new BufferedInputStream(descriptionFile.getContents(true), bufsize); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
249 |
InputStream newStream = new ByteArrayInputStream(newContents); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
250 |
//Compare Streams char by char, ignoring line endings. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
251 |
int newChar = newStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
252 |
int oldChar = oldStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
253 |
while (newChar >= 0 && oldChar >= 0) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
254 |
boolean newGotLine = (newChar == '\r' || newChar == '\n'); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
255 |
boolean oldGotLine = (oldChar == '\r' || oldChar == '\n'); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
256 |
if (newGotLine || oldGotLine) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
257 |
//Ignore newlines if in both streams |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
258 |
if (newGotLine != oldGotLine) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
259 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
260 |
while (newChar == '\r' || newChar == '\n') |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
261 |
newChar = newStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
262 |
while (oldChar == '\r' || oldChar == '\n') |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
263 |
oldChar = oldStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
264 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
265 |
//Now we are pointing to a char that's not a newline. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
266 |
if (newChar != oldChar) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
267 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
268 |
newChar = newStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
269 |
oldChar = oldStream.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
270 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
271 |
//test for excess data in one stream |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
272 |
if (newChar >= 0 || oldChar >= 0) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
273 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
274 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
275 |
} catch (Exception e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
276 |
Policy.log(e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
277 |
//if we failed to compare, just write the new contents |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
278 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
279 |
FileUtil.safeClose(oldStream); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
280 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
281 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
282 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
283 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
284 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
285 |
* @deprecated |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
286 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
287 |
public int doGetEncoding(IFileStore store) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
288 |
InputStream input = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
289 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
290 |
input = store.openInputStream(EFS.NONE, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
291 |
int first = input.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
292 |
int second = input.read(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
293 |
if (first == -1 || second == -1) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
294 |
return IFile.ENCODING_UNKNOWN; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
295 |
first &= 0xFF;//converts unsigned byte to int |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
296 |
second &= 0xFF; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
297 |
//look for the UTF-16 Byte Order Mark (BOM) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
298 |
if (first == 0xFE && second == 0xFF) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
299 |
return IFile.ENCODING_UTF_16BE; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
300 |
if (first == 0xFF && second == 0xFE) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
301 |
return IFile.ENCODING_UTF_16LE; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
302 |
int third = (input.read() & 0xFF); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
303 |
if (third == -1) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
304 |
return IFile.ENCODING_UNKNOWN; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
305 |
//look for the UTF-8 BOM |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
306 |
if (first == 0xEF && second == 0xBB && third == 0xBF) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
307 |
return IFile.ENCODING_UTF_8; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
308 |
return IFile.ENCODING_UNKNOWN; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
309 |
} catch (IOException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
310 |
String message = NLS.bind(Messages.localstore_couldNotRead, store.toString()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
311 |
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, null, message, e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
312 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
313 |
FileUtil.safeClose(input); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
314 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
315 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
316 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
317 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
318 |
* Optimized sync check for files. Returns true if the file exists and is in sync, and false |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
319 |
* otherwise. The intent is to let the default implementation handle the complex |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
320 |
* cases like gender change, case variants, etc. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
321 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
322 |
public boolean fastIsSynchronized(File target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
323 |
ResourceInfo info = target.getResourceInfo(false, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
324 |
if (target.exists(target.getFlags(info), true)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
325 |
IFileInfo fileInfo = getStore(target).fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
326 |
if (!fileInfo.isDirectory() && info.getLocalSyncInfo() == fileInfo.getLastModified()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
327 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
328 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
329 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
330 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
331 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
332 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
333 |
* Returns an IFile for the given file system location or null if there |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
334 |
* is no mapping for this path. This method does NOT check the existence |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
335 |
* of a file in the given location. Location cannot be null. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
336 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
337 |
public IFile fileForLocation(IPath location) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
338 |
IPath path = pathForLocation(location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
339 |
return path == null ? null : (IFile) resourceFor(path, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
340 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
341 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
342 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
343 |
* @deprecated |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
344 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
345 |
public int getEncoding(File target) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
346 |
// thread safety: (the location can be null if the project for this file does not exist) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
347 |
IFileStore store = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
348 |
if (!store.fetchInfo().exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
349 |
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
350 |
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
351 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
352 |
return doGetEncoding(store); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
353 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
354 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
355 |
public IHistoryStore getHistoryStore() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
356 |
if (_historyStore == null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
357 |
IPath location = getWorkspace().getMetaArea().getHistoryStoreLocation(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
358 |
location.toFile().mkdirs(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
359 |
_historyStore = ResourcesCompatibilityHelper.createHistoryStore(location, 256); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
360 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
361 |
return _historyStore; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
362 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
363 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
364 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
365 |
* Returns the real name of the resource on disk. Returns null if no local |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
366 |
* file exists by that name. This is useful when dealing with |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
367 |
* case insensitive file systems. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
368 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
369 |
public String getLocalName(IFileStore target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
370 |
return target.fetchInfo().getName(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
371 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
372 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
373 |
protected IPath getProjectDefaultLocation(IProject project) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
374 |
return workspace.getRoot().getLocation().append(project.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
375 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
376 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
377 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
378 |
* Never returns null |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
379 |
* @param target |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
380 |
* @return The file store for this resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
381 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
382 |
public IFileStore getStore(IResource target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
383 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
384 |
return getStoreRoot(target).createStore(target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
385 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
386 |
//callers aren't expecting failure here, so return null file system |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
387 |
return EFS.getNullFileSystem().getStore(target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
388 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
389 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
390 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
391 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
392 |
* Returns the file store root for the provided resource. Never returns null. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
393 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
394 |
private FileStoreRoot getStoreRoot(IResource target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
395 |
ResourceInfo info = workspace.getResourceInfo(target.getFullPath(), true, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
396 |
FileStoreRoot root; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
397 |
if (info != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
398 |
root = info.getFileStoreRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
399 |
if (root != null && root.isValid()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
400 |
return root; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
401 |
if (info.isSet(ICoreConstants.M_LINK)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
402 |
ProjectDescription description = ((Project) target.getProject()).internalGetDescription(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
403 |
if (description != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
404 |
final URI linkLocation = description.getLinkLocationURI(target.getProjectRelativePath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
405 |
//if we can't determine the link location, fall through to parent resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
406 |
if (linkLocation != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
407 |
setLocation(target, info, linkLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
408 |
return info.getFileStoreRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
409 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
410 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
411 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
412 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
413 |
final IContainer parent = target.getParent(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
414 |
if (parent == null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
415 |
//this is the root, so we know where this must be located |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
416 |
//initialize root location |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
417 |
info = workspace.getResourceInfo(Path.ROOT, false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
418 |
final IWorkspaceRoot rootResource = workspace.getRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
419 |
setLocation(rootResource, info, URIUtil.toURI(rootResource.getLocation())); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
420 |
return info.getFileStoreRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
421 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
422 |
root = getStoreRoot(parent); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
423 |
if (info != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
424 |
info.setFileStoreRoot(root); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
425 |
return root; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
426 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
427 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
428 |
protected Workspace getWorkspace() { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
429 |
return workspace; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
430 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
431 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
432 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
433 |
* Returns whether the project has any local content on disk. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
434 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
435 |
public boolean hasSavedContent(IProject project) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
436 |
return getStore(project).fetchInfo().exists(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
437 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
438 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
439 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
440 |
* Returns whether the project has a project description file on disk. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
441 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
442 |
public boolean hasSavedDescription(IProject project) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
443 |
return getStore(project).getChild(IProjectDescription.DESCRIPTION_FILE_NAME).fetchInfo().exists(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
444 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
445 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
446 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
447 |
* Initializes the file store for a resource. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
448 |
* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
449 |
* @param target The resource to initialize the file store for. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
450 |
* @param location the File system location of this resource on disk |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
451 |
* @return The file store for the provided resource |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
452 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
453 |
private IFileStore initializeStore(IResource target, URI location) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
454 |
ResourceInfo info = ((Resource) target).getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
455 |
setLocation(target, info, location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
456 |
FileStoreRoot root = getStoreRoot(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
457 |
return root.createStore(target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
458 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
459 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
460 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
461 |
* The target must exist in the workspace. This method must only ever |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
462 |
* be called from Project.writeDescription(), because that method ensures |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
463 |
* that the description isn't then immediately discovered as a new change. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
464 |
* @return true if a new description was written, and false if it wasn't written |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
465 |
* because it was unchanged |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
466 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
467 |
public boolean internalWrite(IProject target, IProjectDescription description, int updateFlags, boolean hasPublicChanges, boolean hasPrivateChanges) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
468 |
//write the project's private description to the metadata area |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
469 |
if (hasPrivateChanges) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
470 |
getWorkspace().getMetaArea().writePrivateDescription(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
471 |
if (!hasPublicChanges) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
472 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
473 |
//can't do anything if there's no description |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
474 |
if (description == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
475 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
476 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
477 |
//write the model to a byte array |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
478 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
479 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
480 |
new ModelObjectWriter().write(description, out); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
481 |
} catch (IOException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
482 |
String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
483 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
484 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
485 |
byte[] newContents = out.toByteArray(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
486 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
487 |
//write the contents to the IFile that represents the description |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
488 |
IFile descriptionFile = target.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
489 |
if (!descriptionFile.exists()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
490 |
workspace.createResource(descriptionFile, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
491 |
else { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
492 |
//if the description has not changed, don't write anything |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
493 |
if (!descriptionChanged(descriptionFile, newContents)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
494 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
495 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
496 |
ByteArrayInputStream in = new ByteArrayInputStream(newContents); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
497 |
IFileStore descriptionFileStore = ((Resource) descriptionFile).getStore(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
498 |
IFileInfo fileInfo = descriptionFileStore.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
499 |
if (fileInfo.getAttribute(EFS.ATTRIBUTE_READ_ONLY)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
500 |
IStatus result = getWorkspace().validateEdit(new IFile[] {descriptionFile}, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
501 |
if (!result.isOK()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
502 |
throw new ResourceException(result); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
503 |
// re-read the file info in case the file attributes were modified |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
504 |
fileInfo = descriptionFileStore.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
505 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
506 |
//write the project description file (don't use API because scheduling rule might not match) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
507 |
write(descriptionFile, in, fileInfo, IResource.FORCE, false, Policy.monitorFor(null)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
508 |
workspace.getAliasManager().updateAliases(descriptionFile, getStore(descriptionFile), IResource.DEPTH_ZERO, Policy.monitorFor(null)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
509 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
510 |
//update the timestamp on the project as well so we know when it has |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
511 |
//been changed from the outside |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
512 |
long lastModified = ((Resource) descriptionFile).getResourceInfo(false, false).getLocalSyncInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
513 |
ResourceInfo info = ((Resource) target).getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
514 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
515 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
516 |
//for backwards compatibility, ensure the old .prj file is deleted |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
517 |
getWorkspace().getMetaArea().clearOldDescription(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
518 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
519 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
520 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
521 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
522 |
* Returns true if the given project's description is synchronized with |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
523 |
* the project description file on disk, and false otherwise. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
524 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
525 |
public boolean isDescriptionSynchronized(IProject target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
526 |
//sync info is stored on the description file, and on project info. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
527 |
//when the file is changed by someone else, the project info modification |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
528 |
//stamp will be out of date |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
529 |
IFile descriptionFile = target.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
530 |
ResourceInfo projectInfo = ((Resource) target).getResourceInfo(false, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
531 |
if (projectInfo == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
532 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
533 |
return projectInfo.getLocalSyncInfo() == getStore(descriptionFile).fetchInfo().getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
534 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
535 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
536 |
/* (non-Javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
537 |
* Returns true if the given resource is synchronized with the file system |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
538 |
* to the given depth. Returns false otherwise. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
539 |
* |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
540 |
* @see IResource#isSynchronized(int) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
541 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
542 |
public boolean isSynchronized(IResource target, int depth) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
543 |
switch (target.getType()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
544 |
case IResource.ROOT : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
545 |
if (depth == IResource.DEPTH_ZERO) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
546 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
547 |
//check sync on child projects. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
548 |
depth = depth == IResource.DEPTH_ONE ? IResource.DEPTH_ZERO : depth; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
549 |
IProject[] projects = ((IWorkspaceRoot) target).getProjects(IContainer.INCLUDE_HIDDEN); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
550 |
for (int i = 0; i < projects.length; i++) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
551 |
if (!isSynchronized(projects[i], depth)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
552 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
553 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
554 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
555 |
case IResource.PROJECT : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
556 |
if (!target.isAccessible()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
557 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
558 |
break; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
559 |
case IResource.FILE : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
560 |
if (fastIsSynchronized((File) target)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
561 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
562 |
break; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
563 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
564 |
IsSynchronizedVisitor visitor = new IsSynchronizedVisitor(Policy.monitorFor(null)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
565 |
UnifiedTree tree = new UnifiedTree(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
566 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
567 |
tree.accept(visitor, depth); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
568 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
569 |
Policy.log(e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
570 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
571 |
} catch (IsSynchronizedVisitor.ResourceChangedException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
572 |
//visitor throws an exception if out of sync |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
573 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
574 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
575 |
return true; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
576 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
577 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
578 |
public void link(Resource target, URI location, IFileInfo fileInfo) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
579 |
initializeStore(target, location); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
580 |
ResourceInfo info = target.getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
581 |
long lastModified = fileInfo == null ? 0 : fileInfo.getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
582 |
if (lastModified == 0) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
583 |
info.clearModificationStamp(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
584 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
585 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
586 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
587 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
588 |
* Returns the resolved, absolute file system location of the given resource. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
589 |
* Returns null if the location could not be resolved. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
590 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
591 |
public IPath locationFor(IResource target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
592 |
return getStoreRoot(target).localLocation(target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
593 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
594 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
595 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
596 |
* Returns the resolved, absolute file system location of the given resource. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
597 |
* Returns null if the location could not be resolved. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
598 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
599 |
public URI locationURIFor(IResource target) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
600 |
return getStoreRoot(target).computeURI(target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
601 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
602 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
603 |
public void move(IResource source, IFileStore destination, int flags, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
604 |
//TODO figure out correct semantics for case where destination exists on disk |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
605 |
getStore(source).move(destination, EFS.NONE, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
606 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
607 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
608 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
609 |
* Returns a resource path to the given local location. Returns null if |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
610 |
* it is not under a project's location. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
611 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
612 |
protected IPath pathForLocation(IPath location) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
613 |
if (workspace.getRoot().getLocation().equals(location)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
614 |
return Path.ROOT; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
615 |
IProject[] projects = getWorkspace().getRoot().getProjects(IContainer.INCLUDE_HIDDEN); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
616 |
for (int i = 0; i < projects.length; i++) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
617 |
IProject project = projects[i]; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
618 |
IPath projectLocation = project.getLocation(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
619 |
if (projectLocation != null && projectLocation.isPrefixOf(location)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
620 |
int segmentsToRemove = projectLocation.segmentCount(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
621 |
return project.getFullPath().append(location.removeFirstSegments(segmentsToRemove)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
622 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
623 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
624 |
return null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
625 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
626 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
627 |
public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
628 |
IFileStore store = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
629 |
if (!force) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
630 |
final IFileInfo fileInfo = store.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
631 |
if (!fileInfo.exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
632 |
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
633 |
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
634 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
635 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
636 |
int flags = ((Resource) target).getFlags(info); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
637 |
((Resource) target).checkExists(flags, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
638 |
if (fileInfo.getLastModified() != info.getLocalSyncInfo()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
639 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
640 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
641 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
642 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
643 |
return store.openInputStream(EFS.NONE, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
644 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
645 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
646 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
647 |
* Reads and returns the project description for the given project. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
648 |
* Never returns null. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
649 |
* @param target the project whose description should be read. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
650 |
* @param creation true if this project is just being created, in which |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
651 |
* case the private project information (including the location) needs to be read |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
652 |
* from disk as well. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
653 |
* @exception CoreException if there was any failure to read the project |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
654 |
* description, or if the description was missing. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
655 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
656 |
public ProjectDescription read(IProject target, boolean creation) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
657 |
//read the project location if this project is being created |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
658 |
URI projectLocation = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
659 |
ProjectDescription privateDescription = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
660 |
if (creation) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
661 |
privateDescription = new ProjectDescription(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
662 |
getWorkspace().getMetaArea().readPrivateDescription(target, privateDescription); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
663 |
projectLocation = privateDescription.getLocationURI(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
664 |
} else { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
665 |
IProjectDescription description = ((Project) target).internalGetDescription(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
666 |
if (description != null && description.getLocationURI() != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
667 |
projectLocation = description.getLocationURI(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
668 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
669 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
670 |
final boolean isDefaultLocation = projectLocation == null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
671 |
if (isDefaultLocation) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
672 |
projectLocation = URIUtil.toURI(getProjectDefaultLocation(target)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
673 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
674 |
IFileStore projectStore = initializeStore(target, projectLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
675 |
IFileStore descriptionStore = projectStore.getChild(IProjectDescription.DESCRIPTION_FILE_NAME); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
676 |
ProjectDescription description = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
677 |
//hold onto any exceptions until after sync info is updated, then throw it |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
678 |
ResourceException error = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
679 |
InputStream in = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
680 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
681 |
in = new BufferedInputStream(descriptionStore.openInputStream(EFS.NONE, null)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
682 |
description = new ProjectDescriptionReader(target).read(new InputSource(in)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
683 |
} catch (CoreException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
684 |
//try the legacy location in the meta area |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
685 |
description = getWorkspace().getMetaArea().readOldDescription(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
686 |
if (description != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
687 |
return description; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
688 |
if (!descriptionStore.fetchInfo().exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
689 |
String msg = NLS.bind(Messages.resources_missingProjectMeta, target.getName()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
690 |
throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, target.getFullPath(), msg, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
691 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
692 |
String msg = NLS.bind(Messages.resources_readProjectMeta, target.getName()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
693 |
error = new ResourceException(IResourceStatus.FAILED_READ_METADATA, target.getFullPath(), msg, e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
694 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
695 |
FileUtil.safeClose(in); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
696 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
697 |
if (error == null && description == null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
698 |
String msg = NLS.bind(Messages.resources_readProjectMeta, target.getName()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
699 |
error = new ResourceException(IResourceStatus.FAILED_READ_METADATA, target.getFullPath(), msg, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
700 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
701 |
if (description != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
702 |
//don't trust the project name in the description file |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
703 |
description.setName(target.getName()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
704 |
if (!isDefaultLocation) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
705 |
description.setLocationURI(projectLocation); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
706 |
if (creation && privateDescription != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
707 |
description.setDynamicReferences(privateDescription.getDynamicReferences(false)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
708 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
709 |
long lastModified = descriptionStore.fetchInfo().getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
710 |
IFile descriptionFile = target.getFile(IProjectDescription.DESCRIPTION_FILE_NAME); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
711 |
//don't get a mutable copy because we might be in restore which isn't an operation |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
712 |
//it doesn't matter anyway because local sync info is not included in deltas |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
713 |
ResourceInfo info = ((Resource) descriptionFile).getResourceInfo(false, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
714 |
if (info == null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
715 |
//create a new resource on the sly -- don't want to start an operation |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
716 |
info = getWorkspace().createResource(descriptionFile, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
717 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
718 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
719 |
//if the project description has changed between sessions, let it remain |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
720 |
//out of sync -- that way link changes will be reconciled on next refresh |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
721 |
if (!creation) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
722 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
723 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
724 |
//update the timestamp on the project as well so we know when it has |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
725 |
//been changed from the outside |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
726 |
info = ((Resource) target).getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
727 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
728 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
729 |
if (error != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
730 |
throw error; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
731 |
return description; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
732 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
733 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
734 |
public boolean refresh(IResource target, int depth, boolean updateAliases, IProgressMonitor monitor) throws CoreException { |
16 | 735 |
long startTimeMs = System.currentTimeMillis(); |
736 |
boolean result = refreshImpl(target, depth, updateAliases, monitor); |
|
737 |
if (!RefreshJob.isRefreshing()) { |
|
738 |
long totalMs = System.currentTimeMillis() - startTimeMs; |
|
739 |
StringBuffer sb = new StringBuffer(); |
|
740 |
sb.append("Refresh called on "); |
|
741 |
sb.append(target.getFullPath()); |
|
742 |
sb.append(" completed in : "); |
|
743 |
sb.append(totalMs); |
|
744 |
sb.append("ms"); |
|
745 |
ResourcesPlugin.writeRefreshLog(sb.toString()); |
|
746 |
StackTraceElement[] trace = Thread.currentThread().getStackTrace(); |
|
747 |
for (int i = 2; i < trace.length; i++) { // skip the getStackTrace and dump calls |
|
748 |
ResourcesPlugin.writeRefreshLog("\tat " + trace[i]); |
|
749 |
} |
|
750 |
} |
|
751 |
return result; |
|
752 |
} |
|
753 |
||
754 |
private boolean refreshImpl(IResource target, int depth, boolean updateAliases, IProgressMonitor monitor) throws CoreException { |
|
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
755 |
switch (target.getType()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
756 |
case IResource.ROOT : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
757 |
return refreshRoot((IWorkspaceRoot) target, depth, updateAliases, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
758 |
case IResource.PROJECT : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
759 |
if (!target.isAccessible()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
760 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
761 |
//fall through |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
762 |
case IResource.FOLDER : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
763 |
case IResource.FILE : |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
764 |
return refreshResource(target, depth, updateAliases, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
765 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
766 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
767 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
768 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
769 |
protected boolean refreshResource(IResource target, int depth, boolean updateAliases, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
770 |
monitor = Policy.monitorFor(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
771 |
int totalWork = RefreshLocalVisitor.TOTAL_WORK; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
772 |
String title = NLS.bind(Messages.localstore_refreshing, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
773 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
774 |
monitor.beginTask(title, totalWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
775 |
RefreshLocalVisitor visitor = updateAliases ? new RefreshLocalAliasVisitor(monitor) : new RefreshLocalVisitor(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
776 |
IFileStore fileStore = ((Resource) target).getStore(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
777 |
//try to get all info in one shot, if file system supports it |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
778 |
IFileTree fileTree = fileStore.getFileSystem().fetchFileTree(fileStore, new SubProgressMonitor(monitor, 0)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
779 |
UnifiedTree tree = fileTree == null ? new UnifiedTree(target) : new UnifiedTree(target, fileTree); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
780 |
tree.accept(visitor, depth); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
781 |
IStatus result = visitor.getErrorStatus(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
782 |
if (!result.isOK()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
783 |
throw new ResourceException(result); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
784 |
return visitor.resourcesChanged(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
785 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
786 |
monitor.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
787 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
788 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
789 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
790 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
791 |
* Synchronizes the entire workspace with the local file system. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
792 |
* The current implementation does this by synchronizing each of the |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
793 |
* projects currently in the workspace. A better implementation may |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
794 |
* be possible. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
795 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
796 |
protected boolean refreshRoot(IWorkspaceRoot target, int depth, boolean updateAliases, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
797 |
monitor = Policy.monitorFor(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
798 |
IProject[] projects = target.getProjects(IContainer.INCLUDE_HIDDEN); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
799 |
int totalWork = projects.length; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
800 |
String title = Messages.localstore_refreshingRoot; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
801 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
802 |
monitor.beginTask(title, totalWork); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
803 |
// if doing depth zero, there is nothing to do (can't refresh the root). |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
804 |
// Note that we still need to do the beginTask, done pair. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
805 |
if (depth == IResource.DEPTH_ZERO) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
806 |
return false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
807 |
boolean changed = false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
808 |
// drop the depth by one level since processing the root counts as one level. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
809 |
depth = depth == IResource.DEPTH_ONE ? IResource.DEPTH_ZERO : depth; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
810 |
for (int i = 0; i < projects.length; i++) |
16 | 811 |
changed |= refreshImpl(projects[i], depth, updateAliases, Policy.subMonitorFor(monitor, 1)); |
12
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
812 |
return changed; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
813 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
814 |
monitor.done(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
815 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
816 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
817 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
818 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
819 |
* Returns the resource corresponding to the given workspace path. The |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
820 |
* "files" parameter is used for paths of two or more segments. If true, |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
821 |
* a file is returned, otherwise a folder is returned. Returns null if files is true |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
822 |
* and the path is not of sufficient length. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
823 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
824 |
protected IResource resourceFor(IPath path, boolean files) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
825 |
int numSegments = path.segmentCount(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
826 |
if (files && numSegments < ICoreConstants.MINIMUM_FILE_SEGMENT_LENGTH) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
827 |
return null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
828 |
IWorkspaceRoot root = getWorkspace().getRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
829 |
if (path.isRoot()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
830 |
return root; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
831 |
if (numSegments == 1) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
832 |
return root.getProject(path.segment(0)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
833 |
return files ? (IResource) root.getFile(path) : (IResource) root.getFolder(path); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
834 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
835 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
836 |
/* (non-javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
837 |
* @see IResouce.setLocalTimeStamp |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
838 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
839 |
public long setLocalTimeStamp(IResource target, ResourceInfo info, long value) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
840 |
IFileStore store = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
841 |
IFileInfo fileInfo = store.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
842 |
fileInfo.setLastModified(value); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
843 |
store.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
844 |
//actual value may be different depending on file system granularity |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
845 |
fileInfo = store.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
846 |
long actualValue = fileInfo.getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
847 |
updateLocalSync(info, actualValue); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
848 |
return actualValue; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
849 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
850 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
851 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
852 |
* The storage location for a resource has changed; update the location. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
853 |
* @param target |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
854 |
* @param info |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
855 |
* @param location |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
856 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
857 |
public void setLocation(IResource target, ResourceInfo info, URI location) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
858 |
FileStoreRoot oldRoot = info.getFileStoreRoot(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
859 |
if (location != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
860 |
info.setFileStoreRoot(new FileStoreRoot(location, target.getFullPath())); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
861 |
} else { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
862 |
//project is in default location so clear the store root |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
863 |
info.setFileStoreRoot(null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
864 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
865 |
if (oldRoot != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
866 |
oldRoot.setValid(false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
867 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
868 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
869 |
/* (non-javadoc) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
870 |
* @see IResource.setResourceAttributes |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
871 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
872 |
public void setResourceAttributes(IResource resource, ResourceAttributes attributes) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
873 |
IFileStore store = getStore(resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
874 |
//when the executable bit is changed on a folder a refresh is required |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
875 |
boolean refresh = false; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
876 |
if (resource instanceof IContainer && ((store.getFileSystem().attributes() & EFS.ATTRIBUTE_EXECUTABLE) != 0)) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
877 |
refresh = store.fetchInfo().getAttribute(EFS.ATTRIBUTE_EXECUTABLE) != attributes.isExecutable(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
878 |
store.putInfo(FileUtil.attributesToFileInfo(attributes), EFS.SET_ATTRIBUTES, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
879 |
//must refresh in the background because we are not inside an operation |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
880 |
if (refresh) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
881 |
workspace.getRefreshManager().refresh(resource); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
882 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
883 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
884 |
public void shutdown(IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
885 |
if (_historyStore != null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
886 |
_historyStore.shutdown(monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
887 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
888 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
889 |
public void startup(IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
890 |
//nothing to do |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
891 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
892 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
893 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
894 |
* The ResourceInfo must be mutable. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
895 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
896 |
public void updateLocalSync(ResourceInfo info, long localSyncInfo) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
897 |
info.setLocalSyncInfo(localSyncInfo); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
898 |
if (localSyncInfo == I_NULL_SYNC_INFO) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
899 |
info.clear(M_LOCAL_EXISTS); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
900 |
else |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
901 |
info.set(M_LOCAL_EXISTS); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
902 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
903 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
904 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
905 |
* The target must exist in the workspace. The content InputStream is |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
906 |
* closed even if the method fails. If the force flag is false we only write |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
907 |
* the file if it does not exist or if it is already local and the timestamp |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
908 |
* has NOT changed since last synchronization, otherwise a CoreException |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
909 |
* is thrown. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
910 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
911 |
public void write(IFile target, InputStream content, IFileInfo fileInfo, int updateFlags, boolean append, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
912 |
monitor = Policy.monitorFor(null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
913 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
914 |
IFileStore store = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
915 |
if (fileInfo.getAttribute(EFS.ATTRIBUTE_READ_ONLY)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
916 |
String message = NLS.bind(Messages.localstore_couldNotWriteReadOnly, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
917 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
918 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
919 |
long lastModified = fileInfo.getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
920 |
if (BitMask.isSet(updateFlags, IResource.FORCE)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
921 |
if (append && !target.isLocal(IResource.DEPTH_ZERO) && !fileInfo.exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
922 |
// force=true, local=false, existsInFileSystem=false |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
923 |
String message = NLS.bind(Messages.resources_mustBeLocal, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
924 |
throw new ResourceException(IResourceStatus.RESOURCE_NOT_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
925 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
926 |
} else { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
927 |
if (target.isLocal(IResource.DEPTH_ZERO)) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
928 |
// test if timestamp is the same since last synchronization |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
929 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
930 |
if (lastModified != info.getLocalSyncInfo()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
931 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
932 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
933 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
934 |
} else { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
935 |
if (fileInfo.exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
936 |
String message = NLS.bind(Messages.localstore_resourceExists, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
937 |
throw new ResourceException(IResourceStatus.EXISTS_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
938 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
939 |
if (append) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
940 |
String message = NLS.bind(Messages.resources_mustBeLocal, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
941 |
throw new ResourceException(IResourceStatus.RESOURCE_NOT_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
942 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
943 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
944 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
945 |
// add entry to History Store. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
946 |
if (BitMask.isSet(updateFlags, IResource.KEEP_HISTORY) && fileInfo.exists()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
947 |
//never move to the history store, because then the file is missing if write fails |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
948 |
getHistoryStore().addState(target.getFullPath(), store, fileInfo, false); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
949 |
if (!fileInfo.exists()) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
950 |
store.getParent().mkdir(EFS.NONE, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
951 |
int options = append ? EFS.APPEND : EFS.NONE; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
952 |
OutputStream out = store.openOutputStream(options, Policy.subMonitorFor(monitor, 0)); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
953 |
FileUtil.transferStreams(content, out, store.toString(), monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
954 |
// get the new last modified time and stash in the info |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
955 |
lastModified = store.fetchInfo().getLastModified(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
956 |
ResourceInfo info = ((Resource) target).getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
957 |
updateLocalSync(info, lastModified); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
958 |
info.incrementContentId(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
959 |
info.clear(M_CONTENT_CACHE); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
960 |
workspace.updateModificationStamp(info); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
961 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
962 |
FileUtil.safeClose(content); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
963 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
964 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
965 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
966 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
967 |
* If force is false, this method fails if there is already a resource in |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
968 |
* target's location. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
969 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
970 |
public void write(IFolder target, boolean force, IProgressMonitor monitor) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
971 |
IFileStore store = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
972 |
if (!force) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
973 |
IFileInfo fileInfo = store.fetchInfo(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
974 |
if (fileInfo.isDirectory()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
975 |
String message = NLS.bind(Messages.localstore_resourceExists, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
976 |
throw new ResourceException(IResourceStatus.EXISTS_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
977 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
978 |
if (fileInfo.exists()) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
979 |
String message = NLS.bind(Messages.localstore_fileExists, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
980 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
981 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
982 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
983 |
store.mkdir(EFS.NONE, monitor); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
984 |
ResourceInfo info = ((Resource) target).getResourceInfo(false, true); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
985 |
updateLocalSync(info, store.fetchInfo().getLastModified()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
986 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
987 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
988 |
/** |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
989 |
* Write the .project file without modifying the resource tree. This is called |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
990 |
* during save when it is discovered that the .project file is missing. The tree |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
991 |
* cannot be modified during save. |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
992 |
*/ |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
993 |
public void writeSilently(IProject target) throws CoreException { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
994 |
IPath location = locationFor(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
995 |
//if the project location cannot be resolved, we don't know if a description file exists or not |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
996 |
if (location == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
997 |
return; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
998 |
IFileStore projectStore = getStore(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
999 |
projectStore.mkdir(EFS.NONE, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1000 |
//can't do anything if there's no description |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1001 |
IProjectDescription desc = ((Project) target).internalGetDescription(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1002 |
if (desc == null) |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1003 |
return; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1004 |
//write the project's private description to the meta-data area |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1005 |
getWorkspace().getMetaArea().writePrivateDescription(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1006 |
|
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1007 |
//write the file that represents the project description |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1008 |
IFileStore fileStore = projectStore.getChild(IProjectDescription.DESCRIPTION_FILE_NAME); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1009 |
OutputStream out = null; |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1010 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1011 |
out = fileStore.openOutputStream(EFS.NONE, null); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1012 |
new ModelObjectWriter().write(desc, out); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1013 |
} catch (IOException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1014 |
String msg = NLS.bind(Messages.resources_writeMeta, target.getFullPath()); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1015 |
throw new ResourceException(IResourceStatus.FAILED_WRITE_METADATA, target.getFullPath(), msg, e); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1016 |
} finally { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1017 |
if (out != null) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1018 |
try { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1019 |
out.close(); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1020 |
} catch (IOException e) { |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1021 |
// ignore failure to close stream |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1022 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1023 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1024 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1025 |
//for backwards compatibility, ensure the old .prj file is deleted |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1026 |
getWorkspace().getMetaArea().clearOldDescription(target); |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1027 |
} |
063eb66097dc
Added build of org.eclipse.core.resources
Steve Sobek <steve.sobek@nokia.com>
parents:
diff
changeset
|
1028 |
} |