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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java (-23 / +33 lines)
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
	public static ExternalFoldersManager getExternalFoldersManager() {
49
		return MANAGER;
50
	}
51
	
45
	/*
52
	/*
46
	 * Returns a set of external path to external folders referred to on the given classpath.
53
	 * Returns a set of external path to external folders referred to on the given classpath.
47
	 * Returns null if none.
54
	 * Returns null if none.
Lines 92-99 Link Here
92
		return addFolder(externalFolderPath, getExternalFoldersProject());
99
		return addFolder(externalFolderPath, getExternalFoldersProject());
93
	}
100
	}
94
101
95
	private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
102
	private IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
96
		HashMap knownFolders = getFolders();
103
		Map knownFolders = getFolders();
97
		Object existing = knownFolders.get(externalFolderPath);
104
		Object existing = knownFolders.get(externalFolderPath);
98
		if (existing != null) {
105
		if (existing != null) {
99
			return (IFolder) existing;
106
			return (IFolder) existing;
Lines 129-153 Link Here
129
			project.delete(true, monitor);
136
			project.delete(true, monitor);
130
	}
137
	}
131
138
132
	private synchronized ArrayList getFoldersToCleanUp(IProgressMonitor monitor) throws CoreException {
139
	private ArrayList getFoldersToCleanUp(IProgressMonitor monitor) throws CoreException {
133
		DeltaProcessingState state = JavaModelManager.getDeltaState();
140
		DeltaProcessingState state = JavaModelManager.getDeltaState();
134
		HashMap roots = state.roots;
141
		HashMap roots = state.roots;
135
		HashMap sourceAttachments = state.sourceAttachments;
142
		HashMap sourceAttachments = state.sourceAttachments;
136
		if (roots == null && sourceAttachments == null)
143
		if (roots == null && sourceAttachments == null)
137
			return null;
144
			return null;
138
		HashMap knownFolders = getFolders();
145
		Map knownFolders = getFolders();
139
		Iterator iterator = knownFolders.entrySet().iterator();
140
		ArrayList result = null;
146
		ArrayList result = null;
141
		while (iterator.hasNext()) {
147
		synchronized (knownFolders) {
142
			Map.Entry entry = (Map.Entry) iterator.next();
148
			Iterator iterator = knownFolders.entrySet().iterator();
143
			IPath path = (IPath) entry.getKey();
149
			while (iterator.hasNext()) {
144
			if ((roots != null && !roots.containsKey(path))
150
				Map.Entry entry = (Map.Entry) iterator.next();
145
					&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
151
				IPath path = (IPath) entry.getKey();
146
				IFolder folder = (IFolder) entry.getValue();
152
				if ((roots != null && !roots.containsKey(path))
147
				if (folder != null) {
153
						&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
148
					if (result == null)
154
					IFolder folder = (IFolder) entry.getValue();
149
						result = new ArrayList();
155
					if (folder != null) {
150
					result.add(folder);
156
						if (result == null)
157
							result = new ArrayList();
158
						result.add(folder);
159
					}
151
				}
160
				}
152
			}
161
			}
153
		}
162
		}
Lines 222-234 Link Here
222
		project.create(desc, IResource.HIDDEN, monitor);
231
		project.create(desc, IResource.HIDDEN, monitor);
223
	}
232
	}
224
233
225
	public synchronized IFolder getFolder(IPath externalFolderPath) {
234
	public IFolder getFolder(IPath externalFolderPath) {
226
		return (IFolder) getFolders().get(externalFolderPath);
235
		return (IFolder) getFolders().get(externalFolderPath);
227
	}
236
	}
228
237
229
	private HashMap getFolders() {
238
	private Map getFolders() {
230
		if (this.folders == null) {
239
		if (this.folders == null) {
231
			this.folders = new HashMap();
240
			Map tempFolders = Collections.synchronizedMap(new HashMap());
232
			IProject project = getExternalFoldersProject();
241
			IProject project = getExternalFoldersProject();
233
			try {
242
			try {
234
				if (!project.isAccessible()) {
243
				if (!project.isAccessible()) {
Lines 237-243 Link Here
237
						openExternalFoldersProject(project, null/*no progress*/);
246
						openExternalFoldersProject(project, null/*no progress*/);
238
					} else {
247
					} else {
239
						// if project doesn't exist, do not open and recreate it as it means that there are no external folders
248
						// if project doesn't exist, do not open and recreate it as it means that there are no external folders
240
						return this.folders;
249
						return this.folders = tempFolders;
241
					}
250
					}
242
				}
251
				}
243
				IResource[] members = project.members();
252
				IResource[] members = project.members();
Lines 245-256 Link Here
245
					IResource member = members[i];
254
					IResource member = members[i];
246
					if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
255
					if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
247
						IPath externalFolderPath = member.getLocation();
256
						IPath externalFolderPath = member.getLocation();
248
						this.folders.put(externalFolderPath, member);
257
						tempFolders.put(externalFolderPath, member);
249
					}
258
					}
250
				}
259
				}
251
			} catch (CoreException e) {
260
			} catch (CoreException e) {
252
				Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
261
				Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
253
			}
262
			}
263
			this.folders = tempFolders;
254
		}
264
		}
255
		return this.folders;
265
		return this.folders;
256
	}
266
	}
Lines 308-314 Link Here
308
		return;
318
		return;
309
	}
319
	}
310
320
311
	public synchronized IFolder removeFolder(IPath externalFolderPath) {
321
	public IFolder removeFolder(IPath externalFolderPath) {
312
		return (IFolder) getFolders().remove(externalFolderPath);
322
		return (IFolder) getFolders().remove(externalFolderPath);
313
	}
323
	}
314
324
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +1 lines)
Lines 451-457 Link Here
451
	/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
451
	/* whether an AbortCompilationUnit should be thrown when the source of a compilation unit cannot be retrieved */
452
	public ThreadLocal abortOnMissingSource = new ThreadLocal();
452
	public ThreadLocal abortOnMissingSource = new ThreadLocal();
453
453
454
	private ExternalFoldersManager externalFoldersManager = new ExternalFoldersManager();
454
	private ExternalFoldersManager externalFoldersManager = ExternalFoldersManager.getExternalFoldersManager();
455
455
456
	/**
456
	/**
457
	 * Returns whether the given full path (for a package) conflicts with the output location
457
	 * Returns whether the given full path (for a package) conflicts with the output location

Return to bug 310159