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 java.io.File;
 import java.util.List;
 import java.util.Map;
 
Support running GWT SDK Tools as forked JVM with classpath set according to project source/resource directories and dependencies.

Author(s):
ccollins
cooper
willpugh
Version:
$Id$
 
 public abstract class AbstractGwtShellMojo
     extends AbstractGwtModuleMojo
 {
    
Location on filesystem where GWT will write generated content for review (-gen option to GWTCompiler).

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

Parameter:
default-value="${project.build.directory}/.generated" expression="${gwt.gen}"
 
     private File gen;

    
GWT logging level (-logLevel ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL).

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

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

    
GWT JavaScript compiler output style (-style OBF[USCATED], PRETTY, or DETAILED).

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

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

    
The directory into which deployable but not servable output files will be written (defaults to 'WEB-INF/deploy' under the webappDirectory directory/jar, and may be the same as the extra directory/jar)

Since:
2.3.0-1
Parameter:
 
     private File deploy;

    
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;

    
Option to specify the jvm (or path to the java executable) to use with the forking scripts. For the default, the jvm will be the same as the one used to run Maven.

Since:
1.1
Parameter:
expression="${gwt.jvm}"
    private String jvm;

    
Forked process execution timeOut. Usefull to avoid maven to hang in continuous integration server.

Parameter:
    private int timeOut;
    
Artifacts to be included as source-jars in GWTCompiler Classpath. Removes the restriction that source code must be bundled inside of the final JAR when dealing with external utility libraries not designed exclusivelly for GWT. The plugin will download the source.jar if necessary. This option is a workaround to avoid packaging sources inside the same JAR when splitting and application into modules. A smaller JAR can then be used on server classpath and distributed without sources (that may not be desirable).

Parameter:
    private String[] compileSourcesArtifacts;
    // methods

    
    public final void execute()
    {
        doExecute();
    }
    public abstract void doExecute()
    protected String getExtraJvmArgs()
    {
        return ;
    }
    protected File getGen()
    {
        return this.;
    }
    protected String getLogLevel()
    {
        return this.;
    }
    protected String getStyle()
    {
        return this.;
    }
    protected String getJvm()
    {
        return ;
    }

    
hook to post-process the dependency-based classpath
    protected void postProcessClassPathCollection<Fileclasspath )
        throws MojoExecutionException
    {
        // Nothing to do in most case
    }
    private List<StringgetJvmArgs()
    {
        List<Stringextra = new ArrayList<String>();
        String userExtraJvmArgs = getExtraJvmArgs();
        if ( userExtraJvmArgs != null )
        {
            for ( String extraArg : userExtraJvmArgs.split" " ) )
            {
                extra.addextraArg );
            }
        }
        return extra;
    }
    private String getJavaCommand()
        throws MojoExecutionException
    {
        if ( StringUtils.isEmpty ) )
        {
            // use the same JVM as the one used to run Maven (the "java.home" one)
             = System.getProperty"java.home" );
        }
        // does-it exists ? is-it a directory or a path to a java executable ?
        File jvmFile = new File );
        if ( !jvmFile.exists() )
        {
            throw new MojoExecutionException"the configured jvm " + 
                + " doesn't exists please check your environnement" );
        }
        if ( jvmFile.isDirectory() )
        {
            // it's a directory we construct the path to the java executable
            return jvmFile.getAbsolutePath() + . + "bin" + . + "java";
        }
        getLog().debug"use jvm " +  );
        return ;
    }


    

Parameters:
timeOut the timeOut to set
    public void setTimeOutint timeOut )
    {
        this. = timeOut;
    }

    
Add sources.jar artifacts for project dependencies listed as compileSourcesArtifacts. This is a GWT hack to avoid packaging java source files into JAR when sharing code between server and client. Typically, some domain model classes or business rules may be packaged as a separate Maven module. With GWT packaging this requires to distribute such classes with code, that may not be desirable.

The hack can also be used to include utility code from external librariries that may not have been designed for GWT.

    protected void addCompileSourceArtifacts(JavaCommand cmd)
            throws MojoExecutionException
    {
        if (  == null )
        {
            return;
        }
        for ( String include :  )
        {
            List<Stringparts = new ArrayList<String>();
            parts.addAll( Arrays.asList(include.split(":")) );
            if ( parts.size() == 2 )
            {
                // type is optional as it will mostly be "jar"
                parts.add"jar" );
            }
            String dependencyId = StringUtils.joinparts.iterator(), ":" );
            boolean found = false;
            for ( Artifact artifact : getProjectArtifacts() )
            {
                getLog().debug"compare " + dependencyId + " with " + artifact.getDependencyConflictId() );
                if ( artifact.getDependencyConflictId().equalsdependencyId ) )
                {
                    getLog().debug"Add " + dependencyId + " sources.jar artifact to compile classpath" );
                    Artifact sources =
                            resolveartifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
                                    "jar""sources" );
                    cmd.withinClasspathsources.getFile() );
                    found = true;
                    break;
                }
            }
            if ( !found )
                getLog().warn(
                        "Declared compileSourcesArtifact was not found in project dependencies " + dependencyId );
        }
    }
    protected void addArgumentDeploy(JavaCommand cmd) {
        if (  != null )
        {
            cmd.arg"-deploy" ).arg( String.valueOf ) );
        }
    }

    
