1 package org.apache.maven.toolchain;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
23 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
24 import org.apache.maven.artifact.versioning.VersionRange;
25
26
27
28
29
30 public final class RequirementMatcherFactory
31 {
32 private RequirementMatcherFactory()
33 {
34 }
35
36 public static RequirementMatcher createExactMatcher( String provideValue )
37 {
38 return new ExactMatcher( provideValue );
39 }
40
41 public static RequirementMatcher createVersionMatcher( String provideValue )
42 {
43 return new VersionMatcher( provideValue );
44 }
45
46 private static final class ExactMatcher
47 implements RequirementMatcher
48 {
49
50 private String provides;
51
52 private ExactMatcher( String provides )
53 {
54 this.provides = provides;
55 }
56
57 public boolean matches( String requirement )
58 {
59 return provides.equalsIgnoreCase( requirement );
60 }
61 }
62
63 private static final class VersionMatcher
64 implements RequirementMatcher
65 {
66
67 DefaultArtifactVersion version;
68
69 private VersionMatcher( String version )
70 {
71 this.version = new DefaultArtifactVersion( version );
72 }
73
74 public boolean matches( String requirement )
75 {
76 try
77 {
78 VersionRange range = VersionRange.createFromVersionSpec( requirement );
79 if ( range.hasRestrictions() )
80 {
81 return range.containsVersion( version );
82 }
83 else
84 {
85 return range.getRecommendedVersion().compareTo( version ) == 0;
86 }
87 }
88 catch ( InvalidVersionSpecificationException ex )
89 {
90
91 ex.printStackTrace();
92 return false;
93 }
94 }
95 }
96 }