Skip to content

Commit 586f520

Browse files
committed
added system property telling checkPreConditions to ignore issues
When -Dengine.ignore.preCheckIssues=true, code in checkPreConditions that previously would have thrown an exception due to configuration issues, now will not throw exceptions. This was added purely for testing purposes in which one may wish to attempt to reproduce an error condition.
1 parent 2d1de18 commit 586f520

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

IntelliJ/src/main/java/com/nuix/innovation/enginewrapper/NuixEngine.java

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ private boolean obtainLicenseFromResolvers() throws Exception {
378378
* </ul>
379379
*/
380380
private void checkPreConditions() throws Exception {
381+
// This is for testing!
382+
boolean ignoreIssues = false;
383+
if (System.getProperty("engine.ignore.preCheckIssues").equalsIgnoreCase("true")) {
384+
ignoreIssues = true;
385+
System.out.println("engine.ignore.preCheckIssues = true, ignoring errors found during pre-check!");
386+
}
387+
381388
// Due to changes in later versions of Java coupled with some added functionality
382389
// added to Nuix at one point, we need to make sure the JVM we are running in
383390
// was started with this arg:
@@ -388,14 +395,18 @@ private void checkPreConditions() throws Exception {
388395
List<String> jvmArgs = bean.getInputArguments();
389396
final String requiredJvmArg = "--add-exports=java.base/jdk.internal.loader=ALL-UNNAMED";
390397
if (jvmArgs.stream().noneMatch(arg -> arg.trim().equalsIgnoreCase(requiredJvmArg))) {
391-
throw new IllegalStateException("Please ensure that JVM is started with argument: " + requiredJvmArg);
398+
if (!ignoreIssues) {
399+
throw new IllegalStateException("Please ensure that JVM is started with argument: " + requiredJvmArg);
400+
}
392401
}
393402

394403
// Caller must have set engine distribution directory, fail if they have not.
395404
if (engineDistributionDirectorySupplier == null) {
396-
throw new IllegalStateException("Unable to resolve engine distribution directory, please call one of the following methods " +
397-
"before calling the run method: " +
398-
"setEngineDistributionDirectorySupplier, setEngineDistributionDirectory, setEngineDistributionDirectoryFromENV");
405+
if (!ignoreIssues) {
406+
throw new IllegalStateException("Unable to resolve engine distribution directory, please call one of the following methods " +
407+
"before calling the run method: " +
408+
"setEngineDistributionDirectorySupplier, setEngineDistributionDirectory, setEngineDistributionDirectoryFromENV");
409+
}
399410
}
400411

401412
// We need to set JVM system property 'nuix.libdir' so engine can resolve some things early on.
@@ -412,16 +423,20 @@ private void checkPreConditions() throws Exception {
412423
System.out.println("No log directory specified, assuming local app data log directory: " + logDirectory.getAbsolutePath());
413424
setLogDirectory(logDirectory);
414425
} else {
415-
throw new IllegalStateException("Unable to resolve log directory, please call either " +
416-
"setLogDirectorySupplier or setLogDirectory method before calling run method");
426+
if (!ignoreIssues) {
427+
throw new IllegalStateException("Unable to resolve log directory, please call either " +
428+
"setLogDirectorySupplier or setLogDirectory method before calling run method");
429+
}
417430
}
418431
}
419432

420433
// If we reached here, we should have been able to resolve a log directory. Let's make sure that directory
421434
// exists so later during logging initialization we don't receive an exception about non-existent directory.
422435
logDirectorySupplier.get().getCanonicalFile().mkdirs();
423436
if (!logDirectorySupplier.get().getCanonicalFile().exists()) {
424-
throw new IOException("Unable to create log directory: " + logDirectorySupplier.get().getCanonicalPath());
437+
if (!ignoreIssues) {
438+
throw new IOException("Unable to create log directory: " + logDirectorySupplier.get().getCanonicalPath());
439+
}
425440
}
426441

427442
// If caller has not specified a user-data directory, assume the one that comes with the engine distribution
@@ -433,22 +448,34 @@ private void checkPreConditions() throws Exception {
433448
}
434449

435450
// Make sure PATH points to expected bin and bin/x86 subdirectories of our engine distribution
436-
String[] pathDirs = System.getenv("PATH").split(";");
437-
File expectedBinDir = new File(engineDistributionDirectorySupplier.get(), "bin");
438-
File expectedBinX86Dir = new File(expectedBinDir, "x86");
451+
String envPath = System.getenv("PATH");
439452

440-
// Make sure we can locate 'bin' subdirectory on PATH
441-
if (Arrays.stream(pathDirs).noneMatch(pathDir -> pathDir.equalsIgnoreCase(expectedBinDir.getAbsolutePath()))) {
442-
throw new IllegalStateException("PATH does not contain expected 'bin' directory: " + expectedBinDir.getAbsolutePath());
453+
if (envPath == null || envPath.isBlank()) {
454+
if (!ignoreIssues) {
455+
throw new IllegalStateException("PATH is null or blank. Needs to at least reference engine directories `bin` and `bin/x86`");
456+
}
443457
} else {
444-
System.out.println("'bin' Successfully found on PATH: " + expectedBinDir.getAbsolutePath());
445-
}
458+
String[] pathDirs = envPath.split(";");
459+
File expectedBinDir = new File(engineDistributionDirectorySupplier.get(), "bin");
460+
File expectedBinX86Dir = new File(expectedBinDir, "x86");
461+
462+
// Make sure we can locate 'bin' subdirectory on PATH
463+
if (Arrays.stream(pathDirs).noneMatch(pathDir -> pathDir.equalsIgnoreCase(expectedBinDir.getAbsolutePath()))) {
464+
if (!ignoreIssues) {
465+
throw new IllegalStateException("PATH does not contain expected 'bin' directory: " + expectedBinDir.getAbsolutePath());
466+
}
467+
} else {
468+
System.out.println("'bin' Successfully found on PATH: " + expectedBinDir.getAbsolutePath());
469+
}
446470

447-
// Make sure we can locate 'bin\x86' subdirectory on PATH
448-
if (Arrays.stream(pathDirs).noneMatch(pathDir -> pathDir.equalsIgnoreCase(expectedBinX86Dir.getAbsolutePath()))) {
449-
throw new IllegalStateException("PATH does not contain expected 'bin\\x86' directory: " + expectedBinX86Dir.getAbsolutePath());
450-
} else {
451-
System.out.println("'bin\\x86' Successfully found on PATH: " + expectedBinX86Dir.getAbsolutePath());
471+
// Make sure we can locate 'bin\x86' subdirectory on PATH
472+
if (Arrays.stream(pathDirs).noneMatch(pathDir -> pathDir.equalsIgnoreCase(expectedBinX86Dir.getAbsolutePath()))) {
473+
if (!ignoreIssues) {
474+
throw new IllegalStateException("PATH does not contain expected 'bin\\x86' directory: " + expectedBinX86Dir.getAbsolutePath());
475+
}
476+
} else {
477+
System.out.println("'bin\\x86' Successfully found on PATH: " + expectedBinX86Dir.getAbsolutePath());
478+
}
452479
}
453480
}
454481

0 commit comments

Comments
 (0)