1 package com.atlassian.maven.plugins.licenses;
2
3 import org.apache.maven.artifact.Artifact;
4 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
5 import org.apache.oro.text.GlobCompiler;
6 import org.apache.oro.text.regex.MalformedPatternException;
7 import org.apache.oro.text.regex.Pattern;
8 import org.apache.oro.text.regex.PatternCompiler;
9 import org.apache.oro.text.regex.Perl5Matcher;
10
11
12
13
14
15
16
17
18
19
20 public class GlobArfifactFilter implements ArtifactFilter
21 {
22 private static final char[] EMPTY_CHAR_ARRAY = new char[0];
23 private final Pattern pattern;
24 private final Perl5Matcher matcher = new Perl5Matcher();
25
26 public GlobArfifactFilter(String expr) throws MalformedPatternException
27 {
28 PatternCompiler compiler = new GlobCompiler();
29 pattern = compiler.compile(expr, GlobCompiler.CASE_INSENSITIVE_MASK);
30 }
31
32 public boolean include(Artifact artifact)
33 {
34 String target = toId(artifact);
35 return matcher.matches((target != null) ? target.toCharArray() : EMPTY_CHAR_ARRAY, pattern);
36 }
37
38 private String toId(Artifact artifact)
39 {
40 StringBuffer sb = new StringBuffer();
41 sb.append(artifact.getGroupId());
42 sb.append(":");
43 sb.append(artifact.getArtifactId());
44 sb.append(":");
45 sb.append(artifact.getVersion());
46 return sb.toString();
47 }
48 }