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