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.shared.artifact.filter.resolve;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  import java.util.Collections;
24  
25  /**
26   * Filter based on scope. <strong>Note:</strong> There's no logic for inherited scoped
27   *
28   * @author Robert Scholte
29   * @since 3.0
30   * @see org.eclipse.aether.util.filter.ScopeDependencyFilter
31   */
32  public class ScopeFilter implements TransformableFilter {
33      private final Collection<String> excluded;
34  
35      private final Collection<String> included;
36  
37      /**
38       * <p>Constructor for ScopeFilter.</p>
39       *
40       * @param included specific scopes to include or {@code null} to include all
41       * @param excluded specific scopes to exclude or {@code null} to exclude none
42       */
43      public ScopeFilter(Collection<String> included, Collection<String> excluded) {
44          this.included = (included == null ? null : Collections.unmodifiableCollection(included));
45          this.excluded = (excluded == null ? null : Collections.unmodifiableCollection(excluded));
46      }
47  
48      /**
49       * Construct a ScopeFilter based on included scopes
50       *
51       * @param included the scopes to include, may be {@code null}
52       * @return the filter, never {@code null}
53       */
54      public static ScopeFilter including(Collection<String> included) {
55          return new ScopeFilter(included, null);
56      }
57  
58      /**
59       * Construct a ScopeFilter based on included scopes
60       *
61       * @param included the scopes to include, must not be {@code null}
62       * @return the filter, never {@code null}
63       */
64      public static ScopeFilter including(String... included) {
65          return new ScopeFilter(Arrays.asList(included), null);
66      }
67  
68      /**
69       * Construct a ScopeFilter based on excluded scopes
70       *
71       * @param excluded the scopes to exclude, may be {@code null}
72       * @return the filter, never {@code null}
73       */
74      public static ScopeFilter excluding(Collection<String> excluded) {
75          return new ScopeFilter(null, excluded);
76      }
77  
78      /**
79       * Construct a ScopeFilter based on excluded scopes
80       *
81       * @param excluded the scopes to exclude, must not be {@code null}
82       * @return the filter, never {@code null}
83       */
84      public static ScopeFilter excluding(String... excluded) {
85          return new ScopeFilter(null, Arrays.asList(excluded));
86      }
87  
88      /**
89       * Get the excluded scopes
90       *
91       * @return the scopes to exclude, may be {@code null}
92       */
93      public final Collection<String> getExcluded() {
94          return excluded;
95      }
96  
97      /**
98       * Get the included scopes
99       *
100      * @return the scopes to include, may be {@code null}
101      */
102     public final Collection<String> getIncluded() {
103         return included;
104     }
105 
106     /**
107      * {@inheritDoc}
108      *
109      * Transform this filter to a tool specific implementation
110      */
111     public <T> T transform(FilterTransformer<T> transformer) {
112         return transformer.transform(this);
113     }
114 }