Search in sources :

Example 1 with ParseException

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)

Example 2 with ParseException

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");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException)

Example 3 with ParseException

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");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ParseException(org.absmodels.abs.plugin.exceptions.ParseException)

Example 4 with ParseException

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();
        }
    }
}
Also used : ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) PrintStream(java.io.PrintStream) IFile(org.eclipse.core.resources.IFile) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) ABSTestRunnerGenerator(abs.backend.tests.ABSTestRunnerGenerator) Model(abs.frontend.ast.Model) ParseException(org.absmodels.abs.plugin.exceptions.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ParseException (org.absmodels.abs.plugin.exceptions.ParseException)4 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)4 IStatus (org.eclipse.core.runtime.IStatus)3 ABSTestRunnerGenerator (abs.backend.tests.ABSTestRunnerGenerator)1 ASTBasedABSTestRunnerGenerator (abs.backend.tests.ASTBasedABSTestRunnerGenerator)1 Model (abs.frontend.ast.Model)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 Status (org.eclipse.core.runtime.Status)1