Borș Nicolae
Borș Nicolae

Reputation: 113

How to get console output(in code) after running configurations in eclipse?

I need to start another launch configurations depending on output from executing first launch configurations. So there is a way to get console output from this launch?

Something like this:

 Launch launch = (Launch) configurations[0].launch(ILaunchManager.RUN_MODE, console);
 if(launch.output){
   configurations[1].launch(ILaunchManager.RUN_MODE, console);
 }

For example first launch configuration is a maven project, and I need to check if build is succesfully or it failed.

I have following code:

Launch launch = (Launch) configurations[0].launch(ILaunchManager.RUN_MODE,
                            new NullProgressMonitor());
                    final IProcess[] processes = launch.getProcesses();
                    IDebugEventSetListener listener = new IDebugEventSetListener() {

                        @Override
                        public void handleDebugEvents(DebugEvent[] events) {
                            for(DebugEvent e : events){
                                for(int i = 0; i < processes.length; i++){
                                    if(e.getKind() == DebugEvent.TERMINATE && e.getSource() == processes[i]){
                                        try {
                                            --------To check here if console contains Build Failed--------
                                            configurations[1].launch(ILaunchManager.RUN_MODE,
                                                    new NullProgressMonitor());
                                        } catch (CoreException e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                }

                            }
                        }
                    };
                    DebugPlugin.getDefault().addDebugEventListener(listener);

Upvotes: 1

Views: 335

Answers (1)

greg-449
greg-449

Reputation: 111142

You can use the org.eclipse.ui.console.consolePatternMatchListeners extension point to match patterns in console output:

<extension
     point="org.eclipse.ui.console.consolePatternMatchListeners">
  <consolePatternMatchListener
        class="com.example.ExampleConsolePatternMatcher"
        id="com.example.ExampleConsolePatternMatcher"
        regex=".*foo.*">
     <enablement>
        <test property="org.eclipse.ui.console.consoleTypeTest" value="exampleConsole"/>
     </enablement>
  </consolePatternMatchListener>
</extension>

You can use the org.eclipse.debug.ui.consoleLineTrackers extension point to listen to lines output by processes of a given process type:

<extension
     point="org.eclipse.debug.ui.consoleLineTrackers">
  <consoleLineTracker
        class="org.eclipse.jdt.internal.ui.javadocexport.JavadocConsoleLineTracker"
        processType="org.eclipse.jdt.ui.javadocProcess"
        id="org.eclipse.jdt.ui.javadocexport.JavadocConsoleLineTracker">
  </consoleLineTracker>
</extension>

Upvotes: 1

Related Questions