Skip to content

Commit d13b38e

Browse files
committed
expose Engine.getVersion via EngineWrapper.getNuixVersionString and EngineWrapper.getNuixVersion
1 parent d36c63e commit d13b38e

3 files changed

Lines changed: 295 additions & 3 deletions

File tree

Java/src/main/java/com/nuix/javaenginesimple/EngineWrapper.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,28 @@ public void setLicenseFilter(LicenseFilter licenseFilter) {
495495
this.licenseFilter = licenseFilter;
496496
}
497497

498+
/***
499+
* Returns the Nuix engine version by internally calling Engine.getVersion
500+
* <br/>Note that if Engine instance has not yet been initialized this returns "0.0.0.0"
501+
* @return A String representing the Nuix Engine version or "0.0.0.0" if Engine has not yet been initialized.
502+
*/
503+
public String getNuixVersionString() {
504+
if(engine != null) {
505+
return engine.getVersion();
506+
} else {
507+
return "0.0.0.0";
508+
}
509+
}
510+
511+
/***
512+
* Gets a {@link NuixVersion} object representing the Engine version as obtained by calling Engine.getVersion
513+
* <br/>Note that if Engine instance has not yet been initialized this returns "0.0.0.0"
514+
* @return A NuixVersion object representing the Nuix Engine version or one representing "0.0.0.0" if Engine has not yet been initialized.
515+
*/
516+
public NuixVersion getNuixVersion() {
517+
return NuixVersion.parse(getNuixVersionString());
518+
}
519+
498520
@Override
499521
public void close() throws Exception {
500522
if(engine != null) {
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
package com.nuix.javaenginesimple;
2+
3+
import java.util.regex.Pattern;
4+
5+
/***
6+
* Assists in representing a Nuix version in object form to assist with comparing two versions. This allows for things such as
7+
* only executing chunks of code if the version meets a requirement.<br>
8+
* Ruby example:
9+
* <pre>
10+
* {@code
11+
* current_version = NuixVersion.new(NUIX_VERSION)
12+
* if current_version.isLessThan("7.8.0.10")
13+
* puts "Sorry your version of Nuix is below the minimum required version of 7.8.0.10"
14+
* exit 1
15+
* end
16+
* }
17+
* </pre>
18+
* @author Jason Wells
19+
*
20+
*/
21+
public class NuixVersion implements Comparable<NuixVersion> {
22+
private static Pattern previewVersionInfoRemovalPattern = Pattern.compile("[^0-9\\.].*$");
23+
24+
private int major = 0;
25+
private int minor = 0;
26+
private int bugfix = 0;
27+
private int build = 0;
28+
29+
/***
30+
* Creates a new instance defaulting to version 0.0.0
31+
*/
32+
public NuixVersion(){
33+
this(0,0,0,0);
34+
}
35+
36+
/***
37+
* Creates a new instance using the provided major version: major.0.0.0
38+
* @param majorVersion The major version number
39+
*/
40+
public NuixVersion(int majorVersion){
41+
this(majorVersion,0,0,0);
42+
}
43+
/***
44+
* Creates a new instance using the provided major and minor versions: major.minor.0.0
45+
* @param majorVersion The major version number
46+
* @param minorVersion The minor version number
47+
*/
48+
public NuixVersion(int majorVersion, int minorVersion){
49+
this(majorVersion,minorVersion,0,0);
50+
}
51+
/***
52+
* Creates a new instance using the provided major, minor and bugfix versions: major.minor.bugfix.0
53+
* @param majorVersion The major version number
54+
* @param minorVersion The minor version number
55+
* @param bugfixVersion The bugfix version number
56+
*/
57+
public NuixVersion(int majorVersion, int minorVersion, int bugfixVersion){
58+
this(majorVersion,minorVersion,bugfixVersion,0);
59+
}
60+
61+
/***
62+
* Creates a new instance using the provided major, minor, bugfix and build versions: major.minor.bugfix.build
63+
* @param majorVersion The major version number
64+
* @param minorVersion The minor version number
65+
* @param bugfixVersion The bugfix version number
66+
* @param buildVersion The build version number
67+
*/
68+
public NuixVersion(int majorVersion, int minorVersion, int bugfixVersion, int buildVersion){
69+
major = majorVersion;
70+
minor = minorVersion;
71+
bugfix = bugfixVersion;
72+
build = buildVersion;
73+
}
74+
75+
/***
76+
* Parses a version string into a NuixVersion instance. Supports values such as: 6, 6.2, 6.2.0, 6.2.1-preview6, 7.8.0.10 <br>
77+
* When providing a version string such as "6.2.1-preview6", "-preview6" will be trimmed off before parsing.
78+
* @param versionString The version string to parse.
79+
* @return A NuixVersion instance representing the supplied version string, if there is an error parsing the provided value will return
80+
* an instance representing 100.0.0
81+
*/
82+
public static NuixVersion parse(String versionString){
83+
try {
84+
String[] versionParts = NuixVersion.previewVersionInfoRemovalPattern.matcher(versionString.trim()).replaceAll("").split("\\.");
85+
int[] versionPartInts = new int[versionParts.length];
86+
for(int i=0;i<versionParts.length;i++){
87+
versionPartInts[i] = Integer.parseInt(versionParts[i]);
88+
}
89+
switch(versionParts.length){
90+
case 1:
91+
return new NuixVersion(versionPartInts[0]);
92+
case 2:
93+
return new NuixVersion(versionPartInts[0],versionPartInts[1]);
94+
case 3:
95+
return new NuixVersion(versionPartInts[0],versionPartInts[1],versionPartInts[2]);
96+
case 4:
97+
return new NuixVersion(versionPartInts[0],versionPartInts[1],versionPartInts[2],versionPartInts[3]);
98+
default:
99+
return new NuixVersion();
100+
}
101+
}catch(Exception exc){
102+
System.out.println("Error while parsing version: "+versionString);
103+
System.out.println("Pretending version is 100.0.0.0");
104+
return new NuixVersion(100,0,0,0);
105+
}
106+
}
107+
108+
/***
109+
* Gets the determined major portion of this version instance (X.0.0.0)
110+
* @return The determined major portion of version
111+
*/
112+
public int getMajor() {
113+
return major;
114+
}
115+
116+
/***
117+
* Sets the major portion of this version instance (X.0.0.0)
118+
* @param major The major version value
119+
*/
120+
public void setMajor(int major) {
121+
this.major = major;
122+
}
123+
124+
/***
125+
* Gets the determined minor portion of this version instance (0.X.0.0)
126+
* @return The determined minor portion of version
127+
*/
128+
public int getMinor() {
129+
return minor;
130+
}
131+
132+
/***
133+
* Sets the minor portion of this version instance (0.X.0.0)
134+
* @param minor The minor version value
135+
*/
136+
public void setMinor(int minor) {
137+
this.minor = minor;
138+
}
139+
140+
/***
141+
* Gets the determined bugfix portion of this version instance (0.0.x.0)
142+
* @return The determined bugfix portion of version
143+
*/
144+
public int getBugfix() {
145+
return bugfix;
146+
}
147+
148+
/***
149+
* Sets the determined bugfix portion of this version instance (0.0.x.0)
150+
* @param bugfix The determined bugfix portion of version
151+
*/
152+
public void setBugfix(int bugfix) {
153+
this.bugfix = bugfix;
154+
}
155+
156+
/***
157+
* Gets the determined build portion of this version instance (0.0.0.x)
158+
* @return The determined build portion of version
159+
*/
160+
public int getBuild() {
161+
return build;
162+
}
163+
164+
/***
165+
* Sets the build portion of this version instance (0.0.0.x)
166+
* @param build The build version value
167+
*/
168+
public void setBuild(int build) {
169+
this.build = build;
170+
}
171+
172+
/***
173+
* Determines whether another instance's version is less than this instance
174+
* @param other The other instance to compare against
175+
* @return True if the other instance is a lower version, false otherwise
176+
*/
177+
public boolean isLessThan(NuixVersion other){
178+
return this.compareTo(other) < 0;
179+
}
180+
/***
181+
* Determines whether another instance's version is greater than or equal to this instance
182+
* @param other The other instance to compare against
183+
* @return True if the other instance is greater than or equal to this instance, false otherwise
184+
*/
185+
public boolean isAtLeast(NuixVersion other){
186+
return this.compareTo(other) >= 0;
187+
}
188+
/***
189+
* Determines whether another instance's version is greater than this instance
190+
* @param other The other instance to compare against
191+
* @return True if the other instance is greater than this instance, false otherwise
192+
*/
193+
public boolean isGreaterThan(NuixVersion other){
194+
return this.compareTo(other) > 0;
195+
}
196+
/***
197+
* Determines whether another instance's version is greater than this instance
198+
* @param other The other instance to compare against
199+
* @return True if the other instance is greater than this instance, false otherwise
200+
*/
201+
public boolean isGreaterThan(String other){
202+
return this.compareTo(NuixVersion.parse(other)) > 0;
203+
}
204+
/***
205+
* Determines whether another instance's version is equal to this instance
206+
* @param other The other instance to compare against
207+
* @return True if the other instance is greater than this instance, false otherwise
208+
*/
209+
public boolean isEqualTo(NuixVersion other){
210+
return this.compareTo(other) == 0;
211+
}
212+
/***
213+
* Determines whether another instance's version is equal to this instance
214+
* @param other The other instance to compare against
215+
* @return True if the other instance is equal to this instance (major, minor and release are the same), false otherwise
216+
*/
217+
public boolean isEqualTo(String other){
218+
return this.compareTo(NuixVersion.parse(other)) == 0;
219+
}
220+
/***
221+
* Determines whether another instance's version is less than this instance
222+
* @param other A version string to compare against
223+
* @return True if the other instance is a lower version, false otherwise
224+
*/
225+
public boolean isLessThan(String other){
226+
return isLessThan(parse(other));
227+
}
228+
/***
229+
* Determines whether another instance's version is greater than or equal to this instance
230+
* @param other A version string to compare against
231+
* @return True if the other instance is greater than or equal to this instance, false otherwise
232+
*/
233+
public boolean isAtLeast(String other){
234+
return isAtLeast(parse(other));
235+
}
236+
237+
/***
238+
* Provides comparison logic when comparing two instances.
239+
*/
240+
@Override
241+
public int compareTo(NuixVersion other) {
242+
if(this.major == other.major){
243+
if(this.minor == other.minor){
244+
if(this.bugfix == other.bugfix) {
245+
return Integer.compare(this.build, other.build);
246+
} else {
247+
return Integer.compare(this.bugfix, other.bugfix);
248+
}
249+
} else{
250+
return Integer.compare(this.minor, other.minor);
251+
}
252+
} else{
253+
return Integer.compare(this.major, other.major);
254+
}
255+
256+
}
257+
258+
/***
259+
* Converts this instance back to a version string from its components, such as: "7.8.0.10"
260+
*/
261+
@Override
262+
public String toString(){
263+
return Integer.toString(this.major) + "." +
264+
Integer.toString(this.minor) + "." +
265+
Integer.toString(this.bugfix) + "." +
266+
Integer.toString(this.build);
267+
}
268+
}

README.MD

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Nuix Java Engine Baseline
22
=========================
33

4-
![Nuix Engine 8.8](https://img.shields.io/badge/Nuix%20Engine-8.8-green.svg)
4+
![Nuix Engine 9.0](https://img.shields.io/badge/Nuix%20Engine-9.0-green.svg)
55

66
View the GitHub project [here](https://github.com/Nuix/Nuix-Java-Engine-Baseline) or download the latest release [here](https://github.com/Nuix/Nuix-Java-Engine-Baseline/releases).
77

@@ -23,7 +23,9 @@ D:\engine-releases\9.0.1.325
2323
```
2424
- Have a Nuix license available on a Nuix license dongle, available from a Nuix Management Server instance or available from the Nuix Cloud License Server.
2525
- Download a copy of this repository and open the `Java` sub directory in your IDE of choice. Add the contents of the `lib` sub directory of your engine release to your project's build path.
26-
- Ensure that the Windows `PATH` environment variable references the `bin` sub directory of your engine release as well as the `bin\x86` directory. For example if I have my engine distribution located at `D:\engine-releases\9.0.1.325`, I will want to add the following to my `PATH`: `D:\engine-releases\9.0.1.325\bin` and `D:\engine-releases\9.0.1.325\bin\x86`.
26+
- Ensure that the Windows `PATH` environment variable references the `bin` sub directory of your engine release as well as the `bin\x86` directory. For example if I have my engine distribution located at `D:\engine-releases\9.0.1.325`, I will want to add the following to my `PATH`:
27+
- `D:\engine-releases\9.0.1.325\bin`
28+
- `D:\engine-releases\9.0.1.325\bin\x86`
2729
- Build your project and export a JAR file.
2830

2931
The package `com.nuix.javaenginebaseline.examples` contains a series of examples demonstrating fundamental activities. Each example is executable (they have a static void main method). For example, to run the example [BasicInitializationExample]:
@@ -252,7 +254,7 @@ public static void main(String[] args) throws Exception {
252254
# License
253255

254256
```
255-
Copyright 2020 Nuix
257+
Copyright 2021 Nuix
256258
257259
Licensed under the Apache License, Version 2.0 (the "License");
258260
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)