Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.gwt.eclipse;
  
  /*
   * 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 java.io.File;
 import java.io.Writer;
 import java.util.List;
 import java.util.Map;
 
 
Goal which creates Eclipse lauch configurations for GWT modules.

Author(s):
Nicolas De Loof
Version:
$Id$
Goal:
eclipse
Execute:
phase=generate-resources
RequiresDependencyResolution:
compile
 
 public class EclipseMojo
     extends AbstractGwtModuleMojo
 {
    

Component:
 
     private EclipseUtil eclipseUtil;

    
Extra JVM arguments that are passed to the GWT-Maven generated scripts (for compiler, shell, etc - typically use -Xmx512m here, or -XstartOnFirstThread, etc).

Can be set from command line using '-Dgwt.extraJvmArgs=...', defaults to setting max Heap size to be large enough for most GWT use cases.

Parameter:
expression="${gwt.extraJvmArgs}" default-value="-Xmx512m"
 
     private String extraJvmArgs;

    
The currently executed project (phase=generate-resources).

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

    
Location of the compiled classes.

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

    
Location of the hosted-mode web application structure.

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

    
Additional parameters to append to the module URL. For example, gwt-log users will set "log_level=DEBUG"

Parameter:
    private String additionalPageParameters;

    
Run without hosted mode server

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

    
Port of the HTTP server used when noserver is set

Parameter:
default-value="8080" expression="${gwt.port}"
    private int port;

    
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;

    
Set GWT shell bindAddress.

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

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

    
Setup a launch configuration for using the Google Eclipse Plugin. This is the recommended setup, as the home-made launch configuration has many limitations. This parameter is only for backward compatibility, the standard lauch configuration template will be removed in a future release.

Parameter:
default-value="true" expression="${use.google.eclipse.plugin}"
    private boolean useGoogleEclipsePlugin;

    

Parameters:
parameters additional parameter for module URL
    public void setAdditionalPageParametersString parameters )
    {
        // escape the '&' char used for multiple parameters as the result must be XML compliant
        this. = StringUtils.replaceparameters"&""&" );
    }

    
    public void execute()
    {
        if ( ! )
        {
            // Jetty requires an exploded webapp
            setupExplodedWar();
        }
        else
        {
            getLog().info"noServer is set! Skipping exploding war file..." );
        }
        for ( String module : getModules() )
        {
            createLaunchConfigurationForHostedModeBrowsermodule );
        }
    }
    protected void setupExplodedWar()
        throws MojoExecutionException
    {
        try
        {
            File classes = new File"WEB-INF/classes" );
            if ( !.getAbsolutePath().equalsclasses.getAbsolutePath() ) )
            {
                getLog().warn"Your POM <build><outputdirectory> must match your "
                    + "hosted webapp WEB-INF/classes folder for GWT Hosted browser to see your classes." );
            }
            File lib = new File"WEB-INF/lib" );
            getLog().info"create exploded Jetty webapp in " +  );
            lib.mkdirs();
            Collection<Artifactartifacts = getProject().getRuntimeArtifacts();
            for ( Artifact artifact : artifacts )
            {
                if ( !artifact.getFile().isDirectory() )
                {
                    FileUtils.copyFileToDirectoryartifact.getFile(), lib );
                }
                else
                {
                    // TODO automatically add this one to GWT warnings exlusions
                }
            }
        }
        catch ( IOException ioe )
        {
            throw new MojoExecutionException"Failed to create Jetty exploded webapp"ioe );
        }
    }

    
create an Eclipse launch configuration file to Eclipse to run the module in hosted browser

Parameters:
module the GWT module
Throws:
org.apache.maven.plugin.MojoExecutionException some error occured
    private void createLaunchConfigurationForHostedModeBrowserString module )
        throws MojoExecutionException
    {
        try
        {
            File launchFile = new FilegetProject().getBasedir(), readModulemodule ).getPath() + ".launch" );
            if ( launchFile.exists() )
            {
                getLog().info"launch file exists " + launchFile.getName() + " skip generation " );
                return;
            }
            Configuration cfg = new Configuration();
            cfg.setClassForTemplateLoadingEclipseMojo.class"" );
            Map<StringObjectcontext = new HashMap<StringObject>();
            // Read compileSourceRoots from executedProject to retrieve generated source directories
            Collection<Stringsources = new LinkedList<String>( .getCompileSourceRoots() );
            List<Resourceresources = .getResources();
            for ( Resource resource : resources )
            {
                sources.addresource.getDirectory() );
            }
            context.put"sources"sources );
            context.put"module"module );
            context.put"localRepository".getBasedir() );
            int idx = module.lastIndexOf'.' );
            String page = module.substringidx + 1 ) + ".html";
            if (  != null )
            {
                page += "?" + ;
            }
            context.put"modulePath"readModulemodule ).getPath() );
            context.put"page"page );
            int basedir = getProject().getBasedir().getAbsolutePath().length();
            context.put"out"getOutputDirectory().getAbsolutePath().substringbasedir + 1 ) );
            context.put"war".getAbsolutePath().substringbasedir + 1 ) );
            String args =  ? "-noserver -port " +  : "";
            if (  != null )
            {
                args += " -blacklist " + ;
            }
            if (  != null )
            {
                args += " -whitelist " + ;
            }
            if (  != null )
            {
                args += " -bindAddress " + ;
            }
            context.put"additionalArguments"args );
            context.put"extraJvmArgs" );
            context.put"project".getProjectNamegetProject() ) );
            context.put"gwtDevJarPath"getGwtDevJar().getAbsolutePath().replace'\\''/' ) );
            Writer configWriter = WriterFactory.newXmlWriterlaunchFile );
            String templateName =  ? "google.fm" : "launch.fm";
            Template template = cfg.getTemplatetemplateName"UTF-8" );
            template.processcontextconfigWriter );
            configWriter.flush();
            configWriter.close();
            getLog().info"Write launch configuration for GWT module : " + launchFile.getAbsolutePath() );
        }
        catch ( IOException ioe )
        {
            throw new MojoExecutionException"Unable to write launch configuration"ioe );
        }
        catch ( TemplateException te )
        {
            throw new MojoExecutionException"Unable to merge freemarker template"te );
        }
        catch ( GwtModuleReaderException e )
        {
            throw new MojoExecutionExceptione.getMessage(), e );
        }
        
    }
New to GrepCode? Check out our FAQ X