1 package org.apache.maven.shared.artifact.filter.collection; 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.ArrayList; 23 import java.util.List; 24 import java.util.Set; 25 26 import org.apache.maven.artifact.Artifact; 27 28 /** 29 * <p>FilterArtifacts class.</p> 30 * 31 * @author <a href="mailto:brianf@apache.org">Brian Fox</a> 32 */ 33 public class FilterArtifacts 34 { 35 private List<ArtifactsFilter> filters; 36 37 /** 38 * Created new instance. 39 */ 40 public FilterArtifacts() 41 { 42 filters = new ArrayList<>(); 43 } 44 45 /** 46 * Removes all of the elements from this list. The list will be empty after this call returns. 47 */ 48 public void clearFilters() 49 { 50 filters.clear(); 51 } 52 53 /** 54 * Appends the specified element to the end of this list. 55 * 56 * @param filter element to be appended to this list. 57 */ 58 public void addFilter( ArtifactsFilter filter ) 59 { 60 if ( filter != null ) 61 { 62 filters.add( filter ); 63 } 64 } 65 66 /** 67 * Inserts the specified element at the specified position in this list. Shifts the element currently at that 68 * position (if any) and any subsequent elements to the right (adds one to their indices). 69 * 70 * @param index at which index the specified filter is to be inserted. 71 * @param filter the filter to be inserted. 72 * @throws IndexOutOfBoundsException if index is out of range <code>(index < 0 || index > size())</code>. 73 */ 74 public void addFilter( int index, ArtifactsFilter filter ) 75 { 76 if ( filter != null ) 77 { 78 filters.add( index, filter ); 79 } 80 } 81 82 /** 83 * <p>filter.</p> 84 * 85 * @param artifacts The {@link org.apache.maven.artifact.Artifact}s to filter. 86 * @return The resulting artifacts set. 87 * @throws org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in case of a failure. 88 */ 89 public Set<Artifact> filter( Set<Artifact> artifacts ) 90 throws ArtifactFilterException 91 { 92 // apply filters 93 for ( ArtifactsFilter filter : filters ) 94 { 95 // log(artifacts,log); 96 try 97 { 98 artifacts = filter.filter( artifacts ); 99 } 100 catch ( NullPointerException e ) 101 { 102 // don't do anything, just skip this. 103 } 104 } 105 106 return artifacts; 107 } 108 109 /** 110 * <p>Getter for the field <code>filters</code>.</p> 111 * 112 * @return the filters. 113 */ 114 public List<ArtifactsFilter> getFilters() 115 { 116 return this.filters; 117 } 118 119 /** 120 * <p>Setter for the field <code>filters</code>.</p> 121 * 122 * @param filters The filters to set. 123 */ 124 public void setFilters( List<ArtifactsFilter> filters ) 125 { 126 this.filters = filters; 127 } 128 }