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.apache.maven:maven-artifact" );
62          artifacts.add( "org.apache.maven:maven-aether-provider" );
63          artifacts.add( "org.apache.maven:maven-artifact-manager" );
64          artifacts.add( "org.apache.maven:maven-compat" );
65          artifacts.add( "org.apache.maven:maven-core" );
66          artifacts.add( "org.apache.maven:maven-error-diagnostics" );
67          artifacts.add( "org.apache.maven:maven-lifecycle" );
68          artifacts.add( "org.apache.maven:maven-model" );
69          artifacts.add( "org.apache.maven:maven-model-builder" );
70          artifacts.add( "org.apache.maven:maven-monitor" );
71          artifacts.add( "org.apache.maven:maven-plugin-api" );
72          artifacts.add( "org.apache.maven:maven-plugin-descriptor" );
73          artifacts.add( "org.apache.maven:maven-plugin-parameter-documenter" );
74          artifacts.add( "org.apache.maven:maven-plugin-registry" );
75          artifacts.add( "org.apache.maven:maven-profile" );
76          artifacts.add( "org.apache.maven:maven-project" );
77          artifacts.add( "org.apache.maven:maven-repository-metadata" );
78          artifacts.add( "org.apache.maven:maven-settings" );
79          artifacts.add( "org.apache.maven:maven-settings-builder" );
80          artifacts.add( "org.apache.maven:maven-toolchain" );
81          artifacts.add( "org.apache.maven.wagon:wagon-provider-api" );
82          artifacts.add( "org.sonatype.aether:aether-api" );
83          artifacts.add( "org.sonatype.aether:aether-spi" );
84          artifacts.add( "org.sonatype.aether:aether-impl" );
85  
86          /*
87           * NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise
88           * provoke linkage errors for wagons contributed by build extensions. We also don't need to exclude the wagons
89           * from plugins. Plugins that use wagons directly and declare the corresponding dependency will simply use a
90           * wagon from their plugin realm.
91           */
92  
93          DEFAULT_EXCLUSIONS = Collections.unmodifiableSet( artifacts);
94      }
95  
96      protected Set<String> excludedArtifacts = new HashSet<String>( DEFAULT_EXCLUSIONS );
97  
98      /**
99       * @deprecated Use this class as a component instead, and then use getArtifactFilter().
100      */
101     public static ArtifactFilter createStandardFilter()
102     {
103         // TODO: configure this from bootstrap or scan lib
104         return new ExclusionSetFilter( DEFAULT_EXCLUSIONS );
105     }
106 
107     /**
108      * Returns the artifact filter for the core + extension artifacts.
109      *
110      * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter()
111      */
112     public ArtifactFilter getArtifactFilter()
113     {
114         Set<String> excludes = new LinkedHashSet<String>( excludedArtifacts );
115 
116         for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
117         {
118             delegate.addExcludes( excludes );
119         }
120 
121         return new ExclusionSetFilter( excludes );
122     }
123 
124     /**
125      * Returns the artifact filter for the standard core artifacts.
126      *
127      * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
128      */
129     public ArtifactFilter getCoreArtifactFilter()
130     {
131         return new ExclusionSetFilter( getCoreArtifactExcludes() );
132     }
133 
134     private List<ArtifactFilterManagerDelegate> getDelegates()
135     {
136         try
137         {
138             return plexus.lookupList( ArtifactFilterManagerDelegate.class );
139         }
140         catch ( ComponentLookupException e )
141         {
142             return new ArrayList<ArtifactFilterManagerDelegate>();
143         }
144     }
145 
146     /* (non-Javadoc)
147      * @see org.apache.maven.ArtifactFilterManager#excludeArtifact(java.lang.String)
148      */
149     public void excludeArtifact( String artifactId )
150     {
151         excludedArtifacts.add( artifactId );
152     }
153 
154     public Set<String> getCoreArtifactExcludes()
155     {
156         Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
157 
158         for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
159         {
160             delegate.addCoreExcludes( excludes );
161         }
162 
163         return excludes;
164     }
165 
166 }