in ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaInterpreterRunner.java [178:320]
public static void doRunImpl(InterpreterConfig config, ILaunch launch,
IRutaInterpreterRunnerConfig iconfig, IProgressMonitor monitor) throws CoreException {
String launchMode = launch.getLaunchMode();
IScriptProject proj = AbstractScriptLaunchConfigurationDelegate
.getScriptProject(launch.getLaunchConfiguration());
IPath projectPath = proj.getResource().getLocation();
IPath inputDirPath = projectPath.append(RutaProjectUtils.getDefaultInputLocation());
IPath outputDirPath = projectPath.append(RutaProjectUtils.getDefaultOutputLocation());
ClassLoader classLoader = RutaProjectUtils.getClassLoader(proj.getProject());
String engine = RutaProjectUtils.getAnalysisEngineDescriptorPath(config.getScriptFilePath(),
proj.getProject(), classLoader).toPortableString();
IPath rootPath = RutaProjectUtils.getDescriptorRootPath(proj.getProject());
File inputDir = inputDirPath.makeAbsolute().toFile();
File outputDir = outputDirPath.makeAbsolute().toFile();
if (!inputDir.exists()) {
inputDir.mkdirs();
IFolder folder = proj.getProject().getFolder(RutaProjectUtils.getDefaultInputLocation());
folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
IFolder outputFolder = proj.getProject().getFolder(RutaProjectUtils.getDefaultOutputLocation());
if (!outputDir.exists()) {
outputDir.mkdirs();
outputFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
IPreferenceStore store = RutaIdeUIPlugin.getDefault().getPreferenceStore();
boolean clearOutput = store.getBoolean(RutaCorePreferences.PROJECT_CLEAR_OUTPUT);
if (clearOutput) {
List<File> outputFiles = getFiles(outputDir, false);
for (File file : outputFiles) {
file.delete();
}
outputFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
List<File> inputFiles = getFiles(inputDir, false);
int ticks = (inputFiles.size() * 2) + 1;
SubProgressMonitor mon = new SubProgressMonitor(monitor, ticks);
mon.setTaskName("Initializing");
Handler handler = initConsoleLink(config.getScriptFilePath().lastSegment());
CAS cas = null;
AnalysisEngine ae = null;
try {
File specFile = new File(engine);
XMLInputSource in = new XMLInputSource(specFile);
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
resMgr.setDataPath(rootPath.toPortableString());
ae = UIMAFramework.produceAnalysisEngine(specifier, resMgr, null);
} catch (Exception e) {
String message = e.getMessage();
DLTKCore.error(message, e);
clearConsoleLink(handler);
throw new CoreException(new Status(IStatus.ERROR, RutaIdeUIPlugin.PLUGIN_ID,
ScriptLaunchConfigurationConstants.ERR_INTERNAL_ERROR, message, e));
}
try {
if ("debug".equals(launchMode)) {
ae.setConfigParameterValue(RutaEngine.PARAM_DEBUG, true);
ae.setConfigParameterValue(RutaEngine.PARAM_DEBUG_WITH_MATCHES, true);
ae.setConfigParameterValue(RutaEngine.PARAM_PROFILE, true);
ae.setConfigParameterValue(RutaEngine.PARAM_STATISTICS, true);
ae.setConfigParameterValue(RutaEngine.PARAM_CREATED_BY, true);
ae.reconfigure();
}
} catch (Exception e) {
clearConsoleLink(handler);
String message = e.getMessage();
DLTKCore.error(message, e);
throw new CoreException(new Status(IStatus.ERROR, RutaIdeUIPlugin.PLUGIN_ID,
ScriptLaunchConfigurationConstants.ERR_INTERNAL_ERROR, message, e));
}
mon.worked(1);
for (File each : inputFiles) {
mon.setTaskName("Processing " + each.getName());
if (mon.isCanceled()) {
break;
}
try {
if (cas == null) {
cas = ae.newCAS();
} else {
cas.reset();
}
if (each.getName().endsWith("xmi")) {
XmiCasDeserializer.deserialize(new FileInputStream(each), cas, true);
} else {
cas.setDocumentText(getText(each));
}
if (mon.isCanceled()) {
break;
}
RutaEngine.removeSourceDocumentInformation(cas);
RutaEngine.addSourceDocumentInformation(cas, each);
ae.process(cas);
mon.worked(1);
if (mon.isCanceled()) {
break;
}
File outputFile = new File(outputDir, each.getName() + ".xmi");
mon.setTaskName("Saving " + outputFile.getName());
writeXmi(cas, outputFile);
mon.worked(1);
} catch (Exception e) {
if (cas != null) {
cas.release();
}
if (ae != null) {
ae.destroy();
}
clearConsoleLink(handler);
String message = e.getMessage();
DLTKCore.error(message, e);
throw new CoreException(new Status(IStatus.ERROR, RutaIdeUIPlugin.PLUGIN_ID,
ScriptLaunchConfigurationConstants.ERR_INTERNAL_ERROR, message, e));
}
}
if (cas != null) {
cas.release();
}
if (ae != null) {
ae.destroy();
}
IFolder folder = outputFolder;
folder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
clearConsoleLink(handler);
mon.done();
}