in ruta-ep-addons/src/main/java/org/apache/uima/ruta/utils/apply/AbstractApplyScriptHandlerJob.java [79:187]
public IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Collecting files...", 1);
if (HandlerUtil.getCurrentSelection(event) instanceof IStructuredSelection) {
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
Iterator<?> iter = selection.iterator();
IResource first = null;
List<IPath> paths = new ArrayList<IPath>();
while (iter.hasNext()) {
Object object = iter.next();
if (object instanceof IResource) {
IResource resource = (IResource) object;
if (first == null) {
first = resource;
}
paths.addAll(getPaths(resource));
}
}
CAS cas = null;
AnalysisEngine ae = null;
try {
IPath rootPath = RutaProjectUtils.getDescriptorRootPath(scriptFile.getProject());
ClassLoader classLoader = RutaProjectUtils.getClassLoader(scriptFile.getProject());
IPath descriptorPath = RutaProjectUtils.getAnalysisEngineDescriptorPath(
scriptFile.getLocation(), scriptFile.getProject(), classLoader);
XMLInputSource in = new XMLInputSource(descriptorPath.toPortableString());
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
resMgr.setDataPath(rootPath.toPortableString());
ae = UIMAFramework.produceAnalysisEngine(specifier, resMgr, null);
initAE(ae);
ae.reconfigure();
} catch (Exception e) {
DLTKCore.error(e.getMessage(), e);
return Status.CANCEL_STATUS;
}
monitor.beginTask("Processing... ", paths.size());
for (IPath path : paths) {
if (monitor.isCanceled()) {
break;
}
monitor.setTaskName("Processing " + path.lastSegment() + "... ");
try {
if (cas == null) {
cas = ae.newCAS();
} else {
cas.reset();
}
if (path.getFileExtension().equals("xmi")) {
XmiCasDeserializer.deserialize(new FileInputStream(path.toPortableString()), cas, true);
} else {
cas.setDocumentText(getText(path.toPortableString()));
}
RutaEngine.removeSourceDocumentInformation(cas);
RutaEngine.addSourceDocumentInformation(cas, new File(path.toPortableString()));
ae.process(cas);
} catch (Exception e) {
DLTKCore.error(e.getMessage(), e);
monitor.worked(1);
continue;
}
if (createXMI) {
monitor.setTaskName("Writing " + path.lastSegment() + "... ");
File newFile = null;
if (path.getFileExtension().equals("xmi")) {
newFile = new File(path.toPortableString());
} else {
newFile = new File(path.toPortableString() + ".xmi");
}
try {
writeXmi(cas, newFile);
} catch (Exception e) {
DLTKCore.error(e.getMessage(), e);
monitor.worked(1);
continue;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IPath makeRelativeTo = path.makeRelativeTo(root.getLocation());
IResource resource = root.findMember(makeRelativeTo);
try {
if (resource != null) {
resource.getParent()
.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
} catch (CoreException e) {
}
}
monitor.worked(1);
}
if (cas != null) {
cas.release();
}
if (ae != null) {
ae.destroy();
}
}
monitor.done();
return Status.OK_STATUS;
}