This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 238543
Collapse All | Expand All

(-)maven/mavensrc/org/netbeans/modules/maven/event/NbEventSpy.java (+121 lines)
Lines 42-59 Link Here
42
42
43
package org.netbeans.modules.maven.event;
43
package org.netbeans.modules.maven.event;
44
44
45
import java.io.BufferedInputStream;
46
import java.io.BufferedReader;
47
import java.io.IOException;
48
import java.io.InputStreamReader;
49
import java.net.ServerSocket;
50
import java.net.Socket;
51
import java.net.SocketAddress;
45
import java.net.URL;
52
import java.net.URL;
53
import java.util.Properties;
46
import java.util.concurrent.atomic.AtomicBoolean;
54
import java.util.concurrent.atomic.AtomicBoolean;
55
import java.util.logging.Level;
47
import org.apache.maven.eventspy.AbstractEventSpy;
56
import org.apache.maven.eventspy.AbstractEventSpy;
48
import org.apache.maven.execution.ExecutionEvent;
57
import org.apache.maven.execution.ExecutionEvent;
58
import org.apache.maven.execution.MavenSession;
49
import org.apache.maven.lifecycle.LifecycleExecutionException;
59
import org.apache.maven.lifecycle.LifecycleExecutionException;
60
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
50
import org.apache.maven.model.InputLocation;
61
import org.apache.maven.model.InputLocation;
51
import org.apache.maven.model.PluginExecution;
62
import org.apache.maven.model.PluginExecution;
63
import org.apache.maven.plugin.BuildPluginManager;
64
import org.apache.maven.plugin.ContextEnabled;
65
import org.apache.maven.plugin.MavenPluginManager;
66
import org.apache.maven.plugin.Mojo;
52
import org.apache.maven.plugin.MojoExecution;
67
import org.apache.maven.plugin.MojoExecution;
68
import org.apache.maven.plugin.MojoExecutionException;
69
import org.apache.maven.plugin.MojoFailureException;
70
import org.apache.maven.plugin.PluginConfigurationException;
71
import org.apache.maven.plugin.PluginContainerException;
72
import org.apache.maven.plugin.PluginManagerException;
53
import org.apache.maven.plugin.descriptor.MojoDescriptor;
73
import org.apache.maven.plugin.descriptor.MojoDescriptor;
54
import org.apache.maven.plugin.descriptor.PluginDescriptor;
74
import org.apache.maven.plugin.descriptor.PluginDescriptor;
55
import org.apache.maven.project.MavenProject;
75
import org.apache.maven.project.MavenProject;
76
import org.codehaus.plexus.PlexusContainer;
56
import org.codehaus.plexus.classworlds.realm.ClassRealm;
77
import org.codehaus.plexus.classworlds.realm.ClassRealm;
78
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
57
import org.codehaus.plexus.logging.Logger;
79
import org.codehaus.plexus.logging.Logger;
58
import org.codehaus.plexus.util.Base64;
80
import org.codehaus.plexus.util.Base64;
59
import org.json.simple.JSONArray;
81
import org.json.simple.JSONArray;
Lines 72-77 Link Here
72
    //it's unlikely that we would legally trigger multiple builds inside a single jvm sequentially
94
    //it's unlikely that we would legally trigger multiple builds inside a single jvm sequentially
73
    private static final AtomicBoolean insideSession = new AtomicBoolean(false);
95
    private static final AtomicBoolean insideSession = new AtomicBoolean(false);
74
    private static final AtomicBoolean ignoreInnerSessionEvents = new AtomicBoolean(false);
96
    private static final AtomicBoolean ignoreInnerSessionEvents = new AtomicBoolean(false);
97
    private boolean stopSurefire = false;
98
    private PlexusContainer container;
75
    
99
    
76
    @Override
100
    @Override
77
    public void init(Context context) throws Exception {
101
    public void init(Context context) throws Exception {
Lines 82-88 Link Here
82
        //data.put( "userProperties", cliRequest.userProperties );
106
        //data.put( "userProperties", cliRequest.userProperties );
83
        //data.put( "versionProperties", CLIReportingUtils.getBuildProperties() );
107
        //data.put( "versionProperties", CLIReportingUtils.getBuildProperties() );
84
        super.init(context); 
108
        super.init(context); 
109
        Properties p = (Properties) context.getData().get("userProperties");
110
        if (p != null) {
111
            stopSurefire = p.containsKey("surefire.server");
85
    }
112
    }
113
        logger.info("props=" + p);
114
        logger.info("stop=" + stopSurefire);
115
        container = (PlexusContainer) context.getData().get("plexus");
116
        logger.info("container=" + container);
117
    }
86
118
87
    @Override
119
    @Override
88
    public void onEvent(Object event) throws Exception {
120
    public void onEvent(Object event) throws Exception {
Lines 229-235 Link Here
229
                }
261
                }
230
            }    
262
            }    
