我有一个椭圆RCP应用程序,它使用Maven Surefire进行特殊测试。Maven通过m2e集成到应用程序中。
用户在我的应用程序中构建他的项目,并希望测试其项目的一部分。
现在可以从我的代码中启动maven测试命令,它可以正常运行,但是日志记录输出不会打印到我的应用程序控制台,而是打印到我的IDE控制台。
public class MyAction implements IObjectActionDelegate {
private IFolder selectedFolder;
private IPath path;
@Override
public void run(IAction action) {
String flagValue = foo();
String projectLocation = bar();
PrintStream out = System.out; // <- here
MavenCli cli = new MavenCli();
cli.doMain(new String[] {"test", "-DmyFlag=" + flagValue},
projectLocation, out, out);
}
如何获取mavenCli以打印到应用程序的控制台?
确定,我找到了一种从MavenCLI打印到应用程序控制台的方法:
public class MyAction implements IObjectActionDelegate {
private IFolder selectedFolder;
private IPath path;
@Override
public void run(IAction action) {
String flagValue = foo();
String projectLocation = bar();
PrintStream out = getConsole(); // <- here
MavenCli cli = new MavenCli();
cli.doMain(new String[] {"test", "-DmyFlag=" + flagValue},
projectLocation, out, out);
}
private PrintStream getConsole() {
MessageConsole console = findMessageConsole("Console");
console.activate();
return new PrintStream(console.newOutputStream());
}
private MessageConsole findMessageConsole(String title) {
IConsole[] existingConsoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles();
for (IConsole existingConsole : existingConsoles) {
if (existingConsole.getName().equals(title)) {
return (MessageConsole) existingConsole;
}
}
MessageConsole console = new MessageConsole(title, null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console});
return console;
}
问题是它冻结了应用程序...因此,如果有人有更多的想法,如何正确地使用它,我将非常感谢。