1 package org.eclipse.aether.internal.test.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24
25 import org.eclipse.aether.version.InvalidVersionSpecificationException;
26 import org.eclipse.aether.version.Version;
27 import org.eclipse.aether.version.VersionConstraint;
28 import org.eclipse.aether.version.VersionRange;
29 import org.eclipse.aether.version.VersionScheme;
30
31
32
33
34 final class TestVersionScheme
35 implements VersionScheme
36 {
37
38 public Version parseVersion( final String version )
39 throws InvalidVersionSpecificationException
40 {
41 return new TestVersion( version );
42 }
43
44 public VersionRange parseVersionRange( final String range )
45 throws InvalidVersionSpecificationException
46 {
47 return new TestVersionRange( range );
48 }
49
50 public VersionConstraint parseVersionConstraint( final String constraint )
51 throws InvalidVersionSpecificationException
52 {
53 Collection<VersionRange> ranges = new ArrayList<VersionRange>();
54
55 String process = constraint;
56
57 while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
58 {
59 int index1 = process.indexOf( ')' );
60 int index2 = process.indexOf( ']' );
61
62 int index = index2;
63 if ( index2 < 0 || ( index1 >= 0 && index1 < index2 ) )
64 {
65 index = index1;
66 }
67
68 if ( index < 0 )
69 {
70 throw new InvalidVersionSpecificationException( constraint, "Unbounded version range " + constraint );
71 }
72
73 VersionRange range = parseVersionRange( process.substring( 0, index + 1 ) );
74 ranges.add( range );
75
76 process = process.substring( index + 1 ).trim();
77
78 if ( process.length() > 0 && process.startsWith( "," ) )
79 {
80 process = process.substring( 1 ).trim();
81 }
82 }
83
84 if ( process.length() > 0 && !ranges.isEmpty() )
85 {
86 throw new InvalidVersionSpecificationException( constraint, "Invalid version range " + constraint
87 + ", expected [ or ( but got " + process );
88 }
89
90 VersionConstraint result;
91 if ( ranges.isEmpty() )
92 {
93 result = new TestVersionConstraint( parseVersion( constraint ) );
94 }
95 else
96 {
97 result = new TestVersionConstraint( ranges.iterator().next() );
98 }
99
100 return result;
101 }
102
103 @Override
104 public boolean equals( final Object obj )
105 {
106 if ( this == obj )
107 {
108 return true;
109 }
110
111 return obj != null && getClass().equals( obj.getClass() );
112 }
113
114 @Override
115 public int hashCode()
116 {
117 return getClass().hashCode();
118 }
119
120 }