Search in sources :

Example 1 with MsgConsole

use of org.absmodels.abs.plugin.console.MsgConsole in project abstools by abstools.

the class JavaJob method printProcessOutput.

/**
 * prints the output on users console using a new thread
 *
 * @param moduleName
 * @param info, String nam
 * @param p
 * @throws IOException
 */
private void printProcessOutput(final String moduleName, final String info, final Process p) throws IOException {
    final Display display = Display.getDefault();
    // run in a different thread to prevent blocking of the SWT UI thread
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                if (info != null)
                    javaConsole.println(info, ConsoleManager.MessageType.MESSAGE_INFO);
                javaConsole.println("run " + moduleName + "..", ConsoleManager.MessageType.MESSAGE_INFO);
                // Output
                BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                // read the output from the command
                String s = null;
                if (debugMode)
                    System.out.println("Here is the standard output of the command:");
                while ((s = stdInput.readLine()) != null) {
                    asyncShowString(display, javaConsole, s, ConsoleManager.MessageType.MESSAGE_INFO);
                    if (debugMode)
                        System.out.println(s);
                }
                // read any errors from the attempted command
                if (debugMode)
                    System.out.println("Here is the standard error of the command (if any):");
                while ((s = stdError.readLine()) != null) {
                    asyncShowString(display, javaConsole, s, ConsoleManager.MessageType.MESSAGE_ERROR);
                    if (debugMode)
                        System.err.println(s);
                }
                stdInput.close();
                stdError.close();
                asyncShowString(display, javaConsole, "..finished", ConsoleManager.MessageType.MESSAGE_INFO);
            } catch (IOException e) {
                standardExceptionHandling(e);
            }
        }

        private void asyncShowString(final Display display, final MsgConsole console, final String s, final ConsoleManager.MessageType mtype) {
            display.asyncExec(new Runnable() {

                @Override
                public void run() {
                    console.println(s, mtype);
                }
            });
        }
    };
    new Thread(r).start();
}
Also used : MsgConsole(org.absmodels.abs.plugin.console.MsgConsole) MessageType(org.absmodels.abs.plugin.console.ConsoleManager.MessageType) Display(org.eclipse.swt.widgets.Display)

Example 2 with MsgConsole

use of org.absmodels.abs.plugin.console.MsgConsole in project abstools by abstools.

the class ConsoleManagerTest method testNewConsole.

@Test
public void testNewConsole() {
    MsgConsole newConsole = ConsoleManager.newConsole("test console");
    assertNotNull(newConsole);
    assertTrue(containsConsole(newConsole));
    assertEquals("test console", newConsole.getName());
}
Also used : MsgConsole(org.absmodels.abs.plugin.console.MsgConsole) Test(org.junit.Test)

Example 3 with MsgConsole

use of org.absmodels.abs.plugin.console.MsgConsole in project abstools by abstools.

the class ConsoleManagerTest method testDefaultConsole.

@Test
public void testDefaultConsole() {
    MsgConsole defaultConsole = ConsoleManager.getDefault();
    assertNotNull(defaultConsole);
    assertTrue(containsConsole(defaultConsole));
    assertEquals("Default", defaultConsole.getName());
}
Also used : MsgConsole(org.absmodels.abs.plugin.console.MsgConsole) Test(org.junit.Test)

Example 4 with MsgConsole

use of org.absmodels.abs.plugin.console.MsgConsole in project abstools by abstools.

the class UtilityFunctions method printToConsole.

/**
 * prints a message to the default console
 */
public static void printToConsole(String msg) {
    MsgConsole c = ConsoleManager.getDefault();
    c.println(msg, MessageType.MESSAGE_INFO);
}
Also used : MsgConsole(org.absmodels.abs.plugin.console.MsgConsole)

Example 5 with MsgConsole

use of org.absmodels.abs.plugin.console.MsgConsole 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

MsgConsole (org.absmodels.abs.plugin.console.MsgConsole)5 Test (org.junit.Test)2 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)1 MessageType (org.absmodels.abs.plugin.console.ConsoleManager.MessageType)1 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)1 NoABSNatureException (org.absmodels.abs.plugin.exceptions.NoABSNatureException)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IFile (org.eclipse.core.resources.IFile)1 Display (org.eclipse.swt.widgets.Display)1