Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  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 static org.codehaus.plexus.util.AbstractScanner.DEFAULTEXCLUDES;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 
Goal which run a GWT module in the GWT Hosted mode.

Author(s):
ccollins
cooper
Version:
$Id$
Goal:
run
Execute:
phase=process-classes goal:war:exploded
RequiresDirectInvocation:
RequiresDependencyResolution:
test
Description:
Runs the the project in the GWT Hosted mode for development.
 
 public class RunMojo
     extends AbstractGwtWebMojo
 {
    
Location of the hosted-mode web application structure.

Parameter:
default-value="${project.build.directory}/${project.build.finalName}"
 
     // Parameter shared with EclipseMojo
     private File hostedWebapp;

    
The MavenProject executed by the "compile" phase

Parameter:
expression="${executedProject}"
 
     private MavenProject executedProject;

    
URL that should be automatically opened in the GWT shell. For example com.myapp.gwt.Module/Module.html.

When the host page is outside the module "public" folder (for example, at webapp root), the module MUST be specified (using a single <module> in configuration or by setting -Dgwt.module=..) and the runTarget parameter can only contain the host page URI.

When the GWT module host page is part of the module "public" folder, the runTarget MAY define the full GWT module path (com.myapp.gwt.Module/Module.html) that will be automatically converted according to the rename-to directive into renamed/Module.html.

Parameter:
expression="${runTarget}"
Required:
 
     private String runTarget;

    
Forked process execution timeOut (in seconds). Primary used for integration-testing.

Parameter:
 
     @SuppressWarnings("unused")
     private int runTimeOut;

    
Runs the embedded GWT server on the specified port.

Parameter:
default-value="8888"
    private int port;

    
Specify the location on the filesystem for the generated embedded Tomcat directory.

Parameter:
default-value="${project.build.directory}/tomcat"
    private File tomcat;

    
Location of the compiled classes.

Parameter:
default-value="${project.build.outputDirectory}"
Required:
ReadOnly:
    private File buildOutputDirectory;


    
Source Tomcat context.xml for GWT shell - copied to /gwt/localhost/ROOT.xml (used as the context.xml for the SHELL - requires Tomcat 5.0.x format - hence no default).

Parameter:
    private File contextXml;

    
Prevents the embedded GWT Tomcat server from running (even if a port is specified).

Can be set from command line using '-Dgwt.noserver=...'

Parameter:
default-value="false" expression="${gwt.noserver}"
    private boolean noServer;

    
Specifies a different embedded web server to run (must implement ServletContainerLauncher)

Parameter:
expression="${gwt.server}"
    private String server;

    
Set GWT shell protocol/host whitelist.

Can be set from command line using '-Dgwt.whitelist=...'

Parameter:
expression="${gwt.whitelist}"
    private String whitelist;

    
Set GWT shell protocol/host blacklist.

Can be set from command line using '-Dgwt.blacklist=...'

Parameter:
expression="${gwt.blacklist}"
    private String blacklist;

    
List of System properties to pass when running the hosted mode.

Since:
1.2
Parameter:
    private Map<StringStringsystemProperties;
    
    
Copies the contents of warSourceDirectory to hostedWebapp.

Can be set from command line using '-Dgwt.copyWebapp=...'

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.copyWebapp}"
    private boolean copyWebapp;    

    
set the appengine sdk to use

Artifact will be downloaded with groupId : appEngineGroupId and artifactId appEngineArtifactId

Since:
2.1.0-1
Parameter:
default-value="1.3.8" expression="${gwt.appEngineVersion}"
    private String appEngineVersion;
    
    

List of java.util.regex.Pattern jars to exclude from the classPath when running dev mode

Since:
2.1.0-1
Parameter:
    private List<StringrunClasspathExcludes;
    
    

Location to find appengine sdk or to unzip downloaded one see appEngineVersion

Since:
2.1.0-1
Parameter:
default-value="${project.build.directory}/appengine-sdk/" expression="${gwt.appEngineHome}"
    
    private File appEngineHome;
    
    

groupId to download appengine sdk from maven repo

Since:
2.1.0-1
Parameter:
default-value="com.google.appengine" expression="${gwt.appEngineGroupId}"
    
    private String appEngineGroupId;
    
    

groupId to download appengine sdk from maven repo

Since:
2.1.0-1
Parameter:
default-value="appengine-java-sdk" expression="${gwt.appEngineArtifactId}"
    
    private String appEngineArtifactId;    
    
    
    
To look up Archiver/UnArchiver implementations

Since:
2.1.0-1
Component:
    protected ArchiverManager archiverManager;
    
    
    
     
Set GWT shell bindAddress.

Can be set from command line using '-Dgwt.bindAddress=...'

