package org.codehaus.mojo.gwt.shell;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Extends the gwt goal and runs the project in the GWT Hosted mode with a debugger port hook (optionally suspended).
 *
 * @goal debug
 * @description Runs the project with a debugger port hook (optionally suspended).
 * @author cooper
 * @version $Id$
 */
public class DebugMojo
    extends RunMojo
{

    /**
     * Port to listen for debugger connection on.
     * 
     * @parameter default-value="8000"
     */
    private int debugPort;

    /**
     * Whether or not to suspend execution until a debugger connects.
     *
     * @parameter default-value="true"
     */
    private boolean debugSuspend;

    /**
     * Attach to the debugger application at the specified debugPort.
     * 
     * @parameter default-value="false" expression="${attachDebugger}"
     */
    private boolean attachDebugger;

    /**
     * {@inheritDoc}
     * 
     * @see org.codehaus.mojo.gwt.shell.RunMojo#getFileName()
     */
    @Override
    protected String getFileName()
    {
        return "debug";
    }

    /**
     * Override extraJVMArgs to append JVM debugger option
     * <p>
     * {@inheritDoc}
     * 
     * @see org.codehaus.mojo.gwt.shell.AbstractGwtShellMojo#getExtraJvmArgs()
     */
    @Override
    public String getExtraJvmArgs()
    {
        String extras = super.getExtraJvmArgs();
        extras += " -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket";
        extras += ",server=" + ( attachDebugger ? "n " : "y" );
        extras += ",address=" + debugPort;
        extras += ",suspend=" + ( debugSuspend ? "y " : "n " );
        return extras;
    }


    @Override
    public void doExecute()
        throws MojoExecutionException, MojoFailureException
    {
        if ( debugSuspend )
        {
            getLog().info( "starting debugger on port " + debugPort + " in suspend mode" );
        }
        else
        {
            getLog().info( "starting debugger on port " + debugPort );
        }

        super.doExecute( );
    }
}

@@ -1361,16 +1361,46 @@
 e=%228000%22
+ expression=%22$%7Bgwt.debugPort%7D%22
 %0A     */
@@ -1551,16 +1551,49 @@
 e=%22true%22
+ expression=%22$%7Bgwt.debugSuspend%7D%22
 %0A     */
@@ -2465,17 +2465,16 @@
 ger ? %22n
- 
 %22 : %22y%22 
@@ -2574,16 +2574,14 @@
 ? %22y
- 
 %22 : %22n
- 
 %22 );

Support Netbeans debug via gwt:debug