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.LinkedHashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  import javax.inject.Inject;
27  import javax.inject.Named;
28  import javax.inject.Singleton;
29  
30  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
31  import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
32  import org.apache.maven.extension.internal.CoreExportsProvider;
33  
34  /**
35   * @author Jason van Zyl
36   */
37  @Named
38  @Singleton
39  @SuppressWarnings( "deprecation" )
40  public class DefaultArtifactFilterManager
41      implements ArtifactFilterManager
42  {
43  
44      // this is a live injected collection
45      protected final List<ArtifactFilterManagerDelegate> delegates;
46  
47      protected Set<String> excludedArtifacts;
48  
49      private final Set<String> coreArtifacts;
50  
51      @Inject
52      public DefaultArtifactFilterManager( List<ArtifactFilterManagerDelegate> delegates,
53                                           CoreExportsProvider coreExports )
54      {
55          this.delegates = delegates;
56          this.coreArtifacts = coreExports.get().getExportedArtifacts();
57      }
58  
59      private synchronized Set<String> getExcludedArtifacts()
60      {
61          if ( excludedArtifacts == null )
62          {
63              excludedArtifacts = new LinkedHashSet<>( coreArtifacts );
64          }
65          return excludedArtifacts;
66      }
67  
68      /**
69       * Returns the artifact filter for the core + extension artifacts.
70       *
71       * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter()
72       */
73      public ArtifactFilter getArtifactFilter()
74      {
75          Set<String> excludes = new LinkedHashSet<>( getExcludedArtifacts() );
76  
77          for ( ArtifactFilterManagerDelegate delegate : delegates )
78          {
79              delegate.addExcludes( excludes );
80          }
81  
82          return new ExclusionSetFilter( excludes );
83      }
84  
85      /**
86       * Returns the artifact filter for the standard core artifacts.
87       *
88       * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
89       */
90      public ArtifactFilter getCoreArtifactFilter()
91      {
92          return new ExclusionSetFilter( getCoreArtifactExcludes() );
93      }
94  
95      public void excludeArtifact( String artifactId )
96      {
97          getExcludedArtifacts().add( artifactId );
98      }
99  
100     public Set<String> getCoreArtifactExcludes()
101     {
102         Set<String> excludes = new LinkedHashSet<>( coreArtifacts );
103 
104         for ( ArtifactFilterManagerDelegate delegate : delegates )
105         {
106             delegate.addCoreExcludes( excludes );
107         }
108 
109         return excludes;
110     }
111 
112 }