Search in sources :

Example 1 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class JavaJob method findAndExecuteMain.

/**
 * Tries to find the main block in the chosen ABS file or in the
 * ABS project, if file is null.
 *
 * Finally: executes Modulename.Main
 *
 * @param absFrontendLocation - where to find the absfrontend
 * @throws AbsJobException - if no main block found
 * @throws IOException - If an I/O error occurs
 */
private void findAndExecuteMain(String absFrontendLocation) throws AbsJobException, IOException {
    String info = null;
    ModuleDecl module;
    if (absUnit) {
        module = getModuleByName(ABSTestRunnerGenerator.RUNNER_MAIN);
    } else if (runTarget != null) {
        module = getModuleByName(runTarget);
    } else {
        module = searchForMainBlockInCurrentFile();
        // Search for the main file if previous searching was not successful
        if (module == null) {
            List<ModuleDecl> modules = getAllModulesWithMainInCurrentProject();
            if (modules.size() == 0) {
                throw new AbsJobException("No Module with main block found.");
            } else {
                module = modules.get(0);
            }
            if (currentFile != null) {
                info = "No main file found for \"" + currentFile.getName() + "\".\nBut there is a main file in the project:";
            }
        }
    }
    String moduleName = JavaBackend.getFullJavaNameForMainBlock(module);
    try {
        debugAbsFiles(absFrontendLocation, javaPath, startSDE, moduleName, info);
    } catch (InvalidRandomSeedException e) {
        throw new AbsJobException(e);
    }
}
Also used : InvalidRandomSeedException(org.absmodels.abs.plugin.debug.model.Debugger.InvalidRandomSeedException) ModuleDecl(abs.frontend.ast.ModuleDecl) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 2 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class JavaJob method generateJavaCode.

/**
 * Generates .java files (no .class files).
 * If 'product' is set, will flatten accordingly.
 * @param monitor - must not be null
 * @param path - where to add the modules / java-files
 * @param project - the ABS project
 * @throws IOException, if unable to create java files
 * @throws AbsJobException, if unable to generate java files
 * @throws JavaCodeGenerationException, if unable to generate java files
 * @throws CoreException
 * @throws NoModelException
 */
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
    assert monitor != null;
    monitor.subTask("Creating java source files");
    AbsNature nat = UtilityFunctions.getAbsNature(project);
    synchronized (nat.modelLock) {
        Model model = nat.getCompleteModel();
        if (model == null)
            throw new NoModelException();
        JavaCode javaCode = new JavaCode(path.toFile());
        if (product != null) {
            /* [stolz] Flattening for a product will mangle the model according to [ramus]...
                 */
            // work on a copy:
            model = model.treeCopyNoTransform();
            model.flushTreeCache();
            String productN = product.getName();
            try {
                model.flattenForProduct(productN);
                model.flushCache();
                if (model.hasErrors() || model.hasTypeErrors()) {
                    nat.createMarkers(model);
                    throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
                }
            } catch (WrongProgramArgumentException e) {
                throw new AbsJobException(e);
            } catch (DeltaModellingException e) {
                throw new AbsJobException(e);
            }
        }
        // TODO: the second parameter toggles listener code creation (3
        // Java method calls per ABS statement); make this configurable
        model.generateJavaCode(javaCode, true);
        int countUnits = model.getNumCompilationUnit();
        if (countUnits == 0)
            throw new AbsJobException("No compilation unit found");
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) JavaCode(abs.backend.java.codegeneration.JavaCode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 3 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class JavaJob method getModelFromProject.

/**
 * @Deprecated According to Yannick, you need to hold {@link AbsNature#modelLock} to safely do anything with the model,
 * which means you need the nature first, and then this helper is just a fancy wrapper around {@link AbsNature#getCompleteModel()}...
 * @see AbsNature#getCompleteModel()
 */
public static Model getModelFromProject(IProject project) throws AbsJobException {
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("The file is not in an ABS project!");
    }
    Model model = nature.getCompleteModel();
    // if (model==null && curFile!=null ) model = abs.frontend.parser.Main.parse(new File(curFile.getLocation().toString()), withStdLib);
    if (model == null) {
        throw new AbsJobException("No ABS model found");
    }
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
        // just to be sure
        throw new AbsJobException("An ABS file in the project has type or parser errors");
    }
    return model;
}
Also used : Model(abs.frontend.ast.Model) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 4 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class MavenAction method run.

@Override
public void run() {
    if (selection != null && selection instanceof TreeSelection) {
        final IProject project = getProject((TreeSelection) selection);
        new Job("Maven") {

            protected IStatus run(IProgressMonitor monitor) {
                final MavenJob mavenJob = new MavenJob(project);
                mavenJob.setUser(true);
                try {
                    mavenJob.runMavenUpdates();
                } catch (NoABSNatureException e) {
                    showErrorMessage(e.getMessage());
                } catch (AbsJobException e) {
                    showErrorMessage(e.getMessage());
                } catch (IOException e) {
                    showErrorMessage(e.getMessage());
                }
                MavenAction.super.run();
                return new Status(IStatus.OK, PLUGIN_ID, "done");
            }
        }.schedule();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NoABSNatureException(org.absmodels.abs.plugin.exceptions.NoABSNatureException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MavenJob(org.absmodels.abs.plugin.actions.MavenJob) IOException(java.io.IOException) Job(org.eclipse.core.runtime.jobs.Job) MavenJob(org.absmodels.abs.plugin.actions.MavenJob) IProject(org.eclipse.core.resources.IProject) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 5 with AbsJobException

use of org.absmodels.abs.plugin.exceptions.AbsJobException in project abstools by abstools.

the class JavaJob method checkPath.

private void checkPath(Path javaPath) throws AbsJobException {
    File javaDir = javaPath.toFile();
    File[] genDirs = javaDir.listFiles();
    if (genDirs == null || genDirs.length == 0) {
        throw new AbsJobException("No generated Java files found. Please compile ABS files to Java before debugging.");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Aggregations

AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)12 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)6 Model (abs.frontend.ast.Model)5 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)5 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 ModuleDecl (abs.frontend.ast.ModuleDecl)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 ArrayList (java.util.ArrayList)2 NoABSNatureException (org.absmodels.abs.plugin.exceptions.NoABSNatureException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Job (org.eclipse.core.runtime.jobs.Job)2 ABSTestObserver (abs.backend.java.absunit.ABSTestObserver)1 JavaCode (abs.backend.java.codegeneration.JavaCode)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 File (java.io.File)1 IOException (java.io.IOException)1