Search in sources :

Example 21 with IWorkspaceRunnable

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 22 with IWorkspaceRunnable

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);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 23 with IWorkspaceRunnable

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];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) Assert.fail(org.junit.Assert.fail) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject)

Example 24 with IWorkspaceRunnable

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);
}
Also used : DebugPlugin(org.eclipse.debug.core.DebugPlugin) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) CProjectHelper(org.eclipse.linuxtools.internal.profiling.tests.CProjectHelper) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) ManagedCProjectNature(org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IPath(org.eclipse.core.runtime.IPath) IOverwriteQuery(org.eclipse.ui.dialogs.IOverwriteQuery) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) EFS(org.eclipse.core.filesystem.EFS) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) ImportOperation(org.eclipse.ui.wizards.datatransfer.ImportOperation) NLS(org.eclipse.osgi.util.NLS) Status(org.eclipse.core.runtime.Status) IBinary(org.eclipse.cdt.core.model.IBinary) EFSExtensionManager(org.eclipse.cdt.utils.EFSExtensionManager) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ScannerConfigNature(org.eclipse.cdt.build.core.scannerconfig.ScannerConfigNature) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) FileSystemStructureProvider(org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ICProject(org.eclipse.cdt.core.model.ICProject) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) IDebugUIConstants(org.eclipse.debug.ui.IDebugUIConstants) FileLocator(org.eclipse.core.runtime.FileLocator) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IIndexManager(org.eclipse.cdt.core.index.IIndexManager) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 25 with IWorkspaceRunnable

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];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) IndexerPreferences(org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspace(org.eclipse.core.resources.IWorkspace)

Aggregations

IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)53 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)43 IWorkspace (org.eclipse.core.resources.IWorkspace)29 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IStatus (org.eclipse.core.runtime.IStatus)18 PersistenceException (org.talend.commons.exception.PersistenceException)16 Status (org.eclipse.core.runtime.Status)14 IProject (org.eclipse.core.resources.IProject)13 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 IResource (org.eclipse.core.resources.IResource)10 IPath (org.eclipse.core.runtime.IPath)9 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)7 HashMap (java.util.HashMap)6 IFile (org.eclipse.core.resources.IFile)6 IProjectDescription (org.eclipse.core.resources.IProjectDescription)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)6 HashSet (java.util.HashSet)5