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      @Override
66      public ArtifactFilter getArtifactFilter() {
67          Set<String> excludes = new LinkedHashSet<>(getExcludedArtifacts());
68  
69          for (ArtifactFilterManagerDelegate delegate : delegates) {
70              delegate.addExcludes(excludes);
71          }
72  
73          return new ExclusionSetFilter(excludes);
74      }
75  
76      /**
77       * Returns the artifact filter for the standard core artifacts.
78       *
79       * @see org.apache.maven.ArtifactFilterManager#getCoreArtifactFilter()
80       */
81      @Override
82      public ArtifactFilter getCoreArtifactFilter() {
83          return new ExclusionSetFilter(getCoreArtifactExcludes());
84      }
85  
86      @Override
87      public void excludeArtifact(String artifactId) {
88          getExcludedArtifacts().add(artifactId);
89      }
90  
91      @Override
92      public Set<String> getCoreArtifactExcludes() {
93          Set<String> excludes = new LinkedHashSet<>(coreArtifacts);
94  
95          for (ArtifactFilterManagerDelegate delegate : delegates) {
96              delegate.addCoreExcludes(excludes);
97          }
98  
99          return excludes;
100     }
101 }