View Javadoc

1   package org.apache.maven;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.LinkedHashSet;
26  import java.util.List;
27  import java.util.Set;
28  
29  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
30  import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
31  import org.codehaus.plexus.PlexusContainer;
32  import org.codehaus.plexus.component.annotations.Component;
33  import org.codehaus.plexus.component.annotations.Requirement;
34  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
35  
36  /**
37   * @author Jason van Zyl
38   * @todo this should probably be a component with some dynamic control of filtering
39   */
40  @Component( role = ArtifactFilterManager.class )
41  public class DefaultArtifactFilterManager 
42      implements ArtifactFilterManager
43  {
44  
45      private static final Set<String> DEFAULT_EXCLUSIONS;
46  
47      @Requirement
48      private PlexusContainer plexus;
49  
50      static
51      {
52          Set<String> artifacts = new HashSet<String>();
53  
54          artifacts.add( "classworlds:classworlds" );
55          artifacts.add( "org.codehaus.plexus:plexus-classworlds" );
56          artifacts.add( "org.codehaus.plexus:plexus-component-api" );
57          artifacts.add( "org.codehaus.plexus:plexus-container-default" );
58          artifacts.add( "plexus:plexus-container-default" );
59          artifacts.add( "org.sonatype.spice:spice-inject-plexus" );
60          artifacts.add( "org.sonatype.sisu:sisu-inject-plexus" );
61          artifacts.add( "org.eclipse.sisu:org.eclipse.sisu.plexus" );
62          artifacts.add( "org.apache.maven:maven-artifact" );
63          artifacts.add( "org.apache.maven:maven-aether-provider" );
64          artifacts.add( "org.apache.maven:maven-artifact-manager" );
65          artifacts.add( "org.apache.maven:maven-compat" );
66          artifacts.add( "org.apache.maven:maven-core" );
67          artifacts.add( "org.apache.maven:maven-error-diagnostics" );
68          artifacts.add( "org.apache.maven:maven-lifecycle" );
69          artifacts.add( "org.apache.maven:maven-model" );
70          artifacts.add( "org.apache.maven:maven-model-builder" );
71          artifacts.add( "org.apache.maven:maven-monitor" );
72          artifacts.add( "org.apache.maven:maven-plugin-api" );
73          artifacts.add( "org.apache.maven:maven-plugin-descriptor" );
74          artifacts.add( "org.apache.maven:maven-plugin-parameter-documenter" );
75          artifacts.add( "org.apache.maven:maven-plugin-registry" );
76          artifacts.add( "org.apache.maven:maven-profile" );
77          artifacts.add( "org.apache.maven:maven-project" );
78          artifacts.add( "org.apache.maven:maven-repository-metadata" );
79          artifacts.add( "org.apache.maven:maven-settings" );
80          artifacts.add( "org.apache.maven:maven-settings-builder" );
81          artifacts.add( "org.apache.maven:maven-toolchain" );
82          artifacts.add( "org.apache.maven.wagon:wagon-provider-api" );
83          artifacts.add( "org.eclipse.aether:aether-api" );
84          artifacts.add( "org.eclipse.aether:aether-spi" );
85          artifacts.add( "org.eclipse.aether:aether-impl" );
86          //
87          // We must also filter out the old or NoClassDefFoundErrors will surface
88          //
89          artifacts.add( "org.sonatype.aether:aether-api" );
90          artifacts.add( "org.sonatype.aether:aether-spi" );
91          artifacts.add( "org.sonatype.aether:aether-impl" );
92  
93          /*
94           * NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise
95           * provoke linkage errors for wagons contributed by build extensions. We also don't need to exclude the wagons
96           * from plugins. Plugins that use wagons directly and declare the corresponding dependency will simply use a
97           * wagon from their plugin realm.
98           */
99  
100         DEFAULT_EXCLUSIONS = Collections.unmodifiableSet( artifacts );
101     }
102 
103     protected Set<String> excludedArtifacts = new HashSet<String>( DEFAULT_EXCLUSIONS );
104 
105     /**
106      * @deprecated Use this class as a component instead, and then use getArtifactFilter().
107      */
108     public static ArtifactFilter createStandardFilter()
109     {
110         // TODO: configure this from bootstrap or scan lib
111         return new ExclusionSetFilter( DEFAULT_EXCLUSIONS );
112     }
113 
114     /**
115      * Returns the artifact filter for the core + extension artifacts.
116      *
117      * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter()
118      */
119     public ArtifactFilter getArtifactFilter()
120     {
121         Set<String> excludes = new LinkedHashSet<String>( excludedArtifacts );
122 
123         for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
124         {
125             delegate.addExcludes( excludes );
126         }
127 
128         return new ExclusionSetFilter( excludes );
129     }
130 
131     /**
132      * Returns the artifact filter for the standard core artifacts.
133      *
134      * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
135      */
136     public ArtifactFilter getCoreArtifactFilter()
137     {
138         return new ExclusionSetFilter( getCoreArtifactExcludes() );
139     }
140 
141     private List<ArtifactFilterManagerDelegate> getDelegates()
142     {
143         try
144         {
145             return plexus.lookupList( ArtifactFilterManagerDelegate.class );
146         }
147         catch ( ComponentLookupException e )
148         {
149             return new ArrayList<ArtifactFilterManagerDelegate>();
150         }
151     }
152 
153     /* (non-Javadoc)
154      * @see org.apache.maven.ArtifactFilterManager#excludeArtifact(java.lang.String)
155      */
156     public void excludeArtifact( String artifactId )
157     {
158         excludedArtifacts.add( artifactId );
159     }
160 
161     public Set<String> getCoreArtifactExcludes()
162     {
163         Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
164 
165         for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
166         {
167             delegate.addCoreExcludes( excludes );
168         }
169 
170         return excludes;
171     }
172 
173 }