Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.gwt.shell;
  
  /*
   * CompileMojo.java
   *
   * Created on January 13, 2007, 11:42 AM
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  * To change this template, choose Tools | Template Manager
  * and open the template in the editor.
  *
  */
 
 import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE;
 
 import java.io.File;
 
Invokes the GWTCompiler for the project source. See compiler options : http://code.google.com/intl/fr-FR/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html#DevGuideCompilerOptions

Author(s):
cooper
ccollins
Nicolas De loof
Olivier Lamy
Version:
$Id$
Phase:
prepare-package
Goal:
compile
RequiresDependencyResolution:
compile
 
 public class CompileMojo
     extends AbstractGwtShellMojo
 {

    

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

    
Don't try to detect if GWT compilation is up-to-date and can be skipped.

Can be set from command line using '-Dgwt.compiler.force=true'.

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

    
On GWT 1.6+, number of parallel processes used to compile GWT premutations. Defaults to platform available processors number.

Can be unset from command line using '-Dgwt.compiler.localWorkers=n'.

Parameter:
expression="${gwt.compiler.localWorkers}"
 
     private int localWorkers;

    
Whether or not to enable assertions in generated scripts (-ea).

Parameter:
default-value="false"
 
     private boolean enableAssertions;

    
Logs output in a graphical tree view.

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

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

    
EXPERIMENTAL: Disables some java.lang.Class methods (e.g. getName()).

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

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

    
EXPERIMENTAL: Disables run-time checking of cast operations.

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

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

    
EXPERIMENTAL: Disables code-splitting.

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

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

    
Validate all source code, but do not compile.

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

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

    
Enable faster, but less-optimized, compilations.

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

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

    
The directory into which extra, non-deployed files will be written.

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

    
The temp directory is used for temporary compiled files (defaults is system temp directory).

Parameter:
    private File workDir;
    
    
add -extra parameter to the compiler command line

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

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.extraParam}"
    private boolean extraParam;
    
    
add -compileReport parameter to the compiler command line

Can be set from command line using '-Dgwt.compiler.compileReport=true'.

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.compiler.compileReport}"
    
    private boolean compileReport;
    
    
add -optimize parameter to the compiler command line the value must be between 0 and 9 by default -1 so no arg to the compiler

Can be set from command line using '-Dgwt.compiler.optimizationLevel=n'.

Since:
2.1.0-1
Parameter:
default-value="-1" expression="${gwt.compiler.optimizationLevel}"
    
    private int optimizationLevel;    
    
    
add -XsoycDetailed parameter to the compiler command line

Can be set from command line using '-Dgwt.compiler.soycDetailed=true'.

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.compiler.soycDetailed}"
    
    private boolean soycDetailed;    
    
    
    
add -strict parameter to the compiler command line

Can be set from command line using '-Dgwt.compiler.strict=true'.

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.compiler.strict}"
    
    private boolean strict;     
    public void doExecute( )
    {
        if (  || "pom".equalsgetProject().getPackaging() ) )
        {
            getLog().info"GWT compilation is skipped" );
            return;
        }
        if ( !this.getOutputDirectory().exists() )
        {
            this.getOutputDirectory().mkdirs();
        }
        compilegetModules() );
    }
    private void compileString[] modules )
        throws MojoExecutionException
    {
        boolean upToDate = true;
        JavaCommand cmd = new JavaCommand"com.google.gwt.dev.Compiler" );
        if (  )
        {
            cmd.withinClasspathgetGwtUserJar() )
               .withinClasspathgetGwtDevJar() );
        }
        cmd.withinScope. );
        if ( ! )
        {
            cmd.withinClasspathgetGwtUserJar() )
               .withinClasspathgetGwtDevJar() );
        }
        cmd.arg"-gen"getGen().getAbsolutePath() )
            .arg"-logLevel"getLogLevel() )
            .arg"-style"getStyle() )
            .arg"-war"getOutputDirectory().getAbsolutePath() )
            .arg"-localWorkers", String.valueOfgetLocalWorkers() ) )
            // optional advanced arguments
            .arg"-ea" ).arg"-draftCompile" )
            .arg"-validateOnly" ).arg"-treeLogger" )
            .arg"-XdisableClassMetadata" )
            .arg"-XdisableCastChecking" )
            .arg"-XdisableRunAsync" )
            .arg"-strict" )
            .arg"-XsoycDetailed" );
        if (  >= 0 )
        {
            cmd.arg"-optimize" ).arg( Integer.toString ) );
        }
        if (  ||  )
        {
            getLog().debug"create extra directory " );
            if ( !.exists() )
            {
                .mkdirs();
            }
            cmd.arg"-extra" ).arg.getAbsolutePath() );
        }
        else
        {
            getLog().debug"NOT create extra directory " );
        }
        if (  )
        {
            cmd.arg"-compileReport" );
        }
        addCompileSourceArtifactscmd );
        addArgumentDeploy(cmd);
        if (  != null )
        {
            cmd.arg"-workDir" ).arg( String.valueOf ) );
        }
        for ( String target : modules )
        {
            if ( !compilationRequiredtargetgetOutputDirectory() ) )
            {
                continue;
            }
            cmd.argtarget );
            upToDate = false;
        }
        if ( !upToDate )
        {
            cmd.execute();
        }
    }
    private int getLocalWorkers()
    {
        if (  > 0 )
        {
            return ;
        }
        // workaround to GWT issue 4031 whith IBM JDK
        // @see http://code.google.com/p/google-web-toolkit/issues/detail?id=4031
        if ( System.getProperty"java.vendor" ).startsWith"IBM" ) && StringUtils.isEmpty(getJvm()))
        {
            StringBuilder sb = new StringBuilder"Build is using IBM JDK, and no explicit JVM property has been set." );
            sb.append. );
            sb.append("localWorkers set to 1 as a workaround");
            sb.append. );
            sb.append"see http://code.google.com/p/google-web-toolkit/issues/detail?id=4031" );
            getLog().infosb.toString() );
            return 1;
        }
        return Runtime.getRuntime().availableProcessors();
    }

    
