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_PROVIDED;
 import static org.apache.maven.artifact.Artifact.SCOPE_RUNTIME;
 import static org.apache.maven.artifact.Artifact.SCOPE_SYSTEM;
 import static org.apache.maven.artifact.Artifact.SCOPE_TEST;
 
 import java.io.File;
 import java.util.List;
 import java.util.Set;
 
Util to consolidate classpath manipulation stuff in one place.

Author(s):
ccollins
Version:
$Id$
Plexus.component:
role="org.codehaus.mojo.gwt.ClasspathBuilder"
 
 public class ClasspathBuilder
     extends AbstractLogEnabled
 {

    
Build classpath list using either gwtHome (if present) or using *project* dependencies. Note that this is ONLY used for the script/cmd writers (so the scopes are not for the compiler, or war plugins, etc). This is required so that the script writers can get the dependencies they need regardless of the Maven scopes (still want to use the Maven scopes for everything else Maven, but for GWT-Maven we need to access deps differently - directly at times).

Parameters:
project The maven project the Mojo is running for
artifacts the project artifacts (all scopes)
scope artifact scope to use
Returns:
file collection for classpath
Throws:
org.apache.maven.plugin.MojoExecutionException
 
     @SuppressWarnings"unchecked" )
     public Collection<FilebuildClasspathListfinal MavenProject projectfinal String scope,
                                                 Set<Artifactartifacts )
         throws ClasspathBuilderException
     {
         getLogger().debug"establishing classpath list (scope = " + scope + ")" );
 
         Set<Fileitems = new LinkedHashSet<File>();
 
         // Note : Don't call addSourceWithActiveProject as a GWT dependency MUST be a valid GWT library module :
         // * include java sources in the JAR as resources
         // * define a gwt.xml module file to declare the required inherits
         // addSourceWithActiveProject would make some java sources available to GWT compiler that should not be accessible in
         // a non-reactor build, making the build less deterministic and encouraging bad design.
 
         addSourcesitemsproject.getCompileSourceRoots() );
         addResourcesitemsproject.getResources() );
         items.addnew Fileproject.getBuild().getOutputDirectory() ) );
 
         // Use our own ClasspathElements fitering, as for RUNTIME we need to include PROVIDED artifacts,
         // that is not the default Maven policy, as RUNTIME is used here to build the GWTShell execution classpath
 
         if ( scope.equals ) )
         {
             addSourcesitemsproject.getTestCompileSourceRoots() );
             addResourcesitemsproject.getTestResources() );
             items.addnew Fileproject.getBuild().getTestOutputDirectory() ) );
 
             // Add all project dependencies in classpath
             for ( Artifact artifact : artifacts )
             {
                 items.addartifact.getFile() );
             }
         }
         else if ( scope.equals ) )
        {
            // Add all project dependencies in classpath
            getLogger().debug"candidate artifacts : " + artifacts.size() );
            for ( Artifact artifact : artifacts )
            {
                String artifactScope = artifact.getScope();
                if ( .equalsartifactScope ) || .equalsartifactScope )
                    || .equalsartifactScope ) )
                {
                    items.addartifact.getFile() );
                }
            }
        }
        else if ( scope.equals ) )
        {
            // Add all dependencies BUT "TEST" as we need PROVIDED ones to setup the execution
            // GWTShell that is NOT a full JEE server
            for ( Artifact artifact : artifacts )
            {
                getLogger().debug"candidate artifact : " + artifact );
                if ( !artifact.getScope().equals ) && artifact.getArtifactHandler().isAddedToClasspath() )
                {
                    items.addartifact.getFile() );
                }
            }
        }
        else
        {
            throw new ClasspathBuilderException"unsupported scope " + scope );
        }
        return items;
    }

    
Add all sources and resources also with active (maven reactor active) referenced project sources and resources.

