You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/12/18 15:18:24 UTC
svn commit: r1551948 - in /uima/ruta/trunk:
ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/
ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/
ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/ ruta...
Author: pkluegl
Date: Wed Dec 18 14:18:24 2013
New Revision: 1551948
URL: http://svn.apache.org/r1551948
Log:
UIMA-3441
- applied patch
Modified:
uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/RerunActionHandler.java
uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/TestViewPage.java
uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaLanguageToolkit.java
uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java
Modified: uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/RerunActionHandler.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/RerunActionHandler.java?rev=1551948&r1=1551947&r2=1551948&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/RerunActionHandler.java (original)
+++ uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/handlers/RerunActionHandler.java Wed Dec 18 14:18:24 2013
@@ -21,6 +21,7 @@ package org.apache.uima.ruta.testing.ui.
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,7 +32,9 @@ import java.util.List;
import org.apache.uima.UIMAFramework;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.TypeSystem;
@@ -47,6 +50,8 @@ import org.apache.uima.resource.metadata
import org.apache.uima.ruta.addons.RutaAddonsPlugin;
import org.apache.uima.ruta.engine.RutaEngine;
import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.ruta.ide.launching.RutaLaunchConfigurationConstants;
+import org.apache.uima.ruta.ide.launching.RutaLaunchConstants;
import org.apache.uima.ruta.testing.evaluator.ICasEvaluator;
import org.apache.uima.ruta.testing.preferences.TestingPreferenceConstants;
import org.apache.uima.ruta.testing.ui.views.TestCasData;
@@ -56,6 +61,7 @@ import org.apache.uima.ruta.testing.ui.v
import org.apache.uima.ruta.testing.ui.views.util.EvalDataProcessor;
import org.apache.uima.ruta.type.EvalAnnotation;
import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.FileUtils;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
import org.apache.uima.util.XMLSerializer;
@@ -63,8 +69,10 @@ import org.eclipse.core.commands.Executi
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -73,7 +81,17 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.xml.sax.SAXException;
@@ -100,6 +118,9 @@ public class RerunActionHandler implemen
}
}
+ /**
+ * Handler that runs the script to be tested and updates the GUI.
+ */
private class RerunHandlerJob extends Job {
ExecutionEvent event;
@@ -121,21 +142,228 @@ public class RerunActionHandler implemen
@Override
public IStatus run(IProgressMonitor monitor) {
- final TestPageBookView debugView = (TestPageBookView) HandlerUtil.getActivePart(event);
- final TestViewPage debugPage = (TestViewPage) debugView.getCurrentPage();
+
+ // handle GUI
+ final TestPageBookView testPageView = (TestPageBookView) HandlerUtil.getActivePart(event);
+ final TestViewPage debugPage = (TestViewPage) testPageView.getCurrentPage();
debugPage.saveState();
- debugView.showBusy(true);
+ testPageView.showBusy(true);
+
+ // init variables
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(),
+ final IFile fScript = (IFile) r;
+ final IProject project = r.getProject();
+ final IPath engineDescriptorPath = RutaProjectUtils.getEngineDescriptorPath(r.getLocation(),
project);
+ IPath typeSystemDescriptorPath = RutaProjectUtils.getTypeSystemDescriptorPath(
+ fScript.getLocation(), project);
+
+ // show message
+ ArrayList<TestCasData> testCasData = (ArrayList) debugPage.getViewer().getInput();
+ int numFiles = testCasData.size();
+ monitor.beginTask("Running evaluation, please wait", numFiles);
+
+ // switch usage mode: old (only Ruta) vs. new (supports java/uimaFIT AEs)
+ boolean javaSupportMode = debugPage.doExtendClasspath();
+ if (!javaSupportMode) {
+ // only Ruta mode (classpath NOT expanded)
+ IStatus status = evalRutaOnlyScript(monitor, testPageView, debugPage, fScript, project,
+ engineDescriptorPath, testCasData);
+ if (status.equals(IStatus.ERROR)) {
+ Shell shell = Display.getCurrent().getActiveShell();
+ MessageDialog.openWarning(shell, "Error", status.getMessage());
+ }
+ return status;
+ }
+
+ // MAIN LOGIC for java support mode
+ // TODO:
+
+ // * write clean run files into a temp directory, remember file names
+ // TODO this approach (may) causes problems, when Java/uimaFIT engines have their own
+ // typesystems...
+ final IPath cleanInputPath = project.getLocation()
+ .append(RutaProjectUtils.getDefaultTestLocation())
+ .append(RutaProjectUtils.getDefaultCleanTestLocation());
+ clearFolder(project, cleanInputPath);
+ writeCleanInputFiles(testCasData, project, typeSystemDescriptorPath, cleanInputPath, monitor);
+ if (monitor.isCanceled()) {
+ // TODO call monitor.done()
+ return Status.CANCEL_STATUS;
+ }
+
+ // * apply script to the clean run files
+ final IPath runTestPath = project.getLocation()
+ .append(RutaProjectUtils.getDefaultTestLocation())
+ .append(RutaProjectUtils.getDefaultTempTestLocation());
+ clearFolder(project, runTestPath);
+ runWithJVM(monitor, fScript, cleanInputPath, runTestPath);
+
+ // * for each (goldFile, runFile)-pair:
try {
+ XMLInputSource in = new XMLInputSource(typeSystemDescriptorPath.toPortableString());
+ TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(in);
+ CAS runCas = CasCreationUtils.createCas(tsd, null, null);
+ CAS goldCas = CasCreationUtils.createCas(tsd, null, null);
+ for (TestCasData td : testCasData) {
+ // init etc
+ runCas.reset();
+ goldCas.reset();
+ // deserialize CASes
+ IPath path2RunFile = runTestPath.append(td.getPath().toFile().getName());
+ String runFilePath = path2RunFile.toPortableString();
+ File runFile = new File(runFilePath);
+ deserializeCASs(goldCas, td, runCas, runFile);
+ runCas = runCas.getView(viewCasName);
+ goldCas = goldCas.getView(viewCasName);
+ // ** create TP, FP, FN annotations
+ // ** collect results and gather eval data
+ evalLogicAndUpdateGUI(monitor, testPageView, debugPage, fScript, project, runCas,
+ goldCas, td);
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ }
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ RutaAddonsPlugin.error(e);
+ }
+
+ monitor.done();
+
+ return Status.OK_STATUS;
+ }
+
+ private void clearFolder(final IProject project, final IPath folderPath) {
+ FileUtils.deleteAllFiles(folderPath.toFile()); // clear folder
+ try {
+ project.getFolder(folderPath.makeRelativeTo(project.getLocation())).refreshLocal(
+ IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ private void deserializeCASs(CAS tdCas, TestCasData td, CAS casA, File fileA)
+ throws FileNotFoundException, SAXException, IOException {
+ if (!fileA.exists()) {
+ throw new FileNotFoundException(fileA.getAbsolutePath());
+ }
+ FileInputStream inputStream = null;
+ try {
+ inputStream = new FileInputStream(new File(td.getPath().toPortableString()));
+ XmiCasDeserializer.deserialize(inputStream, tdCas, true);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ try {
+ inputStream = new FileInputStream(fileA);
+ XmiCasDeserializer.deserialize(inputStream, casA, true);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+ }
+
+ private void writeCleanInputFiles(List<TestCasData> testCasData, IProject project,
+ IPath tsDescriptorPath, IPath cleanInputPath, IProgressMonitor monitor) {
+ try {
+ // create CAS:
+ XMLInputSource in = new XMLInputSource(tsDescriptorPath.toPortableString());
+ TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription(in);
+
+ CAS cleanCas = CasCreationUtils.createCas(tsd, null, null);
+
+ for (TestCasData td : testCasData) {
+ // init etc
+ cleanCas.reset(); // clean
+ // deserialize CASes
+ FileInputStream inputStreamRun = null;
+ try {
+ inputStreamRun = new FileInputStream(new File(td.getPath().toPortableString()));
+ XmiCasDeserializer.deserialize(inputStreamRun, cleanCas, true);
+ } finally {
+ if (inputStreamRun != null) {
+ inputStreamRun.close();
+ }
+ }
+ cleanCas = cleanCas.getView(viewCasName);
+
+ // gather uima types
+ if (includedTypes != null && !includedTypes.isEmpty()) {
+ excludedTypes = new ArrayList<String>();
+ List<Type> types = cleanCas.getTypeSystem().getProperlySubsumedTypes(
+ cleanCas.getAnnotationType());
+ for (Type type : types) {
+ if (!includedTypes.contains(type.getName())) {
+ excludedTypes.add(type.getName());
+ }
+ }
+ }
+ List<AnnotationFS> toRemove = new LinkedList<AnnotationFS>();
+ if (excludedTypes != null && !excludedTypes.isEmpty()) {
+ AnnotationIndex<AnnotationFS> annotationIndex = cleanCas.getAnnotationIndex();
+ for (AnnotationFS annotationFS : annotationIndex) {
+ Type type = annotationFS.getType();
+ String typeName = type.getName();
+ if (includedTypes.contains(typeName) || !excludedTypes.contains(typeName)) {
+ if (type != null
+ && cleanCas.getTypeSystem().subsumes(cleanCas.getAnnotationType(), type)) {
+ toRemove.add(annotationFS);
+ }
+ }
+ }
+ }
+ // remove annotations from run (test) cas
+ if (excludedTypes != null && excludedTypes.isEmpty() && includedTypes != null
+ && includedTypes.isEmpty()) {
+ AnnotationIndex<AnnotationFS> annotationIndex = cleanCas.getAnnotationIndex();
+ for (AnnotationFS each : annotationIndex) {
+ toRemove.add(each);
+ }
+ }
+ for (AnnotationFS each : toRemove) {
+ if (!cleanCas.getDocumentAnnotation().equals(each)) {
+ cleanCas.removeFsFromIndexes(each);
+ }
+ }
+ // store clean CAS
+ IPath path2CleanFile = computeCleanPath(cleanInputPath, td);
+ String fPath = path2CleanFile.toPortableString();
+ File cleanFile = new File(fPath);
+ writeXmi(cleanCas, cleanFile);
+
+ td.setResultPath(path2CleanFile);
+
+ cleanCas.release();
+
+ if (monitor.isCanceled())
+ return;
+ }
+ project.getFolder(cleanInputPath.makeRelativeTo(project.getLocation())).refreshLocal(
+ IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ } catch (Exception e) {
+ RutaAddonsPlugin.error(e);
+ }
+ }
+
+ private IPath computeCleanPath(IPath cleanInputPath, TestCasData td) {
+ return cleanInputPath.append(td.getPath().removeFileExtension().lastSegment() + ".xmi");
+ }
+
+ private IStatus evalRutaOnlyScript(IProgressMonitor monitor,
+ final TestPageBookView testPageView, final TestViewPage debugPage, IFile fScript,
+ final IProject project, final IPath engineDescriptorPath,
+ ArrayList<TestCasData> testCasData) {
+ try {
+ // create AE:
XMLInputSource in = new XMLInputSource(engineDescriptorPath.toPortableString());
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
-
+ // create (empty) CAS objects:
String desc = null;
desc = engineDescriptorPath.toPortableString();
XMLInputSource in2 = new XMLInputSource(desc);
@@ -144,15 +372,16 @@ public class RerunActionHandler implemen
CAS testCas = getEmptyCas(descriptor);
for (TestCasData td : testCasData) {
+ // init td etc
runCas.reset();
testCas.reset();
- String elementName = r.getLocation().lastSegment();
- monitor.setTaskName("Evaluating " + td.getPath().lastSegment());
+ String elementName = fScript.getLocation().lastSegment();
+ monitor.setTaskName("Processing [w/o classpatch ext.] " + td.getPath().lastSegment());
int lastIndexOf = elementName.lastIndexOf(RutaEngine.SCRIPT_FILE_EXTENSION);
if (lastIndexOf != -1) {
elementName = elementName.substring(0, lastIndexOf);
}
-
+ // deserialize CASes
FileInputStream inputStreamTest = null;
try {
inputStreamTest = new FileInputStream(new File(td.getPath().toPortableString()));
@@ -174,6 +403,7 @@ public class RerunActionHandler implemen
testCas = testCas.getView(viewCasName);
runCas = runCas.getView(viewCasName);
+ // gather uima eval-types
if (includedTypes != null && !includedTypes.isEmpty()) {
excludedTypes = new ArrayList<String>();
List<Type> types = runCas.getTypeSystem().getProperlySubsumedTypes(
@@ -184,7 +414,6 @@ public class RerunActionHandler implemen
}
}
}
-
List<AnnotationFS> toRemove = new LinkedList<AnnotationFS>();
if (excludedTypes != null && !excludedTypes.isEmpty()) {
AnnotationIndex<AnnotationFS> annotationIndex = runCas.getAnnotationIndex();
@@ -199,6 +428,7 @@ public class RerunActionHandler implemen
}
}
}
+ // remove annotations from run (test) cas
if (excludedTypes != null && excludedTypes.isEmpty() && includedTypes != null
&& includedTypes.isEmpty()) {
AnnotationIndex<AnnotationFS> annotationIndex = runCas.getAnnotationIndex();
@@ -207,74 +437,92 @@ public class RerunActionHandler implemen
}
}
for (AnnotationFS each : toRemove) {
- if(!runCas.getDocumentAnnotation().equals(each)) {
+ if (!runCas.getDocumentAnnotation().equals(each)) {
runCas.removeFsFromIndexes(each);
}
}
- IPreferenceStore store = RutaAddonsPlugin.getDefault().getPreferenceStore();
- String factoryName = store.getString(TestingPreferenceConstants.EVALUATOR_FACTORY);
- ICasEvaluator evaluator = RutaAddonsPlugin.getCasEvaluatorFactoryById(factoryName)
- .createEvaluator();
- boolean includeSubtypes = store.getBoolean(TestingPreferenceConstants.INCLUDE_SUBTYPES);
- boolean useAllTypes = store.getBoolean(TestingPreferenceConstants.ALL_TYPES);
-
+ // process run cas and evaluate it
ae.process(runCas);
- CAS resultCas = evaluator.evaluate(testCas, runCas, excludedTypes, includeSubtypes, useAllTypes);
-
- 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());
- runCas.release();
- testCas.release();
- resultCas.release();
- ae.destroy();
- if (monitor.isCanceled())
+ evalLogicAndUpdateGUI(monitor, testPageView, debugPage, fScript, project, runCas,
+ testCas, td);
+ if (monitor.isCanceled()) {
+ ae.destroy();
return Status.CANCEL_STATUS;
+ }
}
+ ae.destroy();
} catch (Exception e) {
RutaAddonsPlugin.error(e);
+ monitor.done();
+ testPageView.showBusy(false);
+ return new Status(Status.ERROR, RutaAddonsPlugin.PLUGIN_ID,
+ "Error during testing. See Error View for details.");
}
monitor.done();
- debugView.showBusy(false);
+ testPageView.showBusy(false);
return Status.OK_STATUS;
+ }
+
+ private void evalLogicAndUpdateGUI(IProgressMonitor monitor,
+ final TestPageBookView testPageView, final TestViewPage debugPage, IFile fScript,
+ final IProject project, CAS runCas, CAS goldCas, TestCasData td)
+ throws AnalysisEngineProcessException, CASException, IOException, SAXException,
+ CoreException {
+ // memento for prefs
+ IPreferenceStore store = RutaAddonsPlugin.getDefault().getPreferenceStore();
+ String factoryName = store.getString(TestingPreferenceConstants.EVALUATOR_FACTORY);
+ ICasEvaluator evaluator = RutaAddonsPlugin.getCasEvaluatorFactoryById(factoryName)
+ .createEvaluator();
+ boolean includeSubtypes = store.getBoolean(TestingPreferenceConstants.INCLUDE_SUBTYPES);
+ boolean useAllTypes = store.getBoolean(TestingPreferenceConstants.ALL_TYPES);
+
+ CAS resultCas = evaluator.evaluate(goldCas, runCas, excludedTypes, includeSubtypes,
+ useAllTypes);
+
+ // store results
+ IPath path2Test = td.getPath().removeLastSegments(1);
+
+ monitor.setTaskName("Actually evaluating " + td.getPath().lastSegment());
+
+ IPath estimatedTestPath = project.getFullPath().append(
+ RutaProjectUtils.getDefaultTestLocation());
+ IPath path2recource = fScript.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);
+
+ // finally, calculate eval data and show it in the GUI
+ EvalDataProcessor.calculateEvaluatData(td, resultCas);
+
+ testPageView.getDefaultPage().getControl().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ debugPage.getViewer().refresh();
+ }
+ });
+ monitor.worked(1);
+ project.getFolder(path2Result.makeRelativeTo(project.getLocation())).refreshLocal(
+ IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ runCas.release();
+ goldCas.release();
+ resultCas.release();
}
private CAS getEmptyCas(Object descriptor) throws ResourceInitializationException,
@@ -349,6 +597,13 @@ public class RerunActionHandler implemen
}
+ /**
+ *
+ * @param data
+ * will be filled with results
+ * @param resultCas
+ * must contain TP, FP, FN annotations
+ */
public void calculateEvaluatData(TestCasData data, CAS resultCas) {
data.setEvaluationStatus(true);
TypeSystem ts = resultCas.getTypeSystem();
@@ -424,4 +679,77 @@ public class RerunActionHandler implemen
data.setTypeEvalData(map);
}
+ // private void
+
+ /**
+ * This method assumes that gold annotations have already been removed from the files. It just
+ * applies the script to the files.
+ *
+ * @param monitor
+ * @param scriptFile
+ * @param cleanInputPath
+ */
+ private void runWithJVM(IProgressMonitor monitor, IFile scriptFile, IPath cleanInputPath,
+ IPath runOutputPath) {
+ monitor.setTaskName(String.format("Processing script \"%s\" [w classpatch ext.].",
+ scriptFile.getName()));
+
+ IProject project = scriptFile.getProject();
+
+ // init args
+ String inputDirPath = null;
+ String outputDirPath = null;
+ if (cleanInputPath != null) {
+ inputDirPath = cleanInputPath.toFile().getAbsolutePath();
+ } else {
+ // TODO throw exception
+ return;
+ }
+ if (runOutputPath != null) {
+ outputDirPath = runOutputPath.toFile().getAbsolutePath();
+ } else {
+ // TODO throw exception
+ return;
+ }
+ IPath descriptorPath = RutaProjectUtils.getEngineDescriptorPath(scriptFile.getLocation(),
+ project);
+ String descriptorAbsolutePath = descriptorPath.toFile().getAbsolutePath();
+
+ try {
+ ILaunchManager mgr = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = mgr
+ .getLaunchConfigurationType(RutaLaunchConfigurationConstants.ID_RUTA_SCRIPT);
+
+ ILaunchConfigurationWorkingCopy copy = type.newInstance(null, scriptFile.getName()
+ + ".Testing");
+ // do not use RutaLaunchConstants.ARG_INPUT_FOLDER here
+ copy.setAttribute(RutaLaunchConstants.INPUT_FOLDER, inputDirPath);
+ // do not use RutaLaunchConstants.ARG_OUTPUT_FOLDER here
+ copy.setAttribute(RutaLaunchConstants.OUTPUT_FOLDER, outputDirPath);
+ copy.setAttribute(RutaLaunchConstants.ARG_DESCRIPTOR, descriptorAbsolutePath);
+ copy.setAttribute(RutaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
+ ILaunchConfiguration lc = copy.doSave();
+
+ String mode = ILaunchManager.RUN_MODE;
+ ILaunch launch = new Launch(lc, mode, null);
+
+ ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
+
+ ILaunch launched = launchConfiguration.launch(ILaunchManager.RUN_MODE, monitor);
+
+ while (!launched.isTerminated()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
}
Modified: uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/TestViewPage.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/TestViewPage.java?rev=1551948&r1=1551947&r2=1551948&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/TestViewPage.java (original)
+++ uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/testing/ui/views/TestViewPage.java Wed Dec 18 14:18:24 2013
@@ -66,9 +66,11 @@ import org.eclipse.swt.events.KeyAdapter
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
@@ -102,20 +104,23 @@ public class TestViewPage extends Page i
private List<String> excludedTypes = new ArrayList<String>();
private List<String> includedTypes = new ArrayList<String>();
-
+
private ListLabelProvider labelProvider;
- public TestViewPage(Composite parent, IResource r) {
- super();
- this.script = r;
+ private Button buttonDoJavaRun;
+
+ private boolean doJavaRun;
+
+ public TestViewPage(Composite parent, IResource scriptResource) {
+ this(scriptResource);
this.overlay = new Composite(parent, 0);
- this.caretaker = new Caretaker();
this.propertyChangeListener = null;
}
- public TestViewPage(IResource r) {
+ public TestViewPage(IResource scriptResource) {
super();
- this.script = r;
+ this.doJavaRun = true;
+ this.script = scriptResource;
this.caretaker = new Caretaker();
}
@@ -143,6 +148,31 @@ public class TestViewPage extends Page i
gridLayout.marginHeight = 5;
overlay.setLayout(gridLayout);
+ // Composite rowButtonOverlay = new Composite(overlay, SWT.RIGHT_TO_LEFT);
+ GridData layoutData = new GridData(SWT.RIGHT);
+ layoutData.grabExcessHorizontalSpace = true;
+ layoutData.horizontalAlignment = GridData.END;
+ layoutData.horizontalSpan = 1;
+ // rowButtonOverlay.setLayout(rowLayout);
+ buttonDoJavaRun = new Button(overlay, SWT.CHECK);
+ buttonDoJavaRun.setLayoutData(layoutData);
+ buttonDoJavaRun.setText("extend classpath");
+ String buttonDoJavaRunTooltip = "If checked, " + "the classpath will be extended "
+ + "so that java analysis engines can be executed.";
+ buttonDoJavaRun.setToolTipText(buttonDoJavaRunTooltip);
+ buttonDoJavaRun.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent ev) {
+ doJavaRun = ((Button) ev.getSource()).getSelection();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ buttonDoJavaRun.setSelection(true); // TODO use prefs store / memento
+
tInfoPanel = new InfoPanel(overlay);
GridData tInfoLabelData = new GridData();
tInfoLabelData.grabExcessHorizontalSpace = true;
@@ -210,7 +240,7 @@ public class TestViewPage extends Page i
Object obj = event.getSelection();
if (obj instanceof IStructuredSelection) {
StructuredSelection selection = (StructuredSelection) obj;
- Iterator<?>iterator = selection.iterator();
+ Iterator<?> iterator = selection.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof TestCasData) {
@@ -447,8 +477,8 @@ public class TestViewPage extends Page i
IPreferenceStore store = RutaAddonsPlugin.getDefault().getPreferenceStore();
IProject project = script.getProject();
- IPath testFolderPath = project.getFullPath()
- .append(RutaProjectUtils.getDefaultTestLocation()).removeFirstSegments(1);
+ IPath testFolderPath = project.getFullPath().append(RutaProjectUtils.getDefaultTestLocation())
+ .removeFirstSegments(1);
IPath scriptPath = script.getFullPath();
IPath scriptPackagePath = scriptPath.removeFirstSegments(2);
IPath testFolderPackagePath = testFolderPath.append(scriptPackagePath).removeFileExtension();
@@ -482,16 +512,15 @@ public class TestViewPage extends Page i
private void checkProjectTestStructure(IResource r) {
IProject project = r.getProject();
- IPath testFolderPath = project.getFullPath()
- .append(RutaProjectUtils.getDefaultTestLocation()).removeFirstSegments(1);
+ IPath testFolderPath = project.getFullPath().append(RutaProjectUtils.getDefaultTestLocation())
+ .removeFirstSegments(1);
IPath scriptPath = r.getFullPath().removeFileExtension();
IPath scriptPackagePath = scriptPath.removeFirstSegments(2);
IPath testScriptPath = testFolderPath.append(scriptPackagePath);
IPath resultPath = testScriptPath.append(TestCasData.RESULT_FOLDER);
IFolder resultFolder = project.getFolder(resultPath);
- IPath path2TempTests = project.getFullPath()
- .append(RutaProjectUtils.getDefaultTestLocation())
+ IPath path2TempTests = project.getFullPath().append(RutaProjectUtils.getDefaultTestLocation())
.append(RutaProjectUtils.getDefaultTempTestLocation()).removeFirstSegments(1);
IFolder tempTestFolder = project.getFolder(path2TempTests);
@@ -538,8 +567,12 @@ public class TestViewPage extends Page i
public void setIncludedTypes(List<String> includedTypes) {
this.includedTypes = includedTypes;
}
-
+
public List<String> getIncludedTypes() {
return includedTypes;
}
+
+ public boolean doExtendClasspath() {
+ return this.doJavaRun;
+ }
}
Modified: uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java?rev=1551948&r1=1551947&r2=1551948&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java (original)
+++ uima/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/launching/RutaLaunchConfigurationDelegate.java Wed Dec 18 14:18:24 2013
@@ -90,7 +90,7 @@ public class RutaLaunchConfigurationDele
IPath projectPath = proj.getResource().getLocation();
IPath inputDirPath = projectPath.append(RutaProjectUtils.getDefaultInputLocation());
IPath outputDirPath = projectPath.append(RutaProjectUtils.getDefaultOutputLocation());
- String engine = RutaProjectUtils.getEngineDescriptorPath(member.getLocation(),
+ String engineDefaultMethod = RutaProjectUtils.getEngineDescriptorPath(member.getLocation(),
proj.getProject()).toPortableString();
String input = configuration.getAttribute(RutaLaunchConstants.INPUT_FOLDER,
inputDirPath.toPortableString());
@@ -102,6 +102,11 @@ public class RutaLaunchConfigurationDele
if (StringUtils.isBlank(output)) {
output = outputDirPath.toPortableString();
}
+ String engine = configuration.getAttribute(RutaLaunchConstants.ARG_DESCRIPTOR,
+ engineDefaultMethod);
+ if (StringUtils.isBlank(engine)) {
+ engine = engineDefaultMethod;
+ }
cmdline.append(RutaLaunchConstants.ARG_DESCRIPTOR + " ");
cmdline.append(engine + " ");
@@ -215,16 +220,20 @@ public class RutaLaunchConfigurationDele
.getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "conditionExtension").getExtensions();
extensionToClassPath(d, result, extensions);
extensions = Platform.getExtensionRegistry()
- .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "booleanFunctionExtension").getExtensions();
+ .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "booleanFunctionExtension")
+ .getExtensions();
extensionToClassPath(d, result, extensions);
extensions = Platform.getExtensionRegistry()
- .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "numberFunctionExtension").getExtensions();
+ .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "numberFunctionExtension")
+ .getExtensions();
extensionToClassPath(d, result, extensions);
extensions = Platform.getExtensionRegistry()
- .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "stringFunctionExtension").getExtensions();
+ .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "stringFunctionExtension")
+ .getExtensions();
extensionToClassPath(d, result, extensions);
extensions = Platform.getExtensionRegistry()
- .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "typeFunctionExtension").getExtensions();
+ .getExtensionPoint(RutaIdeCorePlugin.PLUGIN_ID, "typeFunctionExtension")
+ .getExtensions();
extensionToClassPath(d, result, extensions);
return result;
}
@@ -312,8 +321,11 @@ public class RutaLaunchConfigurationDele
IScriptProject proj = AbstractScriptLaunchConfigurationDelegate.getScriptProject(configuration);
IPath projectPath = proj.getResource().getLocation();
IPath outputDirPath = projectPath.append(RutaProjectUtils.getDefaultOutputLocation());
- String outputFolderPath = configuration.getAttribute(RutaLaunchConstants.OUTPUT_FOLDER,
- outputDirPath.toPortableString());
+ String outputFolderPath = configuration.getAttribute(RutaLaunchConstants.ARG_OUTPUT_FOLDER, "");
+ if (StringUtils.isBlank(outputFolderPath)) {
+ outputFolderPath = configuration.getAttribute(RutaLaunchConstants.OUTPUT_FOLDER,
+ outputDirPath.toPortableString());
+ }
if (outputFolderPath.length() != 0) {
IPath path = Path.fromPortableString(outputFolderPath);
IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaLanguageToolkit.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaLanguageToolkit.java?rev=1551948&r1=1551947&r2=1551948&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaLanguageToolkit.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/RutaLanguageToolkit.java Wed Dec 18 14:18:24 2013
@@ -28,7 +28,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.dltk.core.AbstractLanguageToolkit;
public class RutaLanguageToolkit extends AbstractLanguageToolkit {
- private static final String[] languageExtensions = new String[] { "tm" };
+ private static final String[] languageExtensions = new String[] { "ruta" };
private static RutaLanguageToolkit sInstance = new RutaLanguageToolkit();
Modified: uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java?rev=1551948&r1=1551947&r2=1551948&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java (original)
+++ uima/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/builder/RutaProjectUtils.java Wed Dec 18 14:18:24 2013
@@ -275,6 +275,10 @@ public class RutaProjectUtils {
return "test";
}
+ public static String getDefaultCleanTestLocation() {
+ return "temp_clean";
+ }
+
public static String getDefaultScriptLocation() {
return "script";
}