Try to find out, if there are stale sources. If aren't some, we don't have to compile... ...this heuristic doesn't take into account, that there could be updated dependencies. But for this case, as 'clean compile' could be executed which would force a compilation.

Parameters:
module Name of the GWT module to compile
output Output path
Returns:
true if compilation is required (i.e. stale sources are found)
Throws:
org.apache.maven.plugin.MojoExecutionException When sources scanning fails
Author(s):
Alexander Gordt
    private boolean compilationRequiredString moduleFile output )
        throws MojoExecutionException
    {
        getLog().debug"**Checking if compilation is required for " + module );
        try
        {
        	GwtModule gwtModule = readModulemodule );
            if ( gwtModule.getEntryPoints().size() == 0 )
            {
                getLog().infogwtModule.getName() + " has no EntryPoint - compilation skipped" );
                // No entry-point, this is an utility module : compiling this one will fail
                // with '[ERROR] Module has no entry points defined'
                return false;
            }
            getLog().debug"Module has an entrypoint" );
            if (  )
            {
                return true;
            }
            getLog().debug"Compilation not forced");
            
            String modulePath = gwtModule.getPath();
            String outputTarget = modulePath + "/" + modulePath + ".nocache.js";
            File outputTargetFile = new FileoutputoutputTarget );
            // Require compilation if no js file present in target.
            if ( !outputTargetFile.exists() )
            {
                return true;
            }
            getLog().debug"Output file exists");
            
            File moduleFile = gwtModule.getSourceFile();
            if(moduleFile == null) {
            	return true//the module was read from something like an InputStream; always recompile this because we can't make any other choice
            }
            getLog().debug"There is a module source file (not an input stream");
            
            //If input is newer than target, recompile
            if(moduleFile.lastModified() > outputTargetFile.lastModified()) 
            {
                getLog().debug"Module file has been modified since the output file was created; recompiling" );
            	return true;
            }
            getLog().debug"The module XML hasn't been updated");
            // js file already exists, but may not be up-to-date with project source files
            SingleTargetSourceMapping singleTargetMapping = new SingleTargetSourceMapping".java"outputTarget );
            StaleSourceScanner scanner = new StaleSourceScanner();
            scanner.addSourceMappingsingleTargetMapping );
            SingleTargetSourceMapping uiBinderMapping = new SingleTargetSourceMapping".ui.xml"outputTarget );
            scanner.addSourceMappinguiBinderMapping );
            Collection<FilecompileSourceRoots = new HashSet<File>();
           	for (Iterator iterator = getProject().getCompileSourceRoots().iterator(); iterator.hasNext();) {	
				String sourceRoot = (Stringiterator.next();
           		for (String sourcePackage : gwtModule.getSources()) {
			        String packagePath = gwtModule.getPackage().replace'.'. );
		            File sourceDirectory = new File (sourceRoot + . + packagePath + . + sourcePackage);
		            if(sourceDirectory.exists()) {
		            	getLog().debug(" Looking in a source directory "+sourceDirectory.getAbsolutePath() + " for possible changes");
			            compileSourceRoots.add(sourceDirectory);					
		            }
				}
			}
            for ( File sourceRoot : compileSourceRoots )
            {
                if ( !sourceRoot.isDirectory() )
                {
                    continue;
                }
                try
                {
                    if ( !scanner.getIncludedSourcessourceRootoutput ).isEmpty() )
                    {
                        getLog().debug"found stale source in " + sourceRoot + " compared with " + output );
                        return true;
                    }
                }
                catch ( InclusionScanException e )
                {
                    throw new MojoExecutionException"Error scanning source root: \'" + sourceRoot + "\' "
                        + "for stale files to recompile."e );
                }
            }
            getLog().infomodule + " is up to date. GWT compilation skipped" );
            return false;
        }
        catch ( GwtModuleReaderException e )
        {
            throw new MojoExecutionExceptione.getMessage(), e );
        }
    }
New to GrepCode? Check out our FAQ X