Search in sources :

Example 21 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule 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 22 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class RefactoringExecutionHelper method perform.

/**
	 * Must be called in the UI thread.<br>
	 * <strong>Use {@link #perform(boolean, boolean)} unless you know exactly what you are doing!</strong>
	 *
	 * @param fork if set, the operation will be forked
	 * @param forkChangeExecution if the change should not be executed in the UI thread: This may not work in any case
	 * @param cancelable  if set, the operation will be cancelable
	 * @throws InterruptedException thrown when the operation is cancelled
	 * @throws InvocationTargetException thrown when the operation failed to execute
	 */
public RefactoringStatus perform(boolean fork, boolean forkChangeExecution, boolean cancelable) throws InterruptedException, InvocationTargetException, CoreException {
    //		Assert.isTrue(Display.getCurrent() != null);
    final IJobManager manager = Job.getJobManager();
    final ISchedulingRule rule;
    if (fRefactoring instanceof IScheduledRefactoring) {
        rule = ((IScheduledRefactoring) fRefactoring).getSchedulingRule();
    } else {
        rule = ResourcesPlugin.getWorkspace().getRoot();
    }
    Operation op = null;
    try {
        try {
            op = new Operation(fork, forkChangeExecution);
            op.run(new NullProgressMonitor());
            fPerformChangeOperation = op.fPerformChangeOperation;
            //			fRefactoring.setValidationContext(fParent);
            if (op.fPerformChangeOperation != null) {
                ResourcesPlugin.getWorkspace().run(op.fPerformChangeOperation, new NullProgressMonitor());
            }
            if (op.fPerformChangeOperation != null) {
                RefactoringStatus validationStatus = op.fPerformChangeOperation.getValidationStatus();
                if (validationStatus != null) /*&& validationStatus.hasFatalError()*/
                {
                    //						throw new InterruptedException();
                    return validationStatus;
                }
            }
        } catch (OperationCanceledException e) {
            if (op != null) {
                if (op.allConditions != null) {
                    return op.allConditions;
                }
            }
            throw new InterruptedException(e.getMessage());
        } finally {
        //				saveHelper.triggerIncrementalBuild();
        }
    } finally {
        //			manager.endRule(rule);
        fRefactoring.setValidationContext(null);
    }
    return new RefactoringStatus();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 23 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class WorkspaceModifyOperation method threadChange.

/* (non-Javadoc)
     * @see IThreadListener#threadChange(Thread);
     * @since 3.2
     */
public void threadChange(Thread thread) {
    //already owns a scheduling rule because this is deadlock prone (bug 105491)
    if (rule == null) {
        return;
    }
    Job currentJob = Job.getJobManager().currentJob();
    if (currentJob == null) {
        return;
    }
    ISchedulingRule currentRule = currentJob.getRule();
    if (currentRule == null) {
        return;
    }
    //$NON-NLS-1$
    throw new IllegalStateException("Cannot fork a thread from a thread owning a rule");
}
Also used : Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 24 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Resource method move.

@Override
public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_moving, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        Policy.checkCanceled(monitor);
        destination = makePathAbsolute(destination);
        //            checkValidPath(destination, getType(), false);
        Resource destResource = workspace.newResource(destination, getType());
        final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destResource);
        WorkManager workManager = workspace.getWorkManager();
        try {
            workspace.prepareOperation(rule, monitor);
            workspace.beginOperation(true);
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                unprotectedMove(destResource, updateFlags, monitor);
            } finally {
                workManager.endUnprotected(depth);
            }
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 25 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)33 CoreException (org.eclipse.core.runtime.CoreException)21 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 IWorkspace (org.eclipse.core.resources.IWorkspace)19 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)19 PersistenceException (org.talend.commons.exception.PersistenceException)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IStatus (org.eclipse.core.runtime.IStatus)9 Status (org.eclipse.core.runtime.Status)8 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)7 HashSet (java.util.HashSet)6 IResource (org.eclipse.core.resources.IResource)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)6 ArrayList (java.util.ArrayList)5 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 HashMap (java.util.HashMap)4 IPath (org.eclipse.core.runtime.IPath)4