Search in sources :

Example 6 with AbsJobException

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

the class JavaJob method searchForMainBlockInCurrentFile.

/**
 * @return a module with a main block from the current file or null if no such module was found
 * @throws AbsJobException
 */
private ModuleDecl searchForMainBlockInCurrentFile() throws AbsJobException {
    if (currentFile == null) {
        return null;
    }
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
    }
    synchronized (nature.modelLock) {
        CompilationUnit unit = nature.getCompilationUnit(currentFile);
        List<ModuleDecl> modules = findModulesWithMain(unit);
        // TODO: is the module still valid once you have returned the lock?
        return modules.size() == 0 ? null : modules.get(0);
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 7 with AbsJobException

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

the class JavaJob method getPathToGeneratedJavaFiles.

/**
 * Returns path of generated Java files.
 * Throws an IllegalArumentException, if path can not be found for the given project.
 *
 * @param project
 * @return
 * @throws CoreException
 * @throws AbsJobException
 */
private Path getPathToGeneratedJavaFiles(IProject project) throws AbsJobException {
    Path path;
    String tempPath;
    try {
        tempPath = getAbsNature(project).getProjectPreferenceStore().getString(JAVA_SOURCE_PATH);
        Assert.isLegal(tempPath != null);
    } catch (NullPointerException e) {
        standardExceptionHandling(e);
        throw new AbsJobException("No ABS project selected.");
    }
    path = new Path(tempPath);
    if (!path.isAbsolute()) {
        path = new Path(project.getLocation().append(path).toOSString());
    }
    return path;
}
Also used : AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 8 with AbsJobException

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

the class JavaJob method generateJavaClassFiles.

/**
 * generates .class files (needs .java files)
 * @param monitor
 *
 * @param absFrontendLocation -where to find the absfrontend
 * @param path - directory with java files
 * @param noWarnings - do not show any compile warnings
 * @throws AbsJobException
 */
private void generateJavaClassFiles(IProgressMonitor monitor, String absFrontendLocation, File path, boolean noWarnings) throws AbsJobException {
    monitor.subTask("Creating class files");
    // args
    String noWarn;
    if (noWarnings) {
        noWarn = "-nowarn";
    } else {
        noWarn = "";
    }
    if (!path.isDirectory() || !path.isAbsolute()) {
        if (debugMode)
            System.err.println("Not a absolute path of a directory: " + path.getAbsolutePath());
        throw new AbsJobException("Path is not an absolute path of a directory");
    }
    String args = "-1.5 " + noWarn + " -classpath " + "\"" + absFrontendLocation + "\"" + " " + "\"" + path.getAbsolutePath() + "\"";
    if (debugMode)
        System.out.println("arguments: " + args);
    // console
    try {
        ConsoleManager.displayConsoleView();
    } catch (PartInitException e) {
        standardExceptionHandling(e);
        throw new AbsJobException("Not able to show console");
    }
    // compile with jdt-BatchCompiler
    CompilationProgress progress = null;
    OutputStream os = javaConsole.getOutputStream(ConsoleManager.MessageType.MESSAGE_ERROR);
    boolean compilationSuccessful = BatchCompiler.compile(args, new PrintWriter(os), new PrintWriter(os), progress);
    if (!compilationSuccessful) {
        throw new AbsJobException("Sorry, there seems to be a bug in the java backend. The generated java " + "files could not be compiled correctly.");
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) CompilationProgress(org.eclipse.jdt.core.compiler.CompilationProgress) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 9 with AbsJobException

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

the class JavaJob method getModuleByName.

/**
 * finds a module with a given name in the current
 * @param moduleName
 * @return
 * @throws AbsJobException
 */
private ModuleDecl getModuleByName(String moduleName) throws AbsJobException {
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("Could not start the debugger, because selected file (" + currentFile.getName() + ") is not in an ABS project!");
    }
    synchronized (nature.modelLock) {
        Model model = nature.getCompleteModel();
        ModuleDecl result = model.lookupModule(moduleName);
        if (result == null) {
            throw new AbsJobException("Could not find a module with name " + moduleName + ".");
        }
        return result;
    }
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 10 with AbsJobException

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

the class MavenJob method runMavenUpdates.

public void runMavenUpdates() throws NoABSNatureException, AbsJobException, IOException {
    AbsNature nature = getAbsNature(project);
    if (nature == null) {
        throw new NoABSNatureException();
    }
    IFile pom = null;
    if (!(pom = getPom()).exists()) {
        throw new AbsJobException("POM for this project is not defined");
    }
    MsgConsole console = nature.getMavenConsole();
    console.clear();
    List<String> args = new ArrayList<String>();
    File file = new File(getMavenPath());
    if (!file.exists() || !file.isDirectory()) {
        throw new AbsJobException("Maven path is not defined");
    }
    String command;
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        command = new File(file, "bin\\mvn.bat").getAbsolutePath();
    } else {
        command = new File(file, "bin/mvn").getAbsolutePath();
    }
    args.add(command);
    args.add("-f");
    args.add(pom.getLocation().toFile().getAbsolutePath());
    args.add(goal);
    InputStream ins = null;
    OutputStream outs = null;
    try {
        if (!abort)
            process = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
        ins = process.getInputStream();
        outs = console.getOutputStream(MessageType.MESSAGE_INFO);
        int d = 0;
        while ((d = ins.read()) != -1) {
            outs.write(d);
        }
        if (process.waitFor() != 0) {
            console.getOutputStream(MessageType.MESSAGE_ERROR).write("An error has occurred.");
        }
    } catch (InterruptedException e) {
        throw new AbsJobException(e.getMessage());
    } finally {
        if (ins != null)
            ins.close();
    }
}
Also used : NoABSNatureException(org.absmodels.abs.plugin.exceptions.NoABSNatureException) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) MsgConsole(org.absmodels.abs.plugin.console.MsgConsole) File(java.io.File) IFile(org.eclipse.core.resources.IFile) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) 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