231
            logger.info("NETBEANS-ExecEvent:"  + root.toString());
263
            logger.info("NETBEANS-ExecEvent:"  + root.toString());
264
            if (stopSurefire && ex.getMojoExecution() != null && (
265
                         ExecutionEvent.Type.MojoFailed.equals(ex.getType()) ||
266
                         ExecutionEvent.Type.MojoSucceeded.equals(ex.getType())) && "test".equals(ex.getMojoExecution().getGoal())) //TODO finetune goal condition
267
            {
268
                Thread serverThread = new Thread(getServerRunnable(ex.getMojoExecution(), ex.getSession()), "Netbeans Test Server Thread");
269
                stopSurefire = false;
270
                serverThread.start();
271
                synchronized (this) {
272
                    this.wait();
232
        }
273
        }
274
            }
275
            
276
        }
233
//        if (event instanceof RepositoryEvent) {
277
//        if (event instanceof RepositoryEvent) {
234
//            RepositoryEvent re = (RepositoryEvent) event;
278
//            RepositoryEvent re = (RepositoryEvent) event;
235
//            logger.info("NETBEANS-RE:" + re.getType() + ":" + re.getFile());
279
//            logger.info("NETBEANS-RE:" + re.getType() + ":" + re.getFile());
Lines 241-244 Link Here
241
        super.close(); 
285
        super.close(); 
242
    }
286
    }
243
287
288
    private Runnable getServerRunnable(final MojoExecution mojoExecution, final MavenSession session) {
289
        return new Runnable() {
290
291
            @Override
292
            public void run() {
293
                ServerSocket ss = null;
294
                try {
295
                    ss = new ServerSocket(2999, 1);
296
                    logger.info("waiting for incoming connections on port 2999");
297
                    boolean cont = true;
298
                    final ExecutionEventCatapult eventCatapult = container.lookup(ExecutionEventCatapult.class);
299
                    final BuildPluginManager pluginManager = container.lookup(BuildPluginManager.class);
300
                    final MavenPluginManager mavenPluginManager = container.lookup(MavenPluginManager.class);
301
                    
302
                    while (cont) {
303
                        Socket s = ss.accept();
304
                        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
305
                        String line = br.readLine();
306
                        logger.info("processing " + line);
307
                        if (line == null || "exit".equals(line)) {
308
                            cont = false;
309
                            break;
244
}
310
}
311
                        long start = System.currentTimeMillis();
312
                        
313
                        eventCatapult.fire(ExecutionEvent.Type.MojoStarted, session, mojoExecution);
314
                        try {
315
                            Mojo mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution );
316
                            if (mojo instanceof ContextEnabled) {
317
                                ContextEnabled en = (ContextEnabled) mojo;
318
                                en.getPluginContext().clear();
319
                            }
320
                            
321
                            try {
322
                                pluginManager.executeMojo(session, mojoExecution);
323
                            } catch (MojoFailureException e) {
324
                                throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(), e);
325
                            } catch (MojoExecutionException e) {
326
                                throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(), e);
327
                            } catch (PluginConfigurationException e) {
328
                                throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(), e);
329
                            } catch (PluginManagerException e) {
330
                                throw new LifecycleExecutionException(mojoExecution, session.getCurrentProject(), e);
331
                            }
332
333
                            eventCatapult.fire(ExecutionEvent.Type.MojoSucceeded, session, mojoExecution);
334
                        } catch (LifecycleExecutionException e) {
335
                            eventCatapult.fire(ExecutionEvent.Type.MojoFailed, session, mojoExecution, e);
336
                        } catch (PluginConfigurationException ex) {
337
                            java.util.logging.Logger.getLogger(NbEventSpy.class.getName()).log(Level.SEVERE, null, ex);
338
                        } catch (PluginContainerException ex) {
339
                            java.util.logging.Logger.getLogger(NbEventSpy.class.getName()).log(Level.SEVERE, null, ex);
340
                        } finally {
341
                            s.close();
342
                            logger.info("has taken ms=" + ((System.currentTimeMillis() - start) ));
343
                        }
344
                    }
345
                } catch (IOException ex) {
346
                    java.util.logging.Logger.getLogger(NbEventSpy.class.getName()).log(Level.SEVERE, null, ex);
347
                } catch (ComponentLookupException ex) {
348
                    java.util.logging.Logger.getLogger(NbEventSpy.class.getName()).log(Level.SEVERE, null, ex);
349
                } finally {
350
                    synchronized (NbEventSpy.this) {
351
                        NbEventSpy.this.notifyAll();
352
                    }
353
                    if (ss != null) {
354
                        try {
355
                            ss.close();
356
                        } catch (IOException ex) {
357
                            java.util.logging.Logger.getLogger(NbEventSpy.class.getName()).log(Level.SEVERE, null, ex);
358
                        }
359
                    }
360
                }
361
            }
362
        };
363
                
364
    }
365
}

Return to bug 238543