JavaEclipse插件:如何检测Ant构建的取消和失败

JavaEclipse插件:如何检测Ant构建的取消和失败,java,ant,eclipse-plugin,Java,Ant,Eclipse Plugin,嗯,我有一个非常丑陋的代码和平,它启动了ant build: private boolean runAntBuild(String antFile, final IProgressMonitor monitor) throws CoreException, Exception { ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager().get

嗯,我有一个非常丑陋的代码和平,它启动了ant build:

private boolean runAntBuild(String antFile, final IProgressMonitor monitor)
            throws CoreException, Exception
    {
        ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, "Ant build");
        ...

        monitor.beginTask("Running ant build", 100);
        ILaunch launch = wc.launch(ILaunchManager.RUN_MODE, monitor);


        final boolean[] buildWasSuccessful = new boolean[] { true };

        // Listen to the text output of the process to see if it ended in
        // success, cancellation or failure:
        for (IProcess proc : launch.getProcesses())
        {
            proc.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {
                @Override
                public void streamAppended(String text, IStreamMonitor monitor1)
                {
                    if (text.contains("BUILD FAILED"))
                    {
                        buildWasSuccessful[0] = false;
                    }
                }
            });
            proc.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {

                @Override
                public void streamAppended(String text, IStreamMonitor monitor1)
                {
                    if (text.toLowerCase().contains("build cancelled"))
                        monitor.setCanceled(true);

                }
            });
        }

        // Wait for build to finish:
        boolean buildIsStillRunning = true;
        while (buildIsStillRunning)
        {
            buildIsStillRunning = false;
            for (IProcess proc : launch.getProcesses())
            {
                if (!proc.isTerminated())
                {
                    buildIsStillRunning = true;
                    try
                    {
                        Thread.sleep(100);
                    }
                    catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                    break;
                }
            }

        }
        if (monitor.isCanceled())
        {
            throw new Exception("Request was cancelled.");
        }

        if (monitor != null)
            monitor.done();
        return buildWasSuccessful[0];
    }
是否有更好的方法来检测构建失败或取消?

您不能使用“proc”系统返回值吗?约定为0表示成功,任何其他值表示错误