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