Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.gwt;
  
  /*
   * 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.apache.maven.artifact.Artifact.SCOPE_COMPILE;
 import static org.apache.maven.artifact.Artifact.SCOPE_RUNTIME;
 import static org.apache.maven.artifact.Artifact.SCOPE_TEST;
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 import java.util.Set;
 
Abstract Support class for all GWT-related operations.

Provide methods to build classpath for GWT SDK tools.

Author(s):
Nicolas De Loof
Version:
$Id$
 
 public abstract class AbstractGwtMojo
     extends AbstractMojo
 {
    
GWT artifacts groupId
 
     public static final String GWT_GROUP_ID = "com.google.gwt";
 
     // --- Some Maven tools ----------------------------------------------------
 
    

Parameter:
expression="${plugin.version}"
Required:
Readonly:
 
     private String version;

    

Parameter:
expression="${plugin.artifacts}"
Required:
Readonly:
 
     private Collection<ArtifactpluginArtifacts;

    

Component:
 
     protected ArtifactResolver resolver;

    

Component:
 
     protected ArtifactFactory artifactFactory;


    

Required:
Readonly:
Component:
 
    // --- Some MavenSession related structures --------------------------------

    

Parameter:
expression="${localRepository}"
Required:
Readonly:
    protected ArtifactRepository localRepository;

    

Parameter:
expression="${project.remoteArtifactRepositories}"
Required:
Readonly:
    protected List<ArtifactRepositoryremoteRepositories;

    

Component:
The maven project descriptor

Parameter:
expression="${project}"
Required:
Readonly:
    private MavenProject project;
    // --- Plugin parameters ---------------------------------------------------

    
Folder where generated-source will be created (automatically added to compile classpath).

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

    
Location on filesystem where GWT will write output files (-out option to GWTCompiler).

Parameter:
expression="${gwt.war}" default-value="${project.build.directory}/${project.build.finalName}"
Alias:
outputDirectory
    private File webappDirectory;

    
Location of the web application static resources (same as maven-war-plugin parameter)

Parameter:
default-value="${basedir}/src/main/webapp"
    protected File warSourceDirectory;

    
Select the place where GWT application is built. In inplace mode, the warSourceDirectory is used to match the same use case of the http://maven.apache.org/plugins/maven-war-plugin/inplace-mojo.html goal.

Parameter:
default-value="false" expression="${gwt.inplace}"
    private boolean inplace;
    
    
The forked command line will use gwt sdk jars first in classpath. see issue http://code.google.com/p/google-web-toolkit/issues/detail?id=5290

Since:
2.1.0-1
Parameter:
default-value="false" expression="${gwt.gwtSdkFirstInClasspath}"
    protected boolean gwtSdkFirstInClasspath;
    public File getOutputDirectory()
    {
        return  ?  : ;
    }

    
Add classpath elements to a classpath URL set

Parameters:
elements the initial URL set
urls the urls to add
startPosition the position to insert URLS
Returns:
full classpath URL set
Throws:
org.apache.maven.plugin.MojoExecutionException some error occured
    protected int addClasspathElementsCollection<?> elementsURL[] urlsint startPosition )
        throws MojoExecutionException
    {
        for ( Object object : elements )
        {
            try
            {
                if ( object instanceof Artifact )
                {
                    urls[startPosition] = ( (Artifactobject ).getFile().toURI().toURL();
                }
                else if ( object instanceof Resource )
                {
                    urls[startPosition] = new File( ( (Resourceobject ).getDirectory() ).toURI().toURL();
                }
                else
                {
                    urls[startPosition] = new File( (Stringobject ).toURI().toURL();
                }
            }
            catch ( MalformedURLException e )
            {
                throw new MojoExecutionException(
                                                  "Failed to convert original classpath element " + object + " to URL.",
                                                  e );
            }
            startPosition++;
        }
        return startPosition;
    }


    
Build the GWT classpath for the specified scope

Parameters:
scope Artifact.SCOPE_COMPILE or Artifact.SCOPE_TEST
Returns:
a collection of dependencies as Files for the specified scope.
Throws:
org.apache.maven.plugin.MojoExecutionException if classPath building failed
    public Collection<FilegetClasspathString scope )
        throws MojoExecutionException
    {
        try
        {
            Collection<Filefiles = .buildClasspathListgetProject(), scopegetProjectArtifacts() );
            if ( getLog().isDebugEnabled() )
            {
                getLog().debug"GWT SDK execution classpath :" );
                for ( File f : files )
                {
                    getLog().debug"   " + f.getAbsolutePath() );
                }
            }
            return files;
        }
        catch ( ClasspathBuilderException e )
        {
            throw new MojoExecutionExceptione.getMessage(), e );
        }
    }
    // FIXME move to GwtDevHelper stuff to avoid duplicates
    protected File getGwtDevJar()
        throws MojoExecutionException
    {
        checkGwtDevAsDependency();
        checkGwtUserVersion();
        return getArtifact"com.google.gwt""gwt-dev" ).getFile();
    }
    protected Artifact getArtifactString groupIdString artifactId )
    {
        return getArtifactgroupIdartifactIdnull );
    }
    protected File[] getGwtUserJar()
            throws MojoExecutionException
    {
        checkGwtUserVersion();
        Artifact gwtUserArtifact = getArtifact"com.google.gwt""gwt-user" );
        Set<Artifactartifacts = new HashSet<Artifact>();
        ArtifactResolutionResult result = null;
        try
        {
            result = .resolveTransitivelyartifactsgwtUserArtifact,
                     );
        }
        catch (ArtifactResolutionException e)
        {
            throw new MojoExecutionException"Failed to resolve artifact"e);
        }
        catch (ArtifactNotFoundException e)
        {
            throw new MojoExecutionException"Failed to resolve artifact"e);
        }
        Collection<Artifactresolved = result.getArtifacts();
        int i = 0;
        // FIXME gwt 2.3.0 don't declare dependency on javax.validation, should be fix in next release
        File[] files = new Fileresolved.size() + 1 + 2 ];
        files[i++] = gwtUserArtifact.getFile();
        for ( Artifact artifact : resolved )
        {
            files[i++] = artifact.getFile();
        }
        files[i++] = getArtifact"javax.validation""validation-api" ).getFile();
        files[i++] = getArtifact"javax.validation""validation-api""sources" ).getFile();
        return files;
    }
    protected Artifact getArtifactString groupIdString artifactIdString classifier )
    {
        for ( Artifact artifact :  )
        {
            if ( groupId.equalsartifact.getGroupId() ) && artifactId.equalsartifact.getArtifactId() ) )
            {
                if ( classifier != null && classifier.equalsartifact.getClassifier() ) )
                {
                    return artifact;
                }
                if ( classifier == null && artifact.getClassifier() == null )
                {
                    return artifact;
                }
            }
        }
        getLog().error"Failed to retrieve " + groupId + ":" + artifactId + ":" + classifier );
        return null;
    }

    
TODO remove ! Check that gwt-dev is not define in dependencies : this can produce version conflicts with other dependencies, as gwt-dev is a "uber-jar" with some commons-* and jetty libs inside.
    private void checkGwtDevAsDependency()
    {
        for ( Iterator iterator = getProject().getArtifacts().iterator(); iterator.hasNext(); )
        {
            Artifact artifact = (Artifactiterator.next();
            if ( .equalsartifact.getGroupId() )
                && "gwt-dev".equalsartifact.getArtifactId() )
                && !.equals(  artifact.getScope() ) )
            {
                getLog().warn"Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflicts" );
            }
        }
    }

    
Check gwt-user dependency matches plugin version
    private void checkGwtUserVersion() throws MojoExecutionException
    {
        InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream"org/codehaus/mojo/gwt/mojoGwtVersion.properties" );
        Properties properties = new Properties();
        try
        {
            properties.loadinputStream );
        }
        catch (IOException e)
        {
            throw new MojoExecutionException"Failed to load plugin properties"e );
        }
        finally
        {
            IOUtils.closeQuietlyinputStream );
        }
        for ( Iterator iterator = getProject().getCompileArtifacts().iterator(); iterator.hasNext(); )
        {
            Artifact artifact = (Artifactiterator.next();
            if ( .equalsartifact.getGroupId() )
                 && "gwt-user".equalsartifact.getArtifactId() ) )
            {
                String mojoGwtVersion = properties.getProperty"gwt.version" );
                //ComparableVersion with an up2date maven version
                ArtifactVersion mojoGwtArtifactVersion = new DefaultArtifactVersionmojoGwtVersion );
                ArtifactVersion userGwtArtifactVersion = new DefaultArtifactVersionartifact.getVersion() );
                if ( userGwtArtifactVersion.compareTomojoGwtArtifactVersion ) < 0 )
                {
                    getLog().warn"You're project declares dependency on gwt-user " + artifact.getVersion()
                                       + ". This plugin is designed for at least gwt version " + mojoGwtVersion );
                }
                break;
            }
        }
    }
    protected Artifact resolveString groupIdString artifactIdString versionString typeString classifier )
        throws MojoExecutionException
    {
        // return project.getArtifactMap().get( groupId + ":" + artifactId );
        Artifact artifact = .createArtifactWithClassifiergroupIdartifactIdversiontypeclassifier );
        try
        {
            .resolve(artifact);
        }
        catch ( ArtifactNotFoundException e )
        {
            throw new MojoExecutionException"artifact not found - " + e.getMessage(), e );
        }
        catch ( ArtifactResolutionException e )
        {
            throw new MojoExecutionException"artifact resolver problem - " + e.getMessage(), e );
        }
        return artifact;
    }

    

Parameters:
path file to add to the project compile directories
    protected void addCompileSourceRootFile path )
    {
        getProject().addCompileSourceRootpath.getAbsolutePath() );
    }

    

Returns:
the project
    public MavenProject getProject()
    {
        return ;
    }
    {
        return this.;
    }
    {
        return this.;
    }
    public File getGenerateDirectory()
    {
        if ( !.exists() )
        {
            getLog().debug"Creating target directory " + .getAbsolutePath() );
            .mkdirs();
        }
        return ;
    }
    @SuppressWarnings"unchecked" )
    public Set<ArtifactgetProjectArtifacts()
    {
        return .getArtifacts();
    }
    @SuppressWarnings"unchecked" )
    {
        Set<Artifactartifacts = new HashSet<Artifact>();
        for (Artifact projectArtifact : (Collection<Artifact>) .getArtifacts() )
        {
            String scope = projectArtifact.getScope();
            if ( .equalsscope )
              || .equalsscope ) )
            {
                artifacts.addprojectArtifact );
            }
        }
        return artifacts;
    }
New to GrepCode? Check out our FAQ X