blob: a12c068bebf74405ba0b9cd15efce92f0c5663b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*******************************************************************************
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Evgeny Mandrikov - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.test.validation;
/**
* Parsed value of "java.version" system property.
*/
public final class JavaVersion {
private final int feature;
private final int update;
/**
* @param javaVersionPropertyValue
* value of "java.version" property
* @see System#getProperties() description of properties
*/
JavaVersion(final String javaVersionPropertyValue) {
final String[] s = javaVersionPropertyValue.split("[._-]");
if ("1".equals(s[0])) {
this.feature = Integer.parseInt(s[1]);
this.update = s.length > 3 ? Integer.parseInt(s[3]) : 0;
} else {
this.feature = Integer.parseInt(s[0]);
this.update = s.length > 2 ? Integer.parseInt(s[2]) : 0;
}
}
/**
* @return value of feature-release counter, for example: 8 for version
* "1.8.0_152" and 9 for version "9.0.1"
*/
int feature() {
return feature;
}
/**
* @return value of update-release counter, for example: 152 for version
* "1.8.0_152" and 1 for version "9.0.1"
*/
int update() {
return update;
}
/**
* @param version
* version to compare with
* @return <code>true</code> if this version is less than given
*/
public boolean isBefore(final String version) {
final JavaVersion other = new JavaVersion(version);
return this.feature < other.feature || (this.feature == other.feature
&& this.update < other.update);
}
}
|