Parameters:
project
items
scope
    public void addSourcesWithActiveProjectsfinal MavenProject projectfinal Collection<Fileitems,
                                              final String scope )
    {
        final List<ArtifactscopeArtifacts = getScopeArtifactsprojectscope );
        addSourcesitemsgetSourceRootsprojectscope ) );
        for ( Artifact artifact : scopeArtifacts )
        {
            String projectReferenceId =
                getProjectReferenceIdartifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
            MavenProject refProject = (MavenProjectproject.getProjectReferences().getprojectReferenceId );
            if ( refProject != null )
            {
                addSourcesitemsgetSourceRootsrefProjectscope ) );
            }
        }
    }

    
Add all sources and resources also with active (maven reactor active) referenced project sources and resources.

Parameters:
project
items
scope
    public void addResourcesWithActiveProjectsfinal MavenProject projectfinal Collection<Fileitems,
                                                final String scope )
    {
        final List<ArtifactscopeArtifacts = getScopeArtifactsprojectscope );
        addResourcesitemsgetResourcesprojectscope ) );
        for ( Artifact artifact : scopeArtifacts )
        {
            String projectReferenceId =
                getProjectReferenceIdartifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
            MavenProject refProject = (MavenProjectproject.getProjectReferences().getprojectReferenceId );
            if ( refProject != null )
            {
                addResourcesitemsgetResourcesrefProjectscope ) );
            }
        }
    }

    
Get artifacts for specific scope.

Parameters:
project
scope
Returns:
    @SuppressWarnings"unchecked" )
    private List<ArtifactgetScopeArtifactsfinal MavenProject projectfinal String scope )
    {
        if ( .equalsscope ) )
        {
            return project.getCompileArtifacts();
        }
        if ( .equalsscope ) )
        {
            return project.getRuntimeArtifacts();
        }
        else if ( .equalsscope ) )
        {
            return project.getTestArtifacts();
        }
        else
        {
            throw new RuntimeException"Not allowed scope " + scope );
        }
    }

    
Get source roots for specific scope.

Parameters:
project
scope
Returns:
    @SuppressWarnings"unchecked" )
    private List<StringgetSourceRootsfinal MavenProject projectfinal String scope )
    {
        if ( .equalsscope ) || .equalsscope ) )
        {
            return project.getCompileSourceRoots();
        }
        else if ( .equalsscope ) )
        {
            List<StringsourceRoots = new ArrayList<String>();
            sourceRoots.addAllproject.getTestCompileSourceRoots() );
            sourceRoots.addAllproject.getCompileSourceRoots() );
            return sourceRoots;
        }
        else
        {
            throw new RuntimeException"Not allowed scope " + scope );
        }
    }

    
Get resources for specific scope.

Parameters:
project
scope
Returns:
    @SuppressWarnings"unchecked" )
    private List<ResourcegetResourcesfinal MavenProject projectfinal String scope )
    {
        if ( .equalsscope ) || .equalsscope ) )
        {
            return project.getResources();
        }
        else if ( .equalsscope ) )
        {
            List<Resourceresources = new ArrayList<Resource>();
            resources.addAllproject.getTestResources() );
            resources.addAllproject.getResources() );
            return resources;
        }
        else
        {
            throw new RuntimeException"Not allowed scope " + scope );
        }
    }

    
Add source path and resource paths of the project to the list of classpath items.

Parameters:
items Classpath items.
sourceRoots
    private void addSourcesfinal Collection<Fileitemsfinal Collection<StringsourceRoots )
    {
        for ( String path : sourceRoots )
        {
            items.addnew Filepath ) );
        }
    }

    
Add source path and resource paths of the project to the list of classpath items.

Parameters:
items Classpath items.
resources
    private void addResourcesfinal Collection<Fileitemsfinal Collection<Resourceresources )
    {
        for ( Resource resource : resources )
        {
            items.addnew Fileresource.getDirectory() ) );
        }
    }

    
Cut from MavenProject.java

Parameters:
groupId
artifactId
version
Returns:
    private String getProjectReferenceIdfinal String groupIdfinal String artifactIdfinal String version )
    {
        return groupId + ":" + artifactId + ":" + version;
    }
New to GrepCode? Check out our FAQ X