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 * 32 * @see org.sonatype.aether.util.filter.ScopeDependencyFilter 33 * @see org.eclipse.aether.util.filter.ScopeDependencyFilter 34 */ 35 public class ScopeFilter implements TransformableFilter 36 { 37 private final Collection<String> excluded; 38 39 private final Collection<String> included; 40 41 /** 42 * 43 * @param included specific scopes to include or {@code null} to include all 44 * @param excluded specific scopes to exclude or {@code null} to exclude none 45 */ 46 public ScopeFilter( Collection<String> included, Collection<String> excluded ) 47 { 48 this.included = ( included == null ? null : Collections.unmodifiableCollection( included ) ); 49 this.excluded = ( excluded == null ? null : Collections.unmodifiableCollection( excluded ) ); 50 } 51 52 /** 53 * Construct a ScopeFilter based on included scopes 54 * 55 * @param included the scopes to include, may be {@code null} 56 * @return the filter, never {@code null} 57 */ 58 public static ScopeFilter including( Collection<String> included ) 59 { 60 return new ScopeFilter( included, null ); 61 } 62 63 /** 64 * Construct a ScopeFilter based on included scopes 65 * 66 * @param included the scopes to include, must not be {@code null} 67 * @return the filter, never {@code null} 68 */ 69 public static ScopeFilter including( String... included ) 70 { 71 return new ScopeFilter( Arrays.asList( included ), null ); 72 } 73 74 /** 75 * Construct a ScopeFilter based on excluded scopes 76 * 77 * @param excluded the scopes to exclude, may be {@code null} 78 * @return the filter, never {@code null} 79 */ 80 public static ScopeFilter excluding( Collection<String> excluded ) 81 { 82 return new ScopeFilter( null, excluded ); 83 } 84 85 /** 86 * Construct a ScopeFilter based on excluded scopes 87 * 88 * @param excluded the scopes to exclude, must not be {@code null} 89 * @return the filter, never {@code null} 90 */ 91 public static ScopeFilter excluding( String... excluded ) 92 { 93 return new ScopeFilter( null, Arrays.asList( excluded ) ); 94 } 95 96 /** 97 * Get the excluded scopes 98 * 99 * @return the scopes to exclude, may be {@code null} 100 */ 101 public final Collection<String> getExcluded() 102 { 103 return excluded; 104 } 105 106 /** 107 * Get the included scopes 108 * 109 * @return the scopes to include, may be {@code null} 110 */ 111 public final Collection<String> getIncluded() 112 { 113 return included; 114 } 115 116 /** 117 * Transform this filter to a tool specific implementation 118 * 119 * @param <T> The type to be used. 120 * @param transformer the transformer, must not be {@code null} 121 * @return T. 122 */ 123 public <T> T transform ( FilterTransformer<T> transformer ) 124 { 125 return transformer.transform( this ); 126 } 127 }