0
# Version Management
1
2
OSGi-compliant version handling and semantic versioning for dependency resolution and compatibility analysis.
3
4
## Capabilities
5
6
### Version
7
8
OSGi version implementation with semantic versioning support for precise dependency management.
9
10
```java { .api }
11
/**
12
* OSGi version implementation with semantic versioning support
13
*/
14
public class Version implements Comparable<Version> {
15
/** Create version with all components */
16
public Version(int major, int minor, int micro, String qualifier);
17
18
/** Create version with major, minor, micro */
19
public Version(int major, int minor, int micro);
20
21
/** Create version with major, minor */
22
public Version(int major, int minor);
23
24
/** Create version with just major */
25
public Version(int major);
26
27
/** Parse version from string */
28
public static Version parseVersion(String version);
29
30
/** Get major version number */
31
public int getMajor();
32
33
/** Get minor version number */
34
public int getMinor();
35
36
/** Get micro version number */
37
public int getMicro();
38
39
/** Get qualifier string */
40
public String getQualifier();
41
42
/** Compare with another version */
43
public int compareTo(Version other);
44
45
/** Check equality with another version */
46
public boolean equals(Object obj);
47
48
/** Get hash code */
49
public int hashCode();
50
51
/** Convert to string representation */
52
public String toString();
53
54
/** Check if this is higher than another version */
55
public boolean isHigher(Version other);
56
57
/** Check if this is lower than another version */
58
public boolean isLower(Version other);
59
60
/** Get base version (without qualifier) */
61
public Version getWithoutQualifier();
62
}
63
```
64
65
**Usage Examples:**
66
67
```java
68
import aQute.bnd.version.Version;
69
70
// Create versions
71
Version v1 = new Version(1, 2, 3, "SNAPSHOT");
72
Version v2 = Version.parseVersion("2.0.0");
73
Version v3 = new Version(1, 2, 4);
74
75
// Compare versions
76
System.out.println(v1.compareTo(v2)); // negative (v1 < v2)
77
System.out.println(v1.compareTo(v3)); // negative (v1 < v3)
78
System.out.println(v2.isHigher(v1)); // true
79
80
// Version components
81
System.out.println("Major: " + v1.getMajor()); // 1
82
System.out.println("Minor: " + v1.getMinor()); // 2
83
System.out.println("Micro: " + v1.getMicro()); // 3
84
System.out.println("Qualifier: " + v1.getQualifier()); // SNAPSHOT
85
86
// String representation
87
System.out.println(v1.toString()); // "1.2.3.SNAPSHOT"
88
System.out.println(v2.toString()); // "2.0.0"
89
90
// Version without qualifier
91
Version base = v1.getWithoutQualifier(); // "1.2.3"
92
```
93
94
### VersionRange
95
96
Represents a version range for dependency resolution with inclusion/exclusion rules.
97
98
```java { .api }
99
/**
100
* Represents a version range for dependency resolution
101
*/
102
public class VersionRange {
103
/** Parse version range from string */
104
public static VersionRange parseVersionRange(String range);
105
106
/** Create range with floor and ceiling */
107
public VersionRange(String floor, boolean floorInclusive, String ceiling, boolean ceilingInclusive);
108
109
/** Check if version is included in range */
110
public boolean includes(Version version);
111
112
/** Check if range includes another range */
113
public boolean includes(VersionRange other);
114
115
/** Get intersection with another range */
116
public VersionRange intersect(VersionRange other);
117
118
/** Check if range intersects with another */
119
public boolean intersects(VersionRange other);
120
121
/** Get floor version */
122
public Version getFloor();
123
124
/** Check if floor is inclusive */
125
public boolean isFloorInclusive();
126
127
/** Get ceiling version */
128
public Version getCeiling();
129
130
/** Check if ceiling is inclusive */
131
public boolean isCeilingInclusive();
132
133
/** Check if this is an exact version (not a range) */
134
public boolean isExact();
135
136
/** Convert to string representation */
137
public String toString();
138
139
/** Convert to OSGi version range string */
140
public String toOSGiString();
141
}
142
```
143
144
**Usage Examples:**
145
146
```java
147
import aQute.bnd.version.VersionRange;
148
import aQute.bnd.version.Version;
149
150
// Parse version ranges
151
VersionRange range1 = VersionRange.parseVersionRange("[1.0,2.0)"); // 1.0 <= v < 2.0
152
VersionRange range2 = VersionRange.parseVersionRange("(1.5,)"); // v > 1.5
153
VersionRange range3 = VersionRange.parseVersionRange("[1.2.3]"); // exactly 1.2.3
154
155
// Check version inclusion
156
Version v = new Version(1, 5, 0);
157
System.out.println(range1.includes(v)); // true
158
System.out.println(range2.includes(v)); // false (1.5.0 not > 1.5)
159
System.out.println(range3.includes(v)); // false
160
161
// Range operations
162
VersionRange intersection = range1.intersect(range2);
163
System.out.println(intersection); // "(1.5,2.0)"
164
165
// Range properties
166
System.out.println("Floor: " + range1.getFloor()); // 1.0.0
167
System.out.println("Floor inclusive: " + range1.isFloorInclusive()); // true
168
System.out.println("Ceiling: " + range1.getCeiling()); // 2.0.0
169
System.out.println("Ceiling inclusive: " + range1.isCeilingInclusive()); // false
170
```
171
172
### Version Utilities
173
174
Utility classes for version manipulation and analysis.
175
176
```java { .api }
177
/**
178
* Utilities for version manipulation and analysis
179
*/
180
public class VersionUtils {
181
/** Check if version satisfies range */
182
public static boolean satisfies(Version version, String range);
183
184
/** Get highest version from collection */
185
public static Version highest(Collection<Version> versions);
186
187
/** Get lowest version from collection */
188
public static Version lowest(Collection<Version> versions);
189
190
/** Filter versions by range */
191
public static List<Version> filter(Collection<Version> versions, VersionRange range);
192
193
/** Increment version component */
194
public static Version increment(Version version, VersionComponent component);
195
196
/** Calculate semantic version change */
197
public static VersionChange calculateChange(Version from, Version to);
198
199
/** Validate version string */
200
public static boolean isValid(String version);
201
202
/** Normalize version string */
203
public static String normalize(String version);
204
}
205
206
/**
207
* Version components for increment operations
208
*/
209
public enum VersionComponent {
210
MAJOR, MINOR, MICRO, QUALIFIER
211
}
212
213
/**
214
* Types of version changes
215
*/
216
public enum VersionChange {
217
MAJOR, // Breaking changes
218
MINOR, // New features, backward compatible
219
MICRO, // Bug fixes
220
QUALIFIER // Qualifier changes only
221
}
222
```
223
224
### Maven Version Support
225
226
Support for Maven-style version handling and conversion.
227
228
```java { .api }
229
/**
230
* Maven version representation and conversion
231
*/
232
public class MavenVersion implements Comparable<MavenVersion> {
233
/** Parse Maven version string */
234
public static MavenVersion parseMavenVersion(String version);
235
236
/** Convert to OSGi version */
237
public Version toOSGiVersion();
238
239
/** Get version string */
240
public String getVersion();
241
242
/** Check if snapshot version */
243
public boolean isSnapshot();
244
245
/** Get base version (without SNAPSHOT) */
246
public MavenVersion getBaseVersion();
247
248
/** Compare with another Maven version */
249
public int compareTo(MavenVersion other);
250
}
251
252
/**
253
* Utilities for Maven version handling
254
*/
255
public class MavenVersionUtils {
256
/** Convert Maven version to OSGi */
257
public static Version toOSGi(String mavenVersion);
258
259
/** Convert OSGi version to Maven */
260
public static String toMaven(Version osgiVersion);
261
262
/** Check if Maven version is valid */
263
public static boolean isValidMavenVersion(String version);
264
265
/** Clean up Maven version for OSGi compatibility */
266
public static String cleanupVersion(String version);
267
}
268
```
269
270
**Complete Version Management Example:**
271
272
```java
273
import aQute.bnd.version.*;
274
275
// Complete version management workflow
276
public class VersionManagementExample {
277
278
public void demonstrateVersionManagement() {
279
// Create and parse versions
280
Version current = Version.parseVersion("1.2.3");
281
Version newer = new Version(1, 3, 0);
282
Version snapshot = Version.parseVersion("1.2.4.SNAPSHOT");
283
284
System.out.println("Current: " + current);
285
System.out.println("Newer: " + newer);
286
System.out.println("Snapshot: " + snapshot);
287
288
// Version comparison
289
if (newer.isHigher(current)) {
290
System.out.println("Update available: " + newer);
291
}
292
293
// Version ranges for dependencies
294
VersionRange apiRange = VersionRange.parseVersionRange("[1.0,2.0)");
295
VersionRange implRange = VersionRange.parseVersionRange("[1.2,1.3)");
296
297
// Check compatibility
298
System.out.println("Current compatible with API: " + apiRange.includes(current));
299
System.out.println("Current compatible with impl: " + implRange.includes(current));
300
301
// Find compatible versions
302
List<Version> availableVersions = Arrays.asList(
303
Version.parseVersion("0.9.0"),
304
Version.parseVersion("1.1.0"),
305
Version.parseVersion("1.2.0"),
306
Version.parseVersion("1.2.5"),
307
Version.parseVersion("1.3.0"),
308
Version.parseVersion("2.0.0")
309
);
310
311
List<Version> compatible = VersionUtils.filter(availableVersions, apiRange);
312
System.out.println("Compatible versions: " + compatible);
313
314
Version highest = VersionUtils.highest(compatible);
315
System.out.println("Highest compatible: " + highest);
316
317
// Maven version conversion
318
MavenVersion mavenVer = MavenVersion.parseMavenVersion("1.2.3-SNAPSHOT");
319
Version osgiVer = mavenVer.toOSGiVersion();
320
System.out.println("Maven: " + mavenVer + " -> OSGi: " + osgiVer);
321
322
// Increment versions for releases
323
Version nextMicro = VersionUtils.increment(current, VersionComponent.MICRO);
324
Version nextMinor = VersionUtils.increment(current, VersionComponent.MINOR);
325
Version nextMajor = VersionUtils.increment(current, VersionComponent.MAJOR);
326
327
System.out.println("Next micro: " + nextMicro); // 1.2.4
328
System.out.println("Next minor: " + nextMinor); // 1.3.0
329
System.out.println("Next major: " + nextMajor); // 2.0.0
330
331
// Calculate version change type
332
VersionChange change = VersionUtils.calculateChange(current, newer);
333
System.out.println("Change type: " + change); // MINOR
334
}
335
}
336
```