use of org.absmodels.abs.plugin.exceptions.ParseException in project abstools by abstools.
the class ABSUnitTestExecutionJob method run.
protected IStatus run(IProgressMonitor monitor) {
AbsNature nature = getAbsNature(project);
if (nature == null) {
return new Status(IStatus.INFO, PLUGIN_ID, "Could not compile current selection. Project is not an ABS project.");
}
monitor.beginTask("ABSUnit Test Execution", 112);
// Parsing and Type Checking ABS model
monitor.subTask("Generating Test Runner");
try {
if (!abort)
generateTestRunner(monitor, nature);
} catch (CoreException e1) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while generating test runner", e1);
} catch (IOException e2) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while generating test runner", e2);
} catch (ParseException e4) {
return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_ERROR, "Could not generating test runnern. Code has parse errors.", e4);
} catch (TypeCheckerException e5) {
return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_ERROR, "Could not generating test runner. Code has type errors.", e5);
}
monitor.worked(12);
try {
// make sure the generated testrunner file is parsed:
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
} catch (CoreException e) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compiling tests", e);
}
monitor.subTask("Executing ABSUnit tests");
IStatus status = null;
try {
status = executeTest(monitor);
} catch (CoreException e) {
return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while executing tests", e);
}
if (abort) {
monitor.setCanceled(true);
return new Status(IStatus.INFO, PLUGIN_ID, ABSUNIT_TEST_USER_ABORT, null, null);
}
return new Status(IStatus.OK, PLUGIN_ID, ABSUNIT_TEST_OK, status.getMessage(), null);
}
use of org.absmodels.abs.plugin.exceptions.ParseException in project abstools by abstools.
the class ABSUnitTestExecutionJobListener method done.
@Override
public void done(IJobChangeEvent event) {
// When the Job is done get the IStatus and print messages on console
final IStatus status = event.getResult();
switch(status.getCode()) {
case ABSUNIT_TEST_OK:
initializeConsole();
console.println(status.getMessage(), MessageType.MESSAGE_INFO);
break;
case ABSUNIT_TEST_ERROR:
// encountered an exception during execution
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (status.getException() instanceof ParseException || status.getException() instanceof TypeCheckerException) {
showErrorMessage(status.getMessage(), status);
} else {
showErrorMessage(status.getMessage());
}
}
});
break;
case ABSUNIT_TEST_USER_ABORT:
initializeConsole();
console.println("Aborted Maude Job.", MessageType.MESSAGE_ERROR);
break;
default:
// This should never happen... just in case...
showErrorMessage("reached an unspecified status");
}
}
use of org.absmodels.abs.plugin.exceptions.ParseException in project abstools by abstools.
the class MaudeJobChangeListener method done.
@Override
public void done(IJobChangeEvent event) {
// When the Job is done get the IStatus and print messages on console
final IStatus status = event.getResult();
switch(status.getCode()) {
// Indicates a successful Job without Maude execution
case MAUDE_OK:
break;
case MAUDE_INFO:
// Execution of Maude was successful
initializeConsole();
console.println(status.getMessage(), MessageType.MESSAGE_INFO);
break;
case // This message type is not used
MAUDE_WARNING:
initializeConsole();
console.println(status.getMessage(), MessageType.MESSAGE_WARNING);
break;
case MAUDE_ERROR_MAUDE:
// Maude encountered an error during execution
initializeConsole();
console.println(status.getMessage(), MessageType.MESSAGE_ERROR);
break;
case MAUDE_ERROR_MAUDE_PATH:
// missconfigured Maude path
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
showErrorMessage("Encountered IOException while executing Maude (probably misconfigured location of maude executable): " + status.getMessage());
PreferencesUtil.createPreferenceDialogOn(Display.getDefault().getActiveShell(), "org.abs-models.abs.plugin.preferences.ABSMaudePreferences", null, null).open();
}
});
break;
case MAUDE_ERROR:
// encountered an exception during execution
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (status.getException() instanceof ParseException || status.getException() instanceof TypeCheckerException) {
showErrorMessage(status.getMessage(), status);
} else {
showErrorMessage(status.getMessage());
}
}
});
break;
case MAUDE_USER_ABORT:
initializeConsole();
console.println("Aborted Maude Job.", MessageType.MESSAGE_ERROR);
break;
default:
// This should never happen... just in case...
showErrorMessage("reached an unspecified status");
}
}
use of org.absmodels.abs.plugin.exceptions.ParseException in project abstools by abstools.
the class ABSUnitTestExecutionJob method generateTestRunner.
/**
* Generate an ABS file from an ABS project that can be used to execute unit tests
* @throws ParseException Is thrown, if the project which is compiled has parse errors
* @throws TypeCheckerException Is thrown, if the project which is compiled has type errors
* @throws DeltaModellingException
* @throws WrongProgramArgumentException
*/
private void generateTestRunner(IProgressMonitor monitor, AbsNature nature) throws CoreException, IOException, ParseException, TypeCheckerException {
PrintStream ps = null;
FileInputStream fis = null;
try {
// find a way to change
String path = Constants.DEFAULT_MAVEN_TARGET_ABS_PATH;
IFolder folder = project.getFolder(path);
MaudeJob.prepareFolder(monitor, folder);
String fileName = "runner.abs";
final IFile wspaceFile = folder.getFile(fileName);
/* generateMaude only knows how to fill PrintStreams */
final File tmpFile = File.createTempFile(fileName, null);
ps = new PrintStream(tmpFile);
// Get model, check for errors and throw respective exception
Model model = nature.getCompleteModel();
if (model.hasParserErrors()) {
throw new ParseException(model.getParserErrors());
}
if (model.hasTypeErrors()) {
throw new TypeCheckerException(model.typeCheck());
}
String mb = abs.backend.tests.ABSTestRunnerGenerator.RUNNER_MAIN;
ABSTestRunnerGenerator gen = new ASTBasedABSTestRunnerGenerator(model);
gen.generateTestRunner(ps);
ps.close();
fis = new FileInputStream(tmpFile);
if (wspaceFile.exists())
wspaceFile.setContents(fis, true, false, monitor);
else
wspaceFile.create(fis, true, monitor);
fis.close();
tmpFile.delete();
destFile = new File(project.getLocation().append(path).toFile(), fileName);
} finally {
if (ps != null) {
ps.flush();
ps.close();
}
if (fis != null) {
fis.close();
}
}
}
Aggregations