View Javadoc

1   /**
2    * 
3    */
4   package com.atlassian.maven.plugins.licenses;
5   
6   import java.util.ArrayList;
7   import java.util.Iterator;
8   import java.util.List;
9   
10  import org.apache.maven.artifact.Artifact;
11  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
12  import org.apache.oro.text.regex.MalformedPatternException;
13  
14  /**
15   * Parses the given list of artifact filter strings into a list of
16   * {@link RegexpArfifactFilter} objects and the given list of scopes into a list
17   * of {@link ArtifactScopeFilter}. Artifact that matches any of those filters
18   * will be excluded.
19   * 
20   * @author Sherali Karimov
21   */
22  class ArtifactExclusionFilter implements ArtifactFilter
23  {
24      private final ArtifactFilter[] filters;
25  
26      public ArtifactExclusionFilter(List artifactFilters, List scopeFilters) throws MalformedPatternException
27      {
28          List tempList = new ArrayList();
29          if (artifactFilters != null)
30          {
31              for (Iterator iterator = artifactFilters.iterator(); iterator.hasNext();)
32              {
33                  String filterStr = (String) iterator.next();
34                  tempList.add(new GlobArfifactFilter(filterStr));
35              }
36          }
37          if (scopeFilters != null)
38          {
39              for (Iterator iterator = scopeFilters.iterator(); iterator.hasNext();)
40              {
41                  String filterStr = (String) iterator.next();
42                  tempList.add(new ArtifactScopeFilter(filterStr));
43              }
44          }
45          this.filters = (ArtifactFilter[]) tempList.toArray(new ArtifactFilter[0]);
46      }
47  
48      public boolean include(Artifact artifactToCheck)
49      {
50          for (int i = 0; i < filters.length; i++)
51          {
52              if (filters[i].include(artifactToCheck))
53                  return false;
54          }
55          return true;
56      }
57  }