use of org.eclipse.core.runtime.jobs.ISchedulingRule in project egit by eclipse.
the class RuleUtil method getRuleForRepositories.
/**
* Calculates a {@link ISchedulingRule} for Jobs working on the index of
* multiple repositories, see {@link #getRule(Repository)}.
*
* @param repositories
* @return scheduling rule
*/
public static ISchedulingRule getRuleForRepositories(Collection<Repository> repositories) {
ISchedulingRule result = null;
for (Repository repository : repositories) {
ISchedulingRule rule = getRule(repository);
result = MultiRule.combine(result, rule);
}
return result;
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project egit by eclipse.
the class LocationEditableRevision method setContent.
@Override
public void setContent(final byte[] newContent) {
try {
// Don't fork: if we are called from a thread which locked
// workspace our *forked* operation will never complete because it
// requires file lock which cannot be acquired from another thread
ISchedulingRule rule = Job.getJobManager().currentRule();
boolean fork = true;
if (rule instanceof IResource) {
IFile ourFile = ResourcesPlugin.getWorkspace().getRoot().getFile(location);
if (ourFile.exists() && ((IResource) rule).isConflicting(ourFile))
fork = false;
}
runnableContext.run(fork, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IFileStore store = EFS.getLocalFileSystem().getStore(location);
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(store.openOutputStream(0, monitor));
out.write(newContent);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} catch (IOException e) {
throw new InvocationTargetException(e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
// Ignore this one
}
}
}
}
});
} catch (InvocationTargetException e) {
Activator.handleError(e.getTargetException().getMessage(), e.getTargetException(), true);
} catch (InterruptedException e) {
// ignore here
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project egit by eclipse.
the class ResourceEditableRevision method setContent.
@Override
public void setContent(final byte[] newContent) {
try {
// Don't fork: if we are called from a thread which locked
// workspace our *forked* operation will never complete because it
// requires file lock which cannot be acquired from another thread
ISchedulingRule rule = Job.getJobManager().currentRule();
boolean fork = true;
if (rule instanceof IResource) {
if (file.exists() && ((IResource) rule).isConflicting(file))
fork = false;
}
runnableContext.run(fork, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor myMonitor) throws InvocationTargetException, InterruptedException {
try {
file.setContents(new ByteArrayInputStream(newContent), false, true, myMonitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Activator.handleError(e.getTargetException().getMessage(), e.getTargetException(), true);
} catch (InterruptedException e) {
// ignore here
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdq-studio-se by Talend.
the class DQStructureManager method createDQStructure.
/**
* DOC bZhou Comment method "createDQStructure".
*/
public void createDQStructure() {
RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(// $NON-NLS-1$
DefaultMessagesImpl.getString("DQStructureManager.SVN_LOG_CREATE_STRUCTURE")) {
@Override
protected void run() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable operation = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
createDQStructureUnit();
}
};
ISchedulingRule schedulingRule = workspace.getRoot();
try {
workspace.run(operation, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
log.error(e, e);
}
}
};
workUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(workUnit);
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdq-studio-se by Talend.
the class DQDeleteAction method deleteReportFile.
/**
* physical delete generating report file.
*
* @param repFileNode
* @throws PersistenceException
*/
private void deleteReportFile(final ReportFileRepNode repFileNode) throws PersistenceException {
@SuppressWarnings("rawtypes") RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit(ProjectManager.getInstance().getCurrentProject(), // $NON-NLS-1$
"deleteReportFile") {
@Override
protected void run() throws LoginException, PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) {
try {
IPath location = Path.fromOSString(repFileNode.getResource().getProjectRelativePath().toOSString());
IFile latestRepIFile = ResourceManager.getRootProject().getFile(location);
if (latestRepIFile.isLinked()) {
File file = new File(latestRepIFile.getRawLocation().toOSString());
if (file.exists()) {
file.delete();
}
}
latestRepIFile.delete(true, null);
IContainer parent = latestRepIFile.getParent();
if (parent != null) {
parent.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
} catch (CoreException e) {
log.error(e, e);
}
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
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 {
PlatformUI.getWorkbench().getProgressService().run(false, false, iRunnableWithProgress);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
// refresh the parent
RepositoryNode parent = repFileNode.getParent();
if (parent != null) {
CorePlugin.getDefault().refreshDQView(parent);
}
}
Aggregations