}
@Override
public IStatus run(IProgressMonitor monitor) {
final TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
final TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
debugPage.saveState();
debugView.showBusy(true);
IResource r = debugPage.getResource();
ArrayList<TestCasData> testCasData = (ArrayList) debugPage.getViewer().getInput();
monitor.beginTask("Running evaluation, please wait", testCasData.size());
IProject project = r.getProject();
IPath engineDescriptorPath = RutaProjectUtils.getEngineDescriptorPath(r.getLocation(),
project);
try {
XMLInputSource in = new XMLInputSource(engineDescriptorPath.toPortableString());
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
String desc = null;
desc = engineDescriptorPath.toPortableString();
XMLInputSource in2 = new XMLInputSource(desc);
Object descriptor = UIMAFramework.getXMLParser().parse(in2);
CAS runCas = ae.newCAS();
for (TestCasData td : testCasData) {
runCas.reset();
String elementName = r.getLocation().lastSegment();
monitor.setTaskName("Evaluating " + td.getPath().lastSegment());
int lastIndexOf = elementName.lastIndexOf(RutaEngine.SCRIPT_FILE_EXTENSION);
if (lastIndexOf != -1) {
elementName = elementName.substring(0, lastIndexOf);
}
CAS testCas = getTestCas(descriptor);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(new File(td.getPath().toPortableString()));
XmiCasDeserializer.deserialize(inputStream, testCas, true);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
for (Iterator<CAS> iterator = testCas.getViewIterator(); iterator.hasNext();) {
CAS each = iterator.next();
String viewName = each.getViewName();
try {
CAS view = runCas.getView(viewName);
view.setDocumentText(each.getDocumentText());
} catch (Exception e) {
RutaAddonsPlugin.error(e);
}
}
testCas = testCas.getView(viewCasName);
runCas = runCas.getView(viewCasName);
IPreferenceStore store = RutaAddonsPlugin.getDefault().getPreferenceStore();
String factoryName = store.getString(TestingPreferenceConstants.EVALUATOR_FACTORY);
ICasEvaluator evaluator = RutaAddonsPlugin.getCasEvaluatorFactoryById(factoryName)
.createEvaluator();
ae.process(runCas);
CAS resultCas = evaluator.evaluate(testCas, runCas, debugPage.getExcludedTypes());
IPath path2Test = td.getPath().removeLastSegments(1);
IPath estimatedTestPath = project.getFullPath().append(
RutaProjectUtils.getDefaultTestLocation());
IPath path2recource = r.getFullPath();
IPath projectRelativePath2Script = path2recource.removeFirstSegments(2);
IPath estimatedTestFolderPath = estimatedTestPath.append(projectRelativePath2Script
.removeFileExtension());
IPath path2Result = path2Test.append(TestCasData.RESULT_FOLDER);
IPath path2ResultFile = path2Result.append(td.getPath().removeFileExtension()
.lastSegment()
+ ".result.xmi");
if (!path2Test.toOSString().contains(estimatedTestFolderPath.toOSString())) {
path2Result = project.getLocation()
.append(RutaProjectUtils.getDefaultTestLocation())
.append(RutaProjectUtils.getDefaultTempTestLocation());
path2ResultFile = path2Result.append(td.getPath().removeFileExtension().lastSegment()
+ ".result.xmi");
}
File resultFile = new File(path2ResultFile.toPortableString());
writeXmi(resultCas, resultFile);
td.setResultPath(path2ResultFile);
// calculateEvaluatData(td, resultCas);
EvalDataProcessor.calculateEvaluatData(td, resultCas);
debugView.getDefaultPage().getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
debugPage.getViewer().refresh();
}
});
monitor.worked(1);
r.getProject().getFolder(path2Result)
.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());