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);
}
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();
}
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");
}
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();
}
}
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();
}
}
Aggregations