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