use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.
the class ContainerCreator method createContainer.
/**
* Creates this container.
*
* @param progressMonitor the progress monitor or <code>null</code> if none
* @return the container specified by this container creator's full path
* @throws CoreException if this container creator's full path denotes a file or creating
* either the project or folders for the given container fails
*/
public IContainer createContainer(IProgressMonitor progressMonitor) throws CoreException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, FileBuffersMessages.ContainerCreator_task_creatingContainer, fContainerFullPath.segmentCount());
if (fContainer != null)
return;
// Does the container exist already?
IWorkspaceRoot root = fWorkspace.getRoot();
IResource found = root.findMember(fContainerFullPath);
if (found instanceof IContainer) {
fContainer = (IContainer) found;
return;
} else if (found != null) {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, fContainerFullPath), null));
}
// Create the containers for the given path
fContainer = root;
for (int i = 0; i < fContainerFullPath.segmentCount(); i++) {
String currentSegment = fContainerFullPath.segment(i);
IResource resource = fContainer.findMember(currentSegment);
if (resource != null) {
if (resource instanceof IContainer) {
fContainer = (IContainer) resource;
subMonitor.split(1);
} else {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, resource.getFullPath()), null));
}
} else {
if (i == 0) {
IProject projectHandle = createProjectHandle(root, currentSegment);
fContainer = createProject(projectHandle, subMonitor.split(1));
} else {
IFolder folderHandle = createFolderHandle(fContainer, currentSegment);
fContainer = createFolder(folderHandle, subMonitor.split(1));
}
}
}
}
};
// Get scheduling rule
IWorkspaceRoot root = fWorkspace.getRoot();
IPath existingParentPath = fContainerFullPath;
while (!root.exists(existingParentPath)) existingParentPath = existingParentPath.removeLastSegments(1);
IResource schedulingRule = root.findMember(existingParentPath);
fWorkspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, progressMonitor);
return fContainer;
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project eclipse.platform.text by eclipse.
the class FileBufferOperationRunner method commit.
@Override
protected void commit(final IFileBuffer[] fileBuffers, final IProgressMonitor progressMonitor) throws CoreException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
doCommit(fileBuffers, progressMonitor);
}
};
ResourcesPlugin.getWorkspace().run(runnable, computeCommitRule(fileBuffers), IWorkspace.AVOID_UPDATE, progressMonitor);
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project linuxtools by eclipse.
the class CProjectHelper method createCProject2.
/**
* Creates a ICProject.
*/
private static ICProject createCProject2(final String projectName, String binFolderName) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject[] newProject = new ICProject[1];
ws.run((IWorkspaceRunnable) monitor -> {
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProject(projectName);
if (!project.exists()) {
project.create(null);
} else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = PLUGIN_ID + ".TestProject";
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
addDefaultBinaryParser(project);
newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
}, null);
return newProject[0];
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project linuxtools by eclipse.
the class AbstractTest method buildProject.
protected void buildProject(IProject proj) throws CoreException {
IWorkspace wsp = ResourcesPlugin.getWorkspace();
final IProject curProject = proj;
ISchedulingRule rule = wsp.getRuleFactory().buildRule();
Job buildJob = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"project build job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
curProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
} catch (CoreException e) {
fail(e.getStatus().getMessage());
} catch (OperationCanceledException e) {
fail(NLS.bind(Messages.getString("AbstractTest.Build_cancelled"), curProject.getName(), // $NON-NLS-1$
e.getMessage()));
}
return Status.OK_STATUS;
}
};
buildJob.setRule(rule);
buildJob.schedule();
try {
buildJob.join();
} catch (InterruptedException e) {
fail(NLS.bind(Messages.getString("AbstractTest.Build_interrupted"), curProject.getName(), // $NON-NLS-1$
e.getMessage()));
}
IStatus status = buildJob.getResult();
if (status.getCode() != IStatus.OK) {
fail(NLS.bind(Messages.getString("AbstractTest.Build_failed"), curProject.getName(), // $NON-NLS-1$
status.getMessage()));
}
IWorkspaceRunnable runnable = monitor -> curProject.refreshLocal(IResource.DEPTH_INFINITE, null);
wsp.run(runnable, wsp.getRoot(), IWorkspace.AVOID_UPDATE, null);
}
use of org.eclipse.core.resources.IWorkspaceRunnable in project linuxtools by eclipse.
the class CProjectHelper method createCCProject.
public static ICProject createCCProject(final String projectName, final String binFolderName, final String indexerID) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject[] newProject = new ICProject[1];
ws.run((IWorkspaceRunnable) monitor -> {
ICProject cproject = createCProject(projectName, binFolderName, indexerID);
if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
}
newProject[0] = cproject;
}, null);
return newProject[0];
}
Aggregations