Eclipse:控制台上的IProcess输出

时间:2011-04-04 09:01:09

标签: java eclipse plugins process eclipse-plugin

当我尝试写入控制台时遇到问题。

在插件项目中,我开发了一个自定义构建,可以使用我开发的命令通过菜单调用。最初构建是在我的类的launch方法中调用的,它实现了ILaunchConfigurationDelegate。

...
        String[] commandLine = (String[]) compilerArgs.toArray(new String[compilerArgs.size()]);
        Process compilerProcess = DebugPlugin.exec(commandLine, new File(project.getLocation().toString()));

        @SuppressWarnings("rawtypes")
        Map processAttributes = new HashMap();
        processAttributes.put(IProcess.ATTR_PROCESS_TYPE, "XVR");
        IProcess dbgProcess = DebugPlugin.newProcess(launch, compilerProcess, "XVR Compiler", processAttributes);

        try {
            compilerProcess.waitFor();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if(compilerProcess.exitValue() != 0) return false;
        launch.removeProcess(dbgProcess); 

执行构建时,进程的输出将打印在控制台上,并使用实现IConsoleLineTracker的类进行解析以突出显示错误。

我将构建方法移到实现ILaunchConfigurationDelegate的类之外,并且不再打印控制台。两种情况之间的唯一区别是如何提供对象iLaunch。新构建方法如下

   ...
String[] commandLine = (String[]) compilerArgs.toArray(new String[compilerArgs.size()]);
    Process compilerProcess = DebugPlugin.exec(commandLine, new File(prj.getLocation().toString()));

    ILaunch xvrLaunch = XVRUtils.getXVRLaunch();
    Map<String, String> processAttributes = new HashMap<String, String>();
    processAttributes.put(IProcess.ATTR_PROCESS_TYPE, "XVR");

    IProcess dbgProcess = DebugPlugin.newProcess(xvrLaunch, compilerProcess, "XVR Compiler", processAttributes);

    try {
        compilerProcess.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if(compilerProcess.exitValue() != 0)
        return false;
    xvrLaunch.removeProcess(dbgProcess);

启动时提供以下功能

public static ILaunch getXVRLaunh(){
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunch[] launches = manager.getLaunches();
    if(launches.length > 0){
        for (ILaunch launch : launches) {
            ILaunchConfiguration conf = launch.getLaunchConfiguration();
            try {
                if(conf.getType().equals(manager.getLaunchConfigurationType(ApplicationLaunchConfigurationDelegate.XVR_LAUNCH_CONFIGURATION_ID)))
                    return launch;
            } catch (CoreException e) {
                e.printStackTrace();
            }
        }

    }
    ILaunchConfiguration config = getXVRLaunchConfiguration();
    Launch l = new Launch(config, "run, debug", null);
    l.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, null);
    try {
        if (l.getSourceLocator() == null) {
            String type;
            type = config.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null);

            if (type == null) {
                type = config.getType().getSourceLocatorId();
            }
            if (type != null) {
                IPersistableSourceLocator locator = manager.newSourceLocator(type);
                String memento = config.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null);
                if (memento == null) {
                    locator.initializeDefaults(config);
                } else {
                    if(locator instanceof IPersistableSourceLocator2)
                        ((IPersistableSourceLocator2)locator).initializeFromMemento(memento, config);
                    else
                        locator.initializeFromMemento(memento);
                }
                l.setSourceLocator(locator);
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return l;
}

为什么进程不再在控制台上打印?

谢谢!

0 个答案:

没有答案