Example usage for org.apache.maven.lifecycle LifecycleExecutionException LifecycleExecutionException

List of usage examples for org.apache.maven.lifecycle LifecycleExecutionException LifecycleExecutionException

Introduction

In this page you can find the example usage for org.apache.maven.lifecycle LifecycleExecutionException LifecycleExecutionException.

Prototype

public LifecycleExecutionException(MojoExecution execution, MavenProject project, Throwable cause) 

Source Link

Usage

From source file:org.mkleint.netbeans.surefire.eventspy.ContSurefireEventSpy.java

private Runnable getServerRunnable(final MojoExecution mojoExecution, final MavenSession session) {
    return new Runnable() {

        @Override/*  w  w w .  ja  va  2 s.  c  o  m*/
        public void run() {
            ServerSocket ss = null;
            try {
                ss = new ServerSocket(2999, 1);
                logger.info("waiting for incoming connections on port 2999");
                boolean cont = true;
                final ExecutionEventCatapult eventCatapult = container.lookup(ExecutionEventCatapult.class);
                final BuildPluginManager pluginManager = container.lookup(BuildPluginManager.class);
                final MavenPluginManager mavenPluginManager = container.lookup(MavenPluginManager.class);

                while (cont) {
                    Socket s = ss.accept();
                    BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
                    String line = br.readLine();
                    logger.info("processing " + line);
                    if (line == null || "exit".equals(line)) {
                        cont = false;
                        break;
                    }
                    long start = System.currentTimeMillis();

                    eventCatapult.fire(ExecutionEvent.Type.MojoStarted, session, mojoExecution);
                    try {
                        Mojo mojo = mavenPluginManager.getConfiguredMojo(Mojo.class, session, mojoExecution);
                        if (mojo instanceof ContextEnabled) {
                            ContextEnabled en = (ContextEnabled) mojo;
                            en.getPluginContext().clear();
                        }

                        try {
                            pluginManager.executeMojo(session, mojoExecution);
                        } catch (MojoFailureException e) {
                            throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(),
                                    e);
                        } catch (MojoExecutionException e) {
                            throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(),
                                    e);
                        } catch (PluginConfigurationException e) {
                            throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(),
                                    e);
                        } catch (PluginManagerException e) {
                            throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(),
                                    e);
                        }

                        eventCatapult.fire(ExecutionEvent.Type.MojoSucceeded, session, mojoExecution);
                    } catch (LifecycleExecutionException e) {
                        eventCatapult.fire(ExecutionEvent.Type.MojoFailed, session, mojoExecution, e);
                    } catch (PluginConfigurationException ex) {
                        java.util.logging.Logger.getLogger(ContSurefireEventSpy.class.getName())
                                .log(Level.SEVERE, null, ex);
                    } catch (PluginContainerException ex) {
                        java.util.logging.Logger.getLogger(ContSurefireEventSpy.class.getName())
                                .log(Level.SEVERE, null, ex);
                    } finally {
                        s.close();
                        logger.info("has taken ms=" + ((System.currentTimeMillis() - start)));
                    }
                }
            } catch (IOException ex) {
                java.util.logging.Logger.getLogger(ContSurefireEventSpy.class.getName()).log(Level.SEVERE, null,
                        ex);
            } catch (ComponentLookupException ex) {
                java.util.logging.Logger.getLogger(ContSurefireEventSpy.class.getName()).log(Level.SEVERE, null,
                        ex);
            } finally {
                synchronized (ContSurefireEventSpy.this) {
                    ContSurefireEventSpy.this.notifyAll();
                }
                if (ss != null) {
                    try {
                        ss.close();
                    } catch (IOException ex) {
                        java.util.logging.Logger.getLogger(ContSurefireEventSpy.class.getName())
                                .log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    };

}