Since:
2.1.0-1
Parameter:
expression="${gwt.bindAddress}"
    private String bindAddress;    
    public String getRunTarget()
    {
        return this.;
    }

    

Returns:
the GWT module to run (gwt 1.6+) -- expected to be unique
    public String getRunModule()
        throws MojoExecutionException
    {
        String[] modules = getModules();
        if (  )
        {
            if (modules.length != 1)
            {
                getLog().error(
                    "Running in 'noserver' mode you must specify the single module to run using -Dgwt.module=..." );
                throw new MojoExecutionException"No single module specified" );
            }
            return modules[0];
        }
        if ( modules.length == 1 )
        {
            // A single module is set, no ambiguity
            return modules[0];
        }
        int dash = .indexOf'/' );
        if ( dash > 0 )
        {
            return .substring( 0, dash );
        }
        // The runTarget MUST start with the full GWT module path
        throw new MojoExecutionException(
            "Unable to choose a GWT module to run. Please specify your module(s) in the configuration" );
    }

    

Returns:
the startup URL to open in hosted browser (gwt 1.6+)
    public String getStartupUrl()
        throws MojoExecutionException
    {
        if (  )
        {
            return ;
        }
        int dash = .indexOf'/' );
        if ( dash > 0 )
        {
            String prefix = .substring( 0, dash );
            // runTarget includes the GWT module full path.
            // Lets retrieve the GWT module and apply the rename-to directive
            String[] modules = getModules();
            for ( String module : modules )
            {
                if ( prefix.equalsmodule ) )
                {
                    try
                    {
                        return readModulemodule ).getPath() + '/' + .substringdash + 1 );
                    }
                    catch ( GwtModuleReaderException e )
                    {
                        throw new MojoExecutionExceptione.getMessage(), e );
                    }
                }
            }
        }
        return ;
    }
    protected String getFileName()
    {
        return "run";
    }
    public void doExecute( )
    {
        JavaCommand cmd = new JavaCommand"com.google.gwt.dev.DevMode" );
        if (  )
        {
            cmd.withinClasspathgetGwtUserJar() ).withinClasspathgetGwtDevJar() );
        }
        cmd.withinScope. );
        addCompileSourceArtifactscmd );
        addArgumentDeploy(cmd);
        if ( ! )
        {
            cmd.withinClasspathgetGwtUserJar() ).withinClasspathgetGwtDevJar() );
        }
        cmd.arg"-war".getAbsolutePath() )
            .arg"-gen"getGen().getAbsolutePath() )
            .arg"-logLevel"getLogLevel() )
            .arg"-port", Integer.toStringgetPort() ) )
            .arg"-startupUrl"getStartupUrl() )
            .arg"-noserver" );
        if (  != null )
        {
            cmd.arg"-server" );
        }
        if (  != null && .length() > 0 )
        {
            cmd.arg"-whitelist" );
        }
        if (  != null && .length() > 0 )
        {
            cmd.arg"-blacklist" );
        }
        if (  != null && !.isEmpty() )
        {
            for ( String key : .keySet() )
            {
                String value = .getkey );
                if ( value != null )
                {
                    getLog().debug" " + key + "=" + value );
                    cmd.systemPropertykeyvalue );
                }
                else
                {
                    getLog().debug"skip sysProps " + key + " with empty value" );
                }
            }
        }
        if (  != null && .length() > 0 )
        {
            cmd.arg"-bindAddress" ).arg );
        }
        if ( ! )
        {
            setupExplodedWar();
        }
        else
        {
            getLog().info"noServer is set! Skipping exploding war file..." );
        }
        for ( String module : getModules() )
        {
            cmd.argmodule );
        }
        cmd.execute();
    }
    @Override
    protected void postProcessClassPathCollection<FileclassPath )
    {
        boolean isAppEngine = "com.google.appengine.tools.development.gwt.AppEngineLauncher".equals );
        if ( !isAppEngine )
        {
            return;
        }
        List<PatternpatternsToExclude = new ArrayList<Pattern>();
        if (  != null && !.isEmpty() )
        {
            for ( String runClasspathExclude :  )
            {
                patternsToExclude.add( Pattern.compilerunClasspathExclude ) );
            }
        }
        Iterator<Fileit = classPath.iterator();
        while ( it.hasNext() )
        {
            String name = it.next().getName();
            if ( !patternsToExclude.isEmpty() )
            {
                for ( Pattern pattern : patternsToExclude )
                {
                    if ( pattern.matchername ).find() )
                    {
                        getLog().info"remove jar " + name + " from system classpath" );
                        it.remove();
                        continue;
                    }
                }
            }
        }
        // TODO refactor this a little 
        if ( isAppEngine )
        {
            File appEngineToolsApi = new File"/lib/appengine-tools-api.jar" );
            File appEngineLocalRuntime = new File"/lib/impl/appengine-local-runtime.jar" );
            File appEngineAgent = new File"/lib/agent/appengine-agent.jar" );
            if ( .exists() && appEngineToolsApi.exists() && appEngineLocalRuntime.exists()
                && appEngineAgent.exists() )
            {
                classPath.addappEngineToolsApi );
                classPath.addappEngineLocalRuntime );
                classPath.addappEngineAgent );
            }
            else
            {
                try
                {
                    if ( !.exists() )
                    {
                        .mkdirs();
                        // force addition of appengine SDK in a exploded SDK repository location
                        Artifact appEngineSdk =
                            resolve"zip""" );
                        // sdk extraction
                        UnArchiver unArchiver = .getUnArchiverappEngineSdk.getFile() );
                        unArchiver.setSourceFileappEngineSdk.getFile() );
                        unArchiver.setDestDirectory );
                        getLog().info"extract appengine " +  + " sdk to " + .getPath() );
                        unArchiver.extract();
                    }
                    else
                    {
                        getLog().info"use existing appengine sdk from " + .getPath() );
                    }
                    appEngineToolsApi =
                        new File"appengine-java-sdk-" + 
                            + "/lib/appengine-tools-api.jar" );
                    if ( !appEngineToolsApi.exists() )
                    {
                        throw new RuntimeExceptionappEngineToolsApi.getPath() + " not exists" );
                    }
                    classPath.addappEngineToolsApi );
                    getLog().debug"add " + appEngineToolsApi.getPath() + " to the classpath" );
                    appEngineLocalRuntime =
                        new File"appengine-java-sdk-" + 
                            + "/lib/impl/appengine-local-runtime.jar" );
                    if ( !appEngineLocalRuntime.exists() )
                    {
                        throw new RuntimeExceptionappEngineLocalRuntime.getPath() + " not exists" );
                    }
                    classPath.addappEngineLocalRuntime );
                    getLog().debug"add " + appEngineLocalRuntime.getPath() + " to the classpath" );
                    appEngineAgent =
                        new File"appengine-java-sdk-" + 
                            + "/lib/agent/appengine-agent.jar" );
                    classPath.addappEngineAgent );
                    getLog().debug"add " + appEngineAgent.getPath() + " to the classpath" );
                }
                catch ( MojoExecutionException e )
                {
                    // FIXME add throws MojoExecutionException in postProcessClassPath
                    throw new RuntimeExceptione.getMessage(), e );
                }
                catch ( ArchiverException e )
                {
                    // FIXME add throws MojoExecutionException in postProcessClassPath
                    throw new RuntimeExceptione.getMessage(), e );
                }
                catch ( NoSuchArchiverException e )
                {
                    // FIXME add throws MojoExecutionException in postProcessClassPath
                    throw new RuntimeExceptione.getMessage(), e );
                }
            }
        }
    }  
    private void setupExplodedWar()
        throws MojoExecutionException
    {
        getLog().info"create exploded Jetty webapp in " +  );
        {
            try
            {
                String excludes = StringUtils.join"," );
                FileUtils.copyDirectory"**"excludes );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Failed to copy warSourceDirectory to " + e );
            }
        }        
        
        File classes = new File"WEB-INF/classes" );
        classes.mkdirs();
        if ( !.getAbsolutePath().equalsclasses.getAbsolutePath() ) )
        {
            getLog().warn"Your POM <build><outputdirectory> does not match your "
                                + "hosted webapp WEB-INF/classes folder for GWT Hosted browser to see your classes." );
            try
            {
                FileUtils.copyDirectoryStructureclasses );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Failed to copy classes to " + classes , e );
            }
        }
        File lib = new File"WEB-INF/lib" );
        lib.mkdirs();
        Collection<Artifactartifacts = getProjectRuntimeArtifacts();
        for ( Artifact artifact : artifacts )
        {
            try
            {
                // Using m2eclipse with "resolve workspace dependencies" the artifact is the buildOutputDirectory
                if ( ! artifact.getFile().isDirectory() )
                {
                    FileUtils.copyFileToDirectoryartifact.getFile(), lib );
                }
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException"Failed to copy runtime dependency " + artifacte );
            }
        }
    }
    public File getContextXml()
    {
        return this.;
    }
    public int getPort()
    {
        return this.;
    }
    public File getTomcat()
    {
        return this.;
    }

    

Parameters:
runTimeOut the runTimeOut to set
    public void setRunTimeOutint runTimeOut )
    {
        setTimeOutrunTimeOut );
    }
    public void setExecutedProjectMavenProject executedProject )
    {
        this. = executedProject;
    }
    @Override
    public MavenProject getProject()
    {
        return ;
    }
New to GrepCode? Check out our FAQ X