|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Stephan Herrmann <stephan@cs.tu-berlin.de> - inconsistent initialization of classpath container backed by external class folder, see https://bugs.eclipse.org/320618 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.internal.core; |
12 |
package org.eclipse.jdt.internal.core; |
| 12 |
|
13 |
|
|
Lines 20-25
Link Here
|
| 20 |
import java.util.HashSet; |
21 |
import java.util.HashSet; |
| 21 |
import java.util.Iterator; |
22 |
import java.util.Iterator; |
| 22 |
import java.util.Map; |
23 |
import java.util.Map; |
|
|
24 |
import java.util.Set; |
| 23 |
import java.util.Vector; |
25 |
import java.util.Vector; |
| 24 |
|
26 |
|
| 25 |
import org.eclipse.core.resources.IFolder; |
27 |
import org.eclipse.core.resources.IFolder; |
|
Lines 36-41
Link Here
|
| 36 |
import org.eclipse.core.runtime.jobs.Job; |
38 |
import org.eclipse.core.runtime.jobs.Job; |
| 37 |
import org.eclipse.jdt.core.IClasspathEntry; |
39 |
import org.eclipse.jdt.core.IClasspathEntry; |
| 38 |
import org.eclipse.jdt.core.JavaCore; |
40 |
import org.eclipse.jdt.core.JavaCore; |
|
|
41 |
import org.eclipse.jdt.core.JavaModelException; |
| 39 |
import org.eclipse.jdt.internal.core.util.Messages; |
42 |
import org.eclipse.jdt.internal.core.util.Messages; |
| 40 |
import org.eclipse.jdt.internal.core.util.Util; |
43 |
import org.eclipse.jdt.internal.core.util.Util; |
| 41 |
|
44 |
|
|
Lines 43-48
Link Here
|
| 43 |
private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$ |
46 |
private static final String EXTERNAL_PROJECT_NAME = ".org.eclipse.jdt.core.external.folders"; //$NON-NLS-1$ |
| 44 |
private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$ |
47 |
private static final String LINKED_FOLDER_NAME = ".link"; //$NON-NLS-1$ |
| 45 |
private Map folders; |
48 |
private Map folders; |
|
|
49 |
private Set pendingFolders; // subset of keys of 'folders', for which linked folders haven't been created yet. |
| 46 |
private int counter = 0; |
50 |
private int counter = 0; |
| 47 |
/* Singleton instance */ |
51 |
/* Singleton instance */ |
| 48 |
private static ExternalFoldersManager MANAGER = new ExternalFoldersManager(); |
52 |
private static ExternalFoldersManager MANAGER = new ExternalFoldersManager(); |
|
Lines 102-112
Link Here
|
| 102 |
return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0)); |
106 |
return EXTERNAL_PROJECT_NAME.equals(resourcePath.segment(0)); |
| 103 |
} |
107 |
} |
| 104 |
|
108 |
|
| 105 |
public IFolder addFolder(IPath externalFolderPath) { |
109 |
public IFolder addFolder(IPath externalFolderPath, boolean scheduleForCreation) { |
| 106 |
return addFolder(externalFolderPath, getExternalFoldersProject()); |
110 |
return addFolder(externalFolderPath, getExternalFoldersProject(), scheduleForCreation); |
| 107 |
} |
111 |
} |
| 108 |
|
112 |
|
| 109 |
private IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject) { |
113 |
private IFolder addFolder(IPath externalFolderPath, IProject externalFoldersProject, boolean scheduleForCreation) { |
| 110 |
Map knownFolders = getFolders(); |
114 |
Map knownFolders = getFolders(); |
| 111 |
Object existing = knownFolders.get(externalFolderPath); |
115 |
Object existing = knownFolders.get(externalFolderPath); |
| 112 |
if (existing != null) { |
116 |
if (existing != null) { |
|
Lines 116-128
Link Here
|
| 116 |
do { |
120 |
do { |
| 117 |
result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++); |
121 |
result = externalFoldersProject.getFolder(LINKED_FOLDER_NAME + this.counter++); |
| 118 |
} while (result.exists()); |
122 |
} while (result.exists()); |
|
|
123 |
if (scheduleForCreation) { |
| 124 |
if (this.pendingFolders == null) |
| 125 |
this.pendingFolders = new HashSet(); |
| 126 |
this.pendingFolders.add(externalFolderPath); |
| 127 |
} |
| 119 |
knownFolders.put(externalFolderPath, result); |
128 |
knownFolders.put(externalFolderPath, result); |
| 120 |
return result; |
129 |
return result; |
| 121 |
} |
130 |
} |
|
|
131 |
|
| 132 |
/** |
| 133 |
* Try to remove the argument from the list of folders pending for creation. |
| 134 |
* @param externalPath to link to |
| 135 |
* @return true if the argument was found in the list of pending folders and could be removed from it. |
| 136 |
*/ |
| 137 |
public boolean removePendingFolder(Object externalPath) { |
| 138 |
if (this.pendingFolders == null) |
| 139 |
return false; |
| 140 |
return this.pendingFolders.remove(externalPath); |
| 141 |
} |
| 122 |
|
142 |
|
| 123 |
public IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, IProgressMonitor monitor) throws CoreException { |
143 |
public IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, IProgressMonitor monitor) throws CoreException { |
| 124 |
IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource |
144 |
IProject externalFoldersProject = createExternalFoldersProject(monitor); // run outside synchronized as this can create a resource |
| 125 |
IFolder result = addFolder(externalFolderPath, externalFoldersProject); |
145 |
return createLinkFolder(externalFolderPath, refreshIfExistAlready, externalFoldersProject, monitor); |
|
|
146 |
} |
| 147 |
|
| 148 |
private IFolder createLinkFolder(IPath externalFolderPath, boolean refreshIfExistAlready, |
| 149 |
IProject externalFoldersProject, IProgressMonitor monitor) throws CoreException { |
| 150 |
|
| 151 |
IFolder result = addFolder(externalFolderPath, externalFoldersProject, false); |
| 126 |
if (!result.exists()) |
152 |
if (!result.exists()) |
| 127 |
result.createLink(externalFolderPath, IResource.ALLOW_MISSING_LOCAL, monitor); |
153 |
result.createLink(externalFolderPath, IResource.ALLOW_MISSING_LOCAL, monitor); |
| 128 |
else if (refreshIfExistAlready) |
154 |
else if (refreshIfExistAlready) |
|
Lines 130-142
Link Here
|
| 130 |
return result; |
156 |
return result; |
| 131 |
} |
157 |
} |
| 132 |
|
158 |
|
|
|
159 |
public void createPendingFolders(IProgressMonitor monitor) throws JavaModelException{ |
| 160 |
if (this.pendingFolders == null || this.pendingFolders.isEmpty()) return; |
| 161 |
|
| 162 |
IProject externalFoldersProject = null; |
| 163 |
try { |
| 164 |
externalFoldersProject = createExternalFoldersProject(monitor); |
| 165 |
} |
| 166 |
catch(CoreException e) { |
| 167 |
throw new JavaModelException(e); |
| 168 |
} |
| 169 |
Iterator iterator = this.pendingFolders.iterator(); |
| 170 |
while (iterator.hasNext()) { |
| 171 |
Object folderPath = iterator.next(); |
| 172 |
try { |
| 173 |
createLinkFolder((IPath) folderPath, false, externalFoldersProject, monitor); |
| 174 |
} catch (CoreException e) { |
| 175 |
Util.log(e, "Error while creating a link for external folder :" + folderPath); //$NON-NLS-1$ |
| 176 |
} |
| 177 |
} |
| 178 |
this.pendingFolders.clear(); |
| 179 |
} |
| 180 |
|
| 133 |
public void cleanUp(IProgressMonitor monitor) throws CoreException { |
181 |
public void cleanUp(IProgressMonitor monitor) throws CoreException { |
| 134 |
ArrayList toDelete = getFoldersToCleanUp(monitor); |
182 |
ArrayList toDelete = getFoldersToCleanUp(monitor); |
| 135 |
if (toDelete == null) |
183 |
if (toDelete == null) |
| 136 |
return; |
184 |
return; |
| 137 |
for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) { |
185 |
for (Iterator iterator = toDelete.iterator(); iterator.hasNext();) { |
| 138 |
IFolder folder = (IFolder) iterator.next(); |
186 |
Map.Entry entry = (Map.Entry) iterator.next(); |
|
|
187 |
IFolder folder = (IFolder) entry.getValue(); |
| 139 |
folder.delete(true, monitor); |
188 |
folder.delete(true, monitor); |
|
|
189 |
IPath key = (IPath) entry.getKey(); |
| 190 |
this.folders.remove(key); |
| 140 |
} |
191 |
} |
| 141 |
IProject project = getExternalFoldersProject(); |
192 |
IProject project = getExternalFoldersProject(); |
| 142 |
if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/) |
193 |
if (project.isAccessible() && project.members().length == 1/*remaining member is .project*/) |
|
Lines 158-168
Link Here
|
| 158 |
IPath path = (IPath) entry.getKey(); |
209 |
IPath path = (IPath) entry.getKey(); |
| 159 |
if ((roots != null && !roots.containsKey(path)) |
210 |
if ((roots != null && !roots.containsKey(path)) |
| 160 |
&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) { |
211 |
&& (sourceAttachments != null && !sourceAttachments.containsKey(path))) { |
| 161 |
IFolder folder = (IFolder) entry.getValue(); |
212 |
if (entry.getValue() != null) { |
| 162 |
if (folder != null) { |
|
|
| 163 |
if (result == null) |
213 |
if (result == null) |
| 164 |
result = new ArrayList(); |
214 |
result = new ArrayList(); |
| 165 |
result.add(folder); |
215 |
result.add(entry); |
| 166 |
} |
216 |
} |
| 167 |
} |
217 |
} |
| 168 |
} |
218 |
} |
|
Lines 173-179
Link Here
|
| 173 |
public IProject getExternalFoldersProject() { |
223 |
public IProject getExternalFoldersProject() { |
| 174 |
return ResourcesPlugin.getWorkspace().getRoot().getProject(EXTERNAL_PROJECT_NAME); |
224 |
return ResourcesPlugin.getWorkspace().getRoot().getProject(EXTERNAL_PROJECT_NAME); |
| 175 |
} |
225 |
} |
| 176 |
private IProject createExternalFoldersProject(IProgressMonitor monitor) throws CoreException { |
226 |
public IProject createExternalFoldersProject(IProgressMonitor monitor) throws CoreException { |
| 177 |
IProject project = getExternalFoldersProject(); |
227 |
IProject project = getExternalFoldersProject(); |
| 178 |
if (!project.isAccessible()) { |
228 |
if (!project.isAccessible()) { |
| 179 |
if (!project.exists()) { |
229 |
if (!project.exists()) { |