View | Details | Raw Unified | Return to bug 220453
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java (-25 / +30 lines)
Lines 33-57 Link Here
33
	private HashMap folders;
33
	private HashMap folders;
34
	private int counter = 0;
34
	private int counter = 0;
35
	
35
	
36
	{
37
		this.folders = new HashMap();
38
		IProject project = getExternalFoldersProject();
39
		if (project.isAccessible()) {
40
			try {
41
				IResource[] members = project.members();
42
				for (int i = 0, length = members.length; i < length; i++) {
43
					IResource member = members[i];
44
					if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
45
						IPath externalFolderPath = member.getLocation();
46
						this.folders.put(externalFolderPath, member);
47
					}
48
				}
49
			} catch (CoreException e) {
50
				Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
51
			}
52
		}
53
	}
54
	
55
	public static boolean isExternal(IPath resourcePath) {
36
	public static boolean isExternal(IPath resourcePath) {
56
		return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0));
37
		return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0));
57
	}
38
	}
Lines 61-67 Link Here
61
	}
42
	}
62
43
63
	private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
44
	private synchronized IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) {
64
		Object existing = this.folders.get(externalFolderPath);
45
		HashMap knownFolders = getFolders();
46
		Object existing = knownFolders.get(externalFolderPath);
65
		if (existing != null) {
47
		if (existing != null) {
66
			return (IFolder) existing;
48
			return (IFolder) existing;
67
		}
49
		}
Lines 69-75 Link Here
69
		do {
51
		do {
70
			result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++);
52
			result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++);
71
		} while (result.exists());
53
		} while (result.exists());
72
		this.folders.put(externalFolderPath, result);
54
		knownFolders.put(externalFolderPath, result);
73
		return result;
55
		return result;
74
	}
56
	}
75
	
57
	
Lines 89-100 Link Here
89
		HashMap sourceAttachments = state.sourceAttachments;
71
		HashMap sourceAttachments = state.sourceAttachments;
90
		if (roots == null && sourceAttachments == null)
72
		if (roots == null && sourceAttachments == null)
91
			return;
73
			return;
92
		Iterator iterator = this.folders.keySet().iterator();
74
		HashMap knownFolders = getFolders();
75
		Iterator iterator = knownFolders.keySet().iterator();
93
		while (iterator.hasNext()) {
76
		while (iterator.hasNext()) {
94
			IPath path = (IPath) iterator.next();
77
			IPath path = (IPath) iterator.next();
95
			if ((roots != null && !roots.containsKey(path))
78
			if ((roots != null && !roots.containsKey(path))
96
					&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
79
					&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) {
97
				IFolder folder = (IFolder) this.folders.get(path);
80
				IFolder folder = (IFolder) knownFolders.get(path);
98
				if (folder != null)
81
				if (folder != null)
99
					folder.delete(true, monitor);
82
					folder.delete(true, monitor);
100
			}
83
			}
Lines 155-165 Link Here
155
	}
138
	}
156
	
139
	
157
	public synchronized IFolder getFolder(IPath externalFolderPath) {
140
	public synchronized IFolder getFolder(IPath externalFolderPath) {
158
		return (IFolder) this.folders.get(externalFolderPath);
141
		return (IFolder) getFolders().get(externalFolderPath);
142
	}
143
	
144
	private HashMap getFolders() {
145
		if (this.folders == null) {
146
			this.folders = new HashMap();
147
			IProject project = getExternalFoldersProject();
148
			if (project.isAccessible()) {
149
				try {
150
					IResource[] members = project.members();
151
					for (int i = 0, length = members.length; i < length; i++) {
152
						IResource member = members[i];
153
						if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) {
154
							IPath externalFolderPath = member.getLocation();
155
							this.folders.put(externalFolderPath, member);
156
						}
157
					}
158
				} catch (CoreException e) {
159
					Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$
160
				}
161
			}
162
		}
163
		return this.folders;
159
	}
164
	}
160
	
165
	
161
	public synchronized IFolder removeFolder(IPath externalFolderPath) {
166
	public synchronized IFolder removeFolder(IPath externalFolderPath) {
162
		return (IFolder) this.folders.remove(externalFolderPath);
167
		return (IFolder) getFolders().remove(externalFolderPath);
163
	}
168
	}
164
169
165
}
170
}

Return to bug 220453