Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 14-19
Link Here
|
14 |
import java.io.FileOutputStream; |
14 |
import java.io.FileOutputStream; |
15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
16 |
import java.util.ArrayList; |
16 |
import java.util.ArrayList; |
|
|
17 |
import java.util.Collections; |
17 |
import java.util.HashMap; |
18 |
import java.util.HashMap; |
18 |
import java.util.HashSet; |
19 |
import java.util.HashSet; |
19 |
import java.util.Iterator; |
20 |
import java.util.Iterator; |
Lines 39-47
Link Here
|
39 |
public class ExternalFoldersManager { |
40 |
public class ExternalFoldersManager { |
40 |
private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$ |
41 |
private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$ |
41 |
private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$ |
42 |
private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$ |
42 |
private HashMap folders; |
43 |
private Map folders; |
43 |
private int counter = 0; |
44 |
private int counter = 0; |
|
|
45 |
/* Singleton instance */ |
46 |
private static ExternalFoldersManager MANAGER = new ExternalFoldersManager(); |
44 |
|
47 |
|
|
|
48 |
private ExternalFoldersManager() { |
49 |
// Prevent instantiation |
50 |
} |
51 |
|
52 |
public static ExternalFoldersManager getExternalFoldersManager() { |
53 |
return MANAGER; |
54 |
} |
55 |
|
45 |
/* |
56 |
/* |
46 |
* Returns a set of external path to external folders referred to on the given classpath. |
57 |
* Returns a set of external path to external folders referred to on the given classpath. |
47 |
* Returns null if none. |
58 |
* Returns null if none. |
Lines 92-99
Link Here
|
92 |
return addFolder(externalFolderPath, getExternalFoldersProject()); |
103 |
return addFolder(externalFolderPath, getExternalFoldersProject()); |
93 |
} |
104 |
} |
94 |
|
105 |
|
95 |
private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) { |
106 |
private IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) { |
96 |
HashMap knownFolders = getFolders(); |
107 |
Map knownFolders = getFolders(); |
97 |
Object existing = knownFolders.get(externalFolderPath); |
108 |
Object existing = knownFolders.get(externalFolderPath); |
98 |
if (existing != null) { |
109 |
if (existing != null) { |
99 |
return (IFolder) existing; |
110 |
return (IFolder) existing; |
Lines 129-153
Link Here
|
129 |
project.delete(true, monitor); |
140 |
project.delete(true, monitor); |
130 |
} |
141 |
} |
131 |
|
142 |
|
132 |
private synchronized ArrayList getFoldersToCleanUp(IProgressMonitor monitor) throws CoreException { |
143 |
private ArrayList getFoldersToCleanUp(IProgressMonitor monitor) throws CoreException { |
133 |
DeltaProcessingState state = JavaModelManager.getDeltaState(); |
144 |
DeltaProcessingState state = JavaModelManager.getDeltaState(); |
134 |
HashMap roots = state.roots; |
145 |
HashMap roots = state.roots; |
135 |
HashMap sourceAttachments = state.sourceAttachments; |
146 |
HashMap sourceAttachments = state.sourceAttachments; |
136 |
if (roots == null && sourceAttachments == null) |
147 |
if (roots == null && sourceAttachments == null) |
137 |
return null; |
148 |
return null; |
138 |
HashMap knownFolders = getFolders(); |
149 |
Map knownFolders = getFolders(); |
139 |
Iterator iterator = knownFolders.entrySet().iterator(); |
|
|
140 |
ArrayList result = null; |
150 |
ArrayList result = null; |
141 |
while (iterator.hasNext()) { |
151 |
synchronized (knownFolders) { |
142 |
Map.Entry entry = (Map.Entry) iterator.next(); |
152 |
Iterator iterator = knownFolders.entrySet().iterator(); |
143 |
IPath path = (IPath) entry.getKey(); |
153 |
while (iterator.hasNext()) { |
144 |
if ((roots != null && !roots.containsKey(path)) |
154 |
Map.Entry entry = (Map.Entry) iterator.next(); |
145 |
&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) { |
155 |
IPath path = (IPath) entry.getKey(); |
146 |
IFolder folder = (IFolder) entry.getValue(); |
156 |
if ((roots != null && !roots.containsKey(path)) |
147 |
if (folder != null) { |
157 |
&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) { |
148 |
if (result == null) |
158 |
IFolder folder = (IFolder) entry.getValue(); |
149 |
result = new ArrayList(); |
159 |
if (folder != null) { |
150 |
result.add(folder); |
160 |
if (result == null) |
|
|
161 |
result = new ArrayList(); |
162 |
result.add(folder); |
163 |
} |
151 |
} |
164 |
} |
152 |
} |
165 |
} |
153 |
} |
166 |
} |
Lines 222-234
Link Here
|
222 |
project.create(desc, IResource.HIDDEN, monitor); |
235 |
project.create(desc, IResource.HIDDEN, monitor); |
223 |
} |
236 |
} |
224 |
|
237 |
|
225 |
public synchronized IFolder getFolder(IPath externalFolderPath) { |
238 |
public IFolder getFolder(IPath externalFolderPath) { |
226 |
return (IFolder) getFolders().get(externalFolderPath); |
239 |
return (IFolder) getFolders().get(externalFolderPath); |
227 |
} |
240 |
} |
228 |
|
241 |
|
229 |
private HashMap getFolders() { |
242 |
private Map getFolders() { |
230 |
if (this.folders == null) { |
243 |
if (this.folders == null) { |
231 |
this.folders = new HashMap(); |
244 |
Map tempFolders = new HashMap(); |
232 |
IProject project = getExternalFoldersProject(); |
245 |
IProject project = getExternalFoldersProject(); |
233 |
try { |
246 |
try { |
234 |
if (!project.isAccessible()) { |
247 |
if (!project.isAccessible()) { |
Lines 237-243
Link Here
|
237 |
openExternalFoldersProject(project, null/*no progress*/); |
250 |
openExternalFoldersProject(project, null/*no progress*/); |
238 |
} else { |
251 |
} else { |
239 |
// if project doesn't exist, do not open and recreate it as it means that there are no external folders |
252 |
// if project doesn't exist, do not open and recreate it as it means that there are no external folders |
240 |
return this.folders; |
253 |
return this.folders = Collections.synchronizedMap(tempFolders); |
241 |
} |
254 |
} |
242 |
} |
255 |
} |
243 |
IResource[] members = project.members(); |
256 |
IResource[] members = project.members(); |
Lines 245-256
Link Here
|
245 |
IResource member = members[i]; |
258 |
IResource member = members[i]; |
246 |
if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) { |
259 |
if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) { |
247 |
IPath externalFolderPath = member.getLocation(); |
260 |
IPath externalFolderPath = member.getLocation(); |
248 |
this.folders.put(externalFolderPath, member); |
261 |
tempFolders.put(externalFolderPath, member); |
249 |
} |
262 |
} |
250 |
} |
263 |
} |
251 |
} catch (CoreException e) { |
264 |
} catch (CoreException e) { |
252 |
Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$ |
265 |
Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$ |
253 |
} |
266 |
} |
|
|
267 |
this.folders = Collections.synchronizedMap(tempFolders); |
254 |
} |
268 |
} |
255 |
return this.folders; |
269 |
return this.folders; |
256 |
} |
270 |
} |
Lines 308-314
Link Here
|
308 |
return; |
322 |
return; |
309 |
} |
323 |
} |
310 |
|
324 |
|
311 |
public synchronized IFolder removeFolder(IPath externalFolderPath) { |
325 |
public IFolder removeFolder(IPath externalFolderPath) { |
312 |
return (IFolder) getFolders().remove(externalFolderPath); |
326 |
return (IFolder) getFolders().remove(externalFolderPath); |
313 |
} |
327 |
} |
314 |
|
328 |
|