View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
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.apache.maven.extension.internal.CoreExports;
32  
33  /**
34   */
35  @Named
36  @Singleton
37  @Deprecated
38  public class DefaultArtifactFilterManager implements ArtifactFilterManager {
39  
40      // this is a live injected collection
41      protected final List<ArtifactFilterManagerDelegate> delegates;
42  
43      protected Set<String> excludedArtifacts;
44  
45      private final Set<String> coreArtifacts;
46  
47      @Inject
48      public DefaultArtifactFilterManager(List<ArtifactFilterManagerDelegate> delegates, CoreExports coreExports) {
49          this.delegates = delegates;
50          this.coreArtifacts = coreExports.getExportedArtifacts();
51      }
52  
53      private synchronized Set<String> getExcludedArtifacts() {
54          if (excludedArtifacts == null) {
55              excludedArtifacts = new LinkedHashSet<>(coreArtifacts);
56          }
57          return excludedArtifacts;
58      }
59  
60      /**
61       * Returns the artifact filter for the core + extension artifacts.
62       *
63       * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter()
64       */
65      public ArtifactFilter getArtifactFilter() {
66          Set<String> excludes = new LinkedHashSet<>(getExcludedArtifacts());
67  
68          for (ArtifactFilterManagerDelegate delegate : delegates) {
69              delegate.addExcludes(excludes);
70          }
71  
72          return new ExclusionSetFilter(excludes);
73      }
74  
75      /**
76       * Returns the artifact filter for the standard core artifacts.
77       *
78       * @see org.apache.maven.ArtifactFilterManager#getCoreArtifactFilter()
79       */
80      public ArtifactFilter getCoreArtifactFilter() {
81          return new ExclusionSetFilter(getCoreArtifactExcludes());
82      }
83  
84      public void excludeArtifact(String artifactId) {
85          getExcludedArtifacts().add(artifactId);
86      }
87  
88      public Set<String> getCoreArtifactExcludes() {
89          Set<String> excludes = new LinkedHashSet<>(coreArtifacts);
90  
91          for (ArtifactFilterManagerDelegate delegate : delegates) {
92              delegate.addCoreExcludes(excludes);
93          }
94  
95          return excludes;
96      }
97  }