View Javadoc
1   package org.codehaus.mojo.gwt.shell;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.plugins.annotations.Mojo;
25  import org.apache.maven.plugins.annotations.Parameter;
26  import org.apache.maven.plugins.annotations.ResolutionScope;
27  
28  /**
29   * Runs the project with a debugger port hook (optionally suspended).
30   *
31   * @author cooper
32   * @version $Id$
33   */
34  @Mojo(name = "debug", requiresDirectInvocation = true, requiresDependencyResolution = ResolutionScope.TEST)
35  public class DebugMojo
36      extends RunMojo
37  {
38  
39      /**
40       * Port to listen for debugger connection on.
41       */
42      @Parameter(defaultValue = "8000", property = "gwt.debugPort")
43      private int debugPort;
44  
45      /**
46       * Whether or not to suspend execution until a debugger connects.
47       */
48      @Parameter(defaultValue = "true", property = "gwt.debugSuspend")
49      private boolean debugSuspend;
50  
51      /**
52       * Attach to the debugger application at the specified debugPort.
53       */
54      @Parameter(defaultValue = "false", property = "attachDebugger")
55      private boolean attachDebugger;
56  
57      /**
58       * Override extraJVMArgs to append JVM debugger option
59       * <p>
60       * {@inheritDoc}
61       * 
62       * @see org.codehaus.mojo.gwt.shell.AbstractGwtShellMojo#getExtraJvmArgs()
63       */
64      @Override
65      public String getExtraJvmArgs()
66      {
67          String extras = super.getExtraJvmArgs();
68          extras += " -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket";
69          extras += ",server=" + ( attachDebugger ? "n" : "y" );
70          extras += ",address=" + debugPort;
71          extras += ",suspend=" + ( debugSuspend ? "y" : "n" );
72          return extras;
73      }
74  
75  
76      @Override
77      public void doExecute()
78          throws MojoExecutionException, MojoFailureException
79      {
80          if ( debugSuspend )
81          {
82              getLog().info( "starting debugger on port " + debugPort + " in suspend mode" );
83          }
84          else
85          {
86              getLog().info( "starting debugger on port " + debugPort );
87          }
88  
89          super.doExecute( );
90      }
91  }