A plexus-util StreamConsumer to redirect messages to plugin log
    protected StreamConsumer out = new StreamConsumer()
    {
        public void consumeLineString line )
        {
            getLog().infoline );
        }
    };

    
A plexus-util StreamConsumer to redirect errors to plugin log
    private StreamConsumer err = new StreamConsumer()
    {
        public void consumeLineString line )
        {
            getLog().errorline );
        }
    };

    

Deprecated:
use the new AbstractGwtShellMojo.JavaCommand Create a command to execute using builder pattern
Author(s):
Nicolas De Loof
    public class JavaCommand
    {
        private String className;
        private List<Fileclasspath = new LinkedList<File>();
        private List<Stringargs = new ArrayList<String>();
        private Properties systemProperties = new Properties();
        private Properties env = new Properties();
        public JavaCommandString className )
        {
            this. = className;
        }
        public JavaCommand withinScopeString scope )
            throws MojoExecutionException
        {
            .addAllgetClasspathscope ) );
            postProcessClassPath );
            return this;
        }
        public JavaCommand withinClasspathFile... path )
        {
            for ( File file : path )
            {
                .addfile );
            }
            return this;
        }
        public JavaCommand argString arg )
        {
            .addarg );
            return this;
        }
        public JavaCommand argString argString value )
        {
            .addarg );
            .addvalue );
            return this;
        }
        public JavaCommand argboolean conditionString arg )
        {
            if ( condition )
            {
                .addarg );
            }
            return this;
        }
        public JavaCommand systemPropertyString nameString value )
        {
            .setPropertynamevalue );
            return this;
        }
        public JavaCommand environmentString nameString value )
        {
            .setPropertynamevalue );
            return this;
        }
        public void execute()
            throws MojoExecutionException
        {
            List<Stringcommand = new ArrayList<String>();
            command.addAllgetJvmArgs() );
            command.add"-classpath" );
            List<Stringpath = new ArrayList<String>( .size() );
            for ( File file :  )
            {
                path.addfile.getAbsolutePath() );
            }
            command.add( StringUtils.joinpath.iterator(), . ) );
            if (  != null )
            {
                for ( Map.Entry entry : .entrySet() )
                {
                    command.add"-D" + entry.getKey() + "=" + entry.getValue() );
                }
            }
            command.add );
            command.addAll );
            try
            {
                String[] arguments = (String[]) command.toArraynew String[command.size()] );
                // On windows, the default Shell will fall into command line length limitation issue
                // On Unixes, not using a Shell breaks the classpath (NoClassDefFoundError:
                // com/google/gwt/dev/Compiler).
                Commandline cmd =
                    Os.isFamily. ) ? new Commandlinenew JavaShell() ) : new Commandline();
                cmd.setExecutablegetJavaCommand() );
                cmd.addArgumentsarguments );
                if (  != null )
                {
                    for ( Map.Entry entry : .entrySet() )
                    {
                        getLog().debug"add env " + (Stringentry.getKey() + " with value " + (Stringentry.getValue() );
                        cmd.addEnvironment( (Stringentry.getKey(), (Stringentry.getValue() );
                    }
                }
                getLog().debug"Execute command :\n" + cmd.toString() );
                int status;
                if (  > 0 )
                {
                    status = CommandLineUtils.executeCommandLinecmd );
                }
                else
                {
                    status = CommandLineUtils.executeCommandLinecmd );
                }
                if ( status != 0 )
                {
                    throw new ForkedProcessExecutionException"Command [[\n" + cmd.toString()
                        + "\n]] failed with status " + status );
                }
            }
            catch ( CommandLineTimeOutException e )
            {
                if (  > 0 )
                {
                    getLog().warn"Forked JVM has been killed on time-out after " +  + " seconds" );
                    return;
                }
                throw new MojoExecutionException"Time-out on command line execution :\n" + commande );
            }
            catch ( CommandLineException e )
            {
                throw new MojoExecutionException"Failed to execute command line :\n" + commande );
            }
        }
        public void withinClasspathFirstFile oophmJar )
        {
            .add( 0, oophmJar );
        }
    }
New to GrepCode? Check out our FAQ X