Search in sources :

Example 36 with ISchedulingRule

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;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 37 with ISchedulingRule

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
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) BufferedOutputStream(java.io.BufferedOutputStream) IResource(org.eclipse.core.resources.IResource)

Example 38 with ISchedulingRule

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
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 39 with ISchedulingRule

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);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 40 with ISchedulingRule

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);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IContainer(org.eclipse.core.resources.IContainer) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)124 CoreException (org.eclipse.core.runtime.CoreException)46 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)46 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)37 IWorkspace (org.eclipse.core.resources.IWorkspace)31 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)29 PersistenceException (org.talend.commons.exception.PersistenceException)19 IStatus (org.eclipse.core.runtime.IStatus)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 Status (org.eclipse.core.runtime.Status)16 IResource (org.eclipse.core.resources.IResource)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 ArrayList (java.util.ArrayList)13 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)13 Job (org.eclipse.core.runtime.jobs.Job)12 IFile (org.eclipse.core.resources.IFile)11 HashSet (java.util.HashSet)10 IPath (org.eclipse.core.runtime.IPath)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)10