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