Search in sources :

Example 76 with ISchedulingRule

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

the class JSPBatchValidator method validateInJob.

public IStatus validateInJob(final IValidationContext helper, final IReporter reporter) throws ValidationException {
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                doValidate(helper, reporter);
            } catch (ValidationException e) {
                throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID_JSP_CORE, 0, PLUGIN_ID_JSP_CORE, e));
            }
        }
    };
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() instanceof ValidationException) {
            throw (ValidationException) e.getCause();
        }
        throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e);
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) CoreException(org.eclipse.core.runtime.CoreException) IValidatorJob(org.eclipse.wst.validation.internal.provisional.core.IValidatorJob) Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 77 with ISchedulingRule

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

the class JSPBatchValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate((IFile) resource))
        return null;
    final ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    if (result.getDependsOn() != null) {
        fDependsOn = new HashSet(Arrays.asList(result.getDependsOn()));
    } else {
        fDependsOn = new HashSet();
    }
    // add web.xml as a dependency
    addDependsOn(DeploymentDescriptorPropertyCache.getInstance().getWebXML(resource.getFullPath()));
    // List relevant JSP 2.0 preludes/codas as dependencies
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(resource.getFullPath());
    for (int j = 0; j < propertyGroups.length; j++) {
        IPath[] preludes = propertyGroups[j].getIncludePrelude();
        for (int i = 0; i < preludes.length; i++) {
            addDependsOn(workspaceRoot.getFile(preludes[i]));
        }
        IPath[] codas = propertyGroups[j].getIncludeCoda();
        for (int i = 0; i < codas.length; i++) {
            addDependsOn(workspaceRoot.getFile(codas[i]));
        }
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            if (fragmentCheck((IFile) resource)) {
                validateFile((IFile) resource, reporter);
            }
            IResource[] resources = (IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]);
            result.setDependsOn(resources);
            fDependsOn.clear();
        }
    };
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) PropertyGroup(org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup) IPath(org.eclipse.core.runtime.IPath) ValidationResult(org.eclipse.wst.validation.ValidationResult) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IValidatorJob(org.eclipse.wst.validation.internal.provisional.core.IValidatorJob) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 78 with ISchedulingRule

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

the class DeleteServerDialog method buttonPressed.

protected void buttonPressed(int buttonId) {
    if (buttonId == OK) {
        final boolean checked = (checkDeleteConfigs != null && checkDeleteConfigs.getSelection());
        final boolean deleteRunning = (checkDeleteRunning == null || checkDeleteRunning.getSelection());
        final boolean deleteRunningStop = (checkDeleteRunningStop != null && checkDeleteRunningStop.getSelection());
        Thread t = new Thread("Delete servers") {

            public void run() {
                if (runningServersList.size() > 0) {
                    // stop servers and/or updates servers' list
                    prepareForDeletion(deleteRunning, deleteRunningStop);
                }
                Job job = new Job(Messages.deleteServerTask) {

                    protected IStatus run(IProgressMonitor monitor) {
                        if (servers.length == 0) {
                            // all servers have been deleted from list
                            return Status.OK_STATUS;
                        }
                        try {
                            if (monitor.isCanceled())
                                return Status.CANCEL_STATUS;
                            for (DeleteServerDialogExtension curDialogExtension : dialogExtensionLst) {
                                curDialogExtension.performPreDeleteAction(monitor);
                            }
                            int size = servers.length;
                            for (int i = 0; i < size; i++) servers[i].delete();
                            if (monitor.isCanceled())
                                return Status.CANCEL_STATUS;
                            if (checked) {
                                size = configs.length;
                                for (int i = 0; i < size; i++) {
                                    configs[i].refreshLocal(IResource.DEPTH_INFINITE, monitor);
                                    configs[i].delete(true, true, monitor);
                                }
                            }
                            for (DeleteServerDialogExtension curDialogExtension : dialogExtensionLst) {
                                curDialogExtension.performPostDeleteAction(monitor);
                            }
                        } catch (Exception e) {
                            if (Trace.SEVERE) {
                                Trace.trace(Trace.STRING_SEVERE, "Error while deleting resources", e);
                            }
                            return new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, 0, e.getMessage(), e);
                        }
                        return Status.OK_STATUS;
                    }
                };
                // set rule for workspace and servers
                int size = servers.length;
                ISchedulingRule[] rules = new ISchedulingRule[size + 1];
                for (int i = 0; i < size; i++) rules[i] = servers[i];
                IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
                rules[size] = ruleFactory.createRule(ResourcesPlugin.getWorkspace().getRoot());
                job.setRule(MultiRule.combine(rules));
                job.setPriority(Job.BUILD);
                job.schedule();
            }
        };
        t.setDaemon(true);
        t.start();
    }
    super.buttonPressed(buttonId);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResourceRuleFactory(org.eclipse.core.resources.IResourceRuleFactory) Job(org.eclipse.core.runtime.jobs.Job) DeleteServerDialogExtension(org.eclipse.wst.server.ui.DeleteServerDialogExtension) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 79 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class ResourceRuleFactory method validateEditRule.

/**
 * Default implementation of <code>IResourceRuleFactory#validateEditRule</code>.
 * This default implementation returns a rule that combines the parents of
 * all read-only resources, or <code>null</code> if there are no read-only
 * resources.
 * <p>
 * Subclasses may override this method. The rule provided by an overriding
 * method must at least contain the rule from this default implementation.
 *
 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
 * @see org.eclipse.core.resources.IResourceRuleFactory#validateEditRule(IResource[])
 */
public ISchedulingRule validateEditRule(IResource[] resources) {
    if (resources.length == 0)
        return null;
    // optimize rule for single file
    if (resources.length == 1)
        return isReadOnly(resources[0]) ? parent(resources[0]) : null;
    // need a lock on the parents of all read-only files
    HashSet rules = new HashSet();
    for (int i = 0; i < resources.length; i++) if (isReadOnly(resources[i]))
        rules.add(parent(resources[i]));
    if (rules.isEmpty())
        return null;
    if (rules.size() == 1)
        return (ISchedulingRule) rules.iterator().next();
    ISchedulingRule[] ruleArray = (ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) HashSet(java.util.HashSet) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 80 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method copy.

/* (non-Javadoc)
	 * @see IResource#copy(IPath, int, IProgressMonitor)
	 */
public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    try {
        monitor = Policy.monitorFor(monitor);
        String message = NLS.bind(Messages.resources_copying, 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().copyRule(this, destResource);
        try {
            workspace.prepareOperation(rule, monitor);
            // The following assert method throws CoreExceptions as stated in the IResource.copy API
            // and assert for programming errors. See checkCopyRequirements for more information.
            assertCopyRequirements(destination, getType(), updateFlags);
            workspace.beginOperation(true);
            getLocalManager().copy(this, destResource, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)116 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)41 CoreException (org.eclipse.core.runtime.CoreException)40 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)32 IWorkspace (org.eclipse.core.resources.IWorkspace)30 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 PersistenceException (org.talend.commons.exception.PersistenceException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 Status (org.eclipse.core.runtime.Status)15 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)12 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