Lines 22-27
Link Here
|
22 |
import org.eclipse.core.resources.IProject; |
22 |
import org.eclipse.core.resources.IProject; |
23 |
import org.eclipse.core.resources.IProjectDescription; |
23 |
import org.eclipse.core.resources.IProjectDescription; |
24 |
import org.eclipse.core.resources.IResource; |
24 |
import org.eclipse.core.resources.IResource; |
|
|
25 |
import org.eclipse.core.resources.IResourceStatus; |
25 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.resources.ResourcesPlugin; |
26 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.IPath; |
28 |
import org.eclipse.core.runtime.IPath; |
Lines 160-195
Link Here
|
160 |
if (!project.isAccessible()) { |
161 |
if (!project.isAccessible()) { |
161 |
try { |
162 |
try { |
162 |
if (!project.exists()) { |
163 |
if (!project.exists()) { |
163 |
IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); |
164 |
createExternalFoldersProject(project, monitor); |
164 |
IPath stateLocation = JavaCore.getPlugin().getStateLocation(); |
|
|
165 |
desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME)); |
166 |
project.create(DEBUG ? null : desc, DEBUG ? IResource.NONE : IResource.HIDDEN, monitor); |
167 |
} |
165 |
} |
168 |
try { |
166 |
try { |
169 |
project.open(monitor); |
167 |
project.open(monitor); |
170 |
} catch (CoreException e1) { |
168 |
} catch (CoreException e1) { |
171 |
// .project or folder on disk have been deleted, recreate them |
169 |
if (e1.getStatus().getCode() == IResourceStatus.FAILED_READ_METADATA) { |
172 |
IPath stateLocation = DEBUG ? ResourcesPlugin.getWorkspace().getRoot().getLocation() : JavaCore.getPlugin().getStateLocation(); |
170 |
// workspace was moved (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=241400) |
173 |
IPath projectPath = stateLocation.append(EXTERNAL_PROJECT_NAME); |
171 |
project.delete(true, monitor); |
174 |
projectPath.toFile().mkdirs(); |
172 |
createExternalFoldersProject(project, monitor); |
175 |
FileOutputStream output = new FileOutputStream(projectPath.append(".project").toOSString()); //$NON-NLS-1$ |
173 |
} else { |
176 |
try { |
174 |
// .project or folder on disk have been deleted, recreate them |
177 |
output.write(( |
175 |
IPath stateLocation = DEBUG ? ResourcesPlugin.getWorkspace().getRoot().getLocation() : JavaCore.getPlugin().getStateLocation(); |
178 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ |
176 |
IPath projectPath = stateLocation.append(EXTERNAL_PROJECT_NAME); |
179 |
"<projectDescription>\n" + //$NON-NLS-1$ |
177 |
projectPath.toFile().mkdirs(); |
180 |
" <name>" + EXTERNAL_PROJECT_NAME + "</name>\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
178 |
FileOutputStream output = new FileOutputStream(projectPath.append(".project").toOSString()); //$NON-NLS-1$ |
181 |
" <comment></comment>\n" + //$NON-NLS-1$ |
179 |
try { |
182 |
" <projects>\n" + //$NON-NLS-1$ |
180 |
output.write(( |
183 |
" </projects>\n" + //$NON-NLS-1$ |
181 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ |
184 |
" <buildSpec>\n" + //$NON-NLS-1$ |
182 |
"<projectDescription>\n" + //$NON-NLS-1$ |
185 |
" </buildSpec>\n" + //$NON-NLS-1$ |
183 |
" <name>" + EXTERNAL_PROJECT_NAME + "</name>\n" + //$NON-NLS-1$ //$NON-NLS-2$ |
186 |
" <natures>\n" + //$NON-NLS-1$ |
184 |
" <comment></comment>\n" + //$NON-NLS-1$ |
187 |
" </natures>\n" + //$NON-NLS-1$ |
185 |
" <projects>\n" + //$NON-NLS-1$ |
188 |
"</projectDescription>").getBytes()); //$NON-NLS-1$ |
186 |
" </projects>\n" + //$NON-NLS-1$ |
189 |
} finally { |
187 |
" <buildSpec>\n" + //$NON-NLS-1$ |
190 |
output.close(); |
188 |
" </buildSpec>\n" + //$NON-NLS-1$ |
191 |
} |
189 |
" <natures>\n" + //$NON-NLS-1$ |
192 |
project.open(null); |
190 |
" </natures>\n" + //$NON-NLS-1$ |
|
|
191 |
"</projectDescription>").getBytes()); //$NON-NLS-1$ |
192 |
} finally { |
193 |
output.close(); |
194 |
} |
195 |
} |
196 |
project.open(monitor); |
193 |
} |
197 |
} |
194 |
} catch (CoreException e) { |
198 |
} catch (CoreException e) { |
195 |
Util.log(e, "Problem creating hidden project for external folders"); //$NON-NLS-1$ |
199 |
Util.log(e, "Problem creating hidden project for external folders"); //$NON-NLS-1$ |
Lines 202-207
Link Here
|
202 |
return project; |
206 |
return project; |
203 |
} |
207 |
} |
204 |
|
208 |
|
|
|
209 |
|
210 |
private void createExternalFoldersProject(IProject project, IProgressMonitor monitor) throws CoreException { |
211 |
IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName()); |
212 |
IPath stateLocation = JavaCore.getPlugin().getStateLocation(); |
213 |
desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME)); |
214 |
project.create(DEBUG ? null : desc, DEBUG ? IResource.NONE : IResource.HIDDEN, monitor); |
215 |
} |
216 |
|
205 |
public synchronized IFolder getFolder(IPath externalFolderPath) { |
217 |
public synchronized IFolder getFolder(IPath externalFolderPath) { |
206 |
return (IFolder) getFolders().get(externalFolderPath); |
218 |
return (IFolder) getFolders().get(externalFolderPath); |
207 |
} |
219 |
} |