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();
}
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());
}
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());
}
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);
}
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();
}
}
Aggregations