use of org.eclipse.core.runtime.jobs.ISchedulingRule in project evosuite by EvoSuite.
the class ExtendSuiteAction method addTestJob.
// @Override
// public void selectionChanged(IAction action, ISelection selection) {
// currentSelection.clear();
//
// if (selection instanceof IStructuredSelection) {
// IStructuredSelection sel = (IStructuredSelection) selection;
//
// for (Object o : sel.toList()) {
// if (o instanceof IJavaElement) {
// IJavaElement jEl = (IJavaElement) o;
// try {
// IResource jRes = jEl.getCorrespondingResource();
// if (jRes != null) {
// jRes.accept(new IResourceVisitor() {
// @Override
// public boolean visit(IResource resource)
// throws CoreException {
// if ("java".equals(resource.getFileExtension()))
// currentSelection.add(resource);
// return true;
// }
// });
// }
// } catch (JavaModelException e) {
// System.err.println("Error while traversing resources!" + e);
// } catch (CoreException e) {
// System.err.println("Error while traversing resources!" + e);
// }
// }
// }
// }
// }
//
// @Override
// public void run(IAction action) {
// if (currentSelection.isEmpty()) {
// MessageDialog.openError(shell, "Evosuite",
// "Unable to generate test cases for selection: Cannot find .java files.");
// } else if (currentSelection.size() > 1) {
// MessageDialog.openError(shell, "Evosuite",
// "Please only select one class at a time.");
// } else {
//
// for (IResource res : currentSelection) {
// IProject proj = res.getProject();
// fixJUnitClassPath(JavaCore.create(proj));
// generateTests(res);
// }
// }
// }
/**
* Add a new test generation job to the job queue
*
* @param target
*/
@Override
protected void addTestJob(final IResource target) {
IJavaElement element = JavaCore.create(target);
IJavaElement packageElement = element.getParent();
String packageName = packageElement.getElementName();
final String suiteClass = (!packageName.equals("") ? packageName + "." : "") + target.getName().replace(".java", "").replace(File.separator, ".");
System.out.println("Building new job for " + suiteClass);
DetermineSUT det = new DetermineSUT();
IJavaProject jProject = JavaCore.create(target.getProject());
try {
String classPath = target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation().toOSString();
String SUT = det.getSUTName(suiteClass, classPath);
// choose
SelectionDialog typeDialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), target.getProject(), IJavaElementSearchConstants.CONSIDER_CLASSES, false);
Object[] sutDefault = new Object[1];
sutDefault[0] = SUT;
typeDialog.setInitialSelections(sutDefault);
typeDialog.setTitle("Please select the class under test");
typeDialog.open();
// Type selected by the user
Object[] result = typeDialog.getResult();
if (result.length > 0) {
SourceType sourceType = (SourceType) result[0];
SUT = sourceType.getFullyQualifiedName();
} else {
return;
}
Job job = new TestExtensionJob(shell, target, SUT, suiteClass);
job.setPriority(Job.SHORT);
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule = ruleFactory.createRule(target.getProject());
// IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
job.setRule(rule);
job.setUser(true);
// start as soon as possible
job.schedule();
} catch (JavaModelException e) {
e.printStackTrace();
} catch (NoJUnitClassException e) {
MessageDialog.openError(shell, "Evosuite", "Cannot find JUnit tests in " + suiteClass);
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project evosuite by EvoSuite.
the class TestGenerationAction method addTestJob.
/**
* Add a new test generation job to the job queue
*
* @param target
*/
protected void addTestJob(final IResource target) {
IJavaElement element = JavaCore.create(target);
if (element == null) {
return;
}
IJavaElement packageElement = element.getParent();
String packageName = packageElement.getElementName();
final String targetClass = (!packageName.isEmpty() ? packageName + "." : "") + target.getName().replace(".java", "").replace(File.separator, ".");
System.out.println("* Scheduling new automated job for " + targetClass);
final String targetClassWithoutPackage = target.getName().replace(".java", "");
final String suiteClassName = targetClass + Properties.JUNIT_SUFFIX;
final String suiteFileName = target.getProject().getLocation() + "/evosuite-tests/" + suiteClassName.replace('.', File.separatorChar) + ".java";
System.out.println("Checking for " + suiteFileName);
File suiteFile = new File(suiteFileName);
Job job = null;
if (suiteFile.exists()) {
MessageDialog dialog = new MessageDialog(shell, "Existing test suite found", // image
null, "A test suite for class \"" + targetClass + "\" already exists. EvoSuite will overwrite this test suite. Do you really want to proceed?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Overwrite", "Extend", "Rename Original", "Cancel" }, 0);
int returnCode = dialog.open();
// 1 == extend
if (returnCode == 1) {
IWorkspaceRoot wroot = target.getWorkspace().getRoot();
IResource suiteResource = wroot.getFileForLocation(new Path(suiteFileName));
job = new TestExtensionJob(shell, suiteResource, targetClass, suiteClassName);
} else if (returnCode == 2) {
// 2 == Rename
renameSuite(target, packageName, targetClassWithoutPackage + Properties.JUNIT_SUFFIX + ".java");
} else if (returnCode > 2) {
// Cancel
return;
}
}
if (job == null)
job = new TestGenerationJob(shell, target, targetClass, suiteClassName);
job.setPriority(Job.SHORT);
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule = ruleFactory.createRule(target.getProject());
// IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
job.setRule(rule);
job.setUser(true);
// start as soon as possible
job.schedule();
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project ecf by eclipse.
the class ResourcesShare method handleResourceChangeMessage.
private void handleResourceChangeMessage(byte[] data) throws Exception {
IModelChange remoteChange = ResourcesSynchronizationStrategy.getInstance().deserializeRemoteChange(data);
final IModelChange[] remoteChanges = ResourcesSynchronizationStrategy.getInstance().transformRemoteChange(remoteChange);
// create a scheduling rule to lock the projects
ISchedulingRule[] rules = new ISchedulingRule[sharedProjects.size()];
int index = 0;
for (Iterator it = sharedProjects.iterator(); it.hasNext(); ) {
String projectName = (String) it.next();
rules[index] = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
index++;
}
try {
// lock to prevent resource changes from being propagated
lock(remoteChanges);
applyRemoteChanges(remoteChanges, new MultiRule(rules));
} finally {
// unlock now that we've applied the remote changes to our
// own workspace
unlock(remoteChanges);
}
if (remoteChange instanceof BatchModelChange) {
BatchModelChange batchChange = (BatchModelChange) remoteChange;
batchChange.setOutgoing(false);
batchChange.setTime(System.currentTimeMillis());
SyncResourcesCore.add(batchChange);
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project titan.EclipsePlug-ins by eclipse.
the class FormatLog method createRuleFromResources.
private ISchedulingRule createRuleFromResources(final IFile file, final IFile[] targetFiles) {
final IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
final ISchedulingRule rule1 = ruleFactory.createRule(file);
ISchedulingRule combinedRule = MultiRule.combine(rule1, null);
for (final IFile targetFile : targetFiles) {
combinedRule = MultiRule.combine(ruleFactory.createRule(targetFile), combinedRule);
}
return combinedRule;
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project titan.EclipsePlug-ins by eclipse.
the class ProjectSourceParser method makefileCreatingAnalyzeAll.
/**
* This function behaves just like the {@link #analyzeAll(IFile)}
* function. With the only difference being that it does not have a
* scheduling rule and does not can not run in parallel with the calling
* party..
* <p>
* This function should only be called if no on-the-fly check was run
* previously, it is required to have one run, but the scheduling rules
* of the actual job does not allow it to run with its own scheduling
* rules. In such cases the external scheduling rules must provide the
* protection, that is usually provided by its own rules.
*/
// FIXME this function is only temporary, it should be removed once its
// functionality is available on any other way
public void makefileCreatingAnalyzeAll() {
fullAnalyzersRunning.incrementAndGet();
ISchedulingRule rule = getSchedulingRule();
Job.getJobManager().beginRule(rule, new NullProgressMonitor());
try {
internalDoAnalyzeWithReferences(null);
} catch (Exception e) {
ErrorReporter.logExceptionStackTrace(e);
} finally {
Job.getJobManager().endRule(rule);
fullAnalyzersRunning.decrementAndGet();
}
}
Aggregations