/
Version.java
156 lines (138 loc) · 4.81 KB
/
Version.java
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* JBoss, Home of Professional Open Source.
* Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.infinispan;
import net.jcip.annotations.Immutable;
/**
* Contains version information about this release of Infinispan.
*
* @author Bela Ban
* @since 4.0
*/
@Immutable
public class Version {
public static final String version = "4.1.0.SNAPSHOT";
public static final String codename = "Radegast";
public static final String projectName = "Infinispan";
static final byte[] version_id = {'0', '4', '1', '0', 'S'};
private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
private static final int MAJOR_MASK = 0x00f800;
private static final int MINOR_MASK = 0x0007c0;
private static final int PATCH_MASK = 0x00003f;
/**
* Prints version information.
*/
public static void main(String[] args) {
printFullVersionInformation();
}
/**
* Prints full version information to the standard output.
*/
public static void printFullVersionInformation() {
System.out.println(projectName);
System.out.println();
System.out.println("\nVersion: \t" + version);
System.out.println("Codename: \t" + codename);
System.out.println("History: \t(see https://jira.jboss.org/jira/browse/ISPN for details)\n");
}
/**
* Returns version information as a string.
*/
public static String printVersion() {
return projectName + " '" + codename + "' " + version;
}
public static String printVersionId(byte[] v, int len) {
StringBuilder sb = new StringBuilder();
if (v != null) {
if (len <= 0)
len = v.length;
for (int i = 0; i < len; i++)
sb.append((char) v[i]);
}
return sb.toString();
}
public static String printVersionId(byte[] v) {
StringBuilder sb = new StringBuilder();
if (v != null) {
for (byte aV : v) sb.append((char) aV);
}
return sb.toString();
}
public static boolean compareTo(byte[] v) {
if (v == null)
return false;
if (v.length < version_id.length)
return false;
for (int i = 0; i < version_id.length; i++) {
if (version_id[i] != v[i])
return false;
}
return true;
}
public static int getLength() {
return version_id.length;
}
public static short getVersionShort() {
return getVersionShort(version);
}
public static short getVersionShort(String versionString) {
if (versionString == null)
throw new IllegalArgumentException("versionString is null");
String parts[] = getParts(versionString);
int a = 0;
int b = 0;
int c = 0;
if (parts.length > 0)
a = Integer.parseInt(parts[0]);
if (parts.length > 1)
b = Integer.parseInt(parts[1]);
if (parts.length > 2)
c = Integer.parseInt(parts[2]);
return encodeVersion(a, b, c);
}
public static short encodeVersion(int major, int minor, int patch) {
return (short) ((major << MAJOR_SHIFT)
+ (minor << MINOR_SHIFT)
+ patch);
}
public static String decodeVersion(short version) {
int major = (version & MAJOR_MASK) >> MAJOR_SHIFT;
int minor = (version & MINOR_MASK) >> MINOR_SHIFT;
int patch = (version & PATCH_MASK);
return major + "." + minor + "." + patch;
}
/**
* Serialization only looks at major and minor, not micro or below.
*/
public static String decodeVersionForSerialization(short version) {
int major = (version & MAJOR_MASK) >> MAJOR_SHIFT;
int minor = (version & MINOR_MASK) >> MINOR_SHIFT;
return major + "." + minor;
}
private static String[] getParts(String versionString) {
return versionString.split("[\\.\\-]");
}
public static String getMajorVersion() {
String[] parts = getParts(version);
return parts[0] + "." + parts[1];
}
}