Search in sources :

Example 1 with NoABSNatureException

use of org.absmodels.abs.plugin.exceptions.NoABSNatureException 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 2 with NoABSNatureException

use of org.absmodels.abs.plugin.exceptions.NoABSNatureException 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)2 NoABSNatureException (org.absmodels.abs.plugin.exceptions.NoABSNatureException)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 MavenJob (org.absmodels.abs.plugin.actions.MavenJob)1 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)1 MsgConsole (org.absmodels.abs.plugin.console.MsgConsole)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1