From 9463178a2fe45ae4799c7caa8db2e849be7fd3e9 Mon Sep 17 00:00:00 2001 From: "Barry M. Caceres" Date: Sat, 11 Apr 2026 23:56:05 -0700 Subject: [PATCH] Changes pertaining to bootstrap builds and enforciong szBuildVersion.json is correct at build time --- .../sdk/core/GenerateTestJVMScript.java | 14 +- .../senzing/sdk/core/InstallUtilities.java | 188 ++++++++++-------- 2 files changed, 121 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/senzing/sdk/core/GenerateTestJVMScript.java b/src/main/java/com/senzing/sdk/core/GenerateTestJVMScript.java index 0af1806..454839a 100644 --- a/src/main/java/com/senzing/sdk/core/GenerateTestJVMScript.java +++ b/src/main/java/com/senzing/sdk/core/GenerateTestJVMScript.java @@ -58,9 +58,14 @@ public static void main(String[] args) } if ((senzingDirPath == null || senzingDirPath.trim().length() == 0) - && senzingPath != null && senzingPath.trim().length() > 0) { + && senzingPath != null && senzingPath.trim().length() > 0) + { File baseDir = new File(senzingPath); - File erDir = new File(baseDir, "er"); + + devBuild = ((baseDir.getName().equalsIgnoreCase("dist")) + && baseDir.getParentFile().getName().equalsIgnoreCase("build")); + + File erDir = devBuild ? baseDir : new File(baseDir, "er"); try { senzingDirPath = erDir.getCanonicalPath(); @@ -126,8 +131,11 @@ public static void main(String[] args) // normalize the senzing directory path if (senzingDir != null) { String dirName = senzingDir.getName(); + File parentDir = senzingDir.getParentFile(); if (senzingDir.exists() && senzingDir.isDirectory()) { - if (dirName.equalsIgnoreCase("dist")) { + if ((dirName.equalsIgnoreCase("dist")) + && parentDir.getName().equalsIgnoreCase("build")) + { senzingDirPath = senzingDir.toString(); senzingDir = null; devBuild = true; diff --git a/src/main/java/com/senzing/sdk/core/InstallUtilities.java b/src/main/java/com/senzing/sdk/core/InstallUtilities.java index eb9eeec..c6aef2a 100644 --- a/src/main/java/com/senzing/sdk/core/InstallUtilities.java +++ b/src/main/java/com/senzing/sdk/core/InstallUtilities.java @@ -266,6 +266,52 @@ static PrintStream getOut() { EXECUTABLE_PATH_ENV_VARIABLE = pathVar; } + + /** + * Parses the "VERSION" property from the + * specified text formatted as a JSON object. + * + * @param jsonText The JSON object text describing the version. + * @return The version value, or null if not found. + */ + static String parseVersionFromJson(String jsonText) { + String jsonKey = QUOTED_JSON_VERSION_KEY; + int index = jsonText.indexOf(jsonKey); + if (index < 0 || ((index + jsonKey.length()) >= jsonText.length())) + { + return null; + } + + index += jsonKey.length(); + + // eat whitespace + index = eatWhiteSpace(jsonText, index); + + // check for a colon + if (jsonText.charAt(index) != ':') { + return null; + } + index++; + + // eat whitespace again + index = eatWhiteSpace(jsonText, index); + + // check for a double-quote + if (jsonText.charAt(index) != '"') { + return null; + } + + // capture the content within the double quotes + int startIndex = index + 1; + int endIndex = jsonText.indexOf('"', startIndex); + if (endIndex < 0) { + return null; + } + + // return the version + return jsonText.substring(startIndex, endIndex).trim(); + } + /** * Gets the library path for the current operating system platform * as a {@link List} of {@link File} objects. @@ -465,17 +511,37 @@ static File findSenzingPathFromLib() { return null; } File erDir = libDir.getParentFile(); - if (erDir == null || !erDir.exists() || !erDir.getName().equalsIgnoreCase("er")) { - // unexpected location for "lib" directory -- it does not appear to - // be located within the Senzing installation + if (erDir == null || !erDir.exists()) { + // failed to find the "er" or "dist" directory return null; } + File senzingDir = erDir.getParentFile(); if (senzingDir == null || !senzingDir.exists()) { - // unexpected location for the "er" directory -- it does not appear - // to be located within the Senzing installation + // unexpected location for the "er" (or "dist") directory -- + // it does not appear to be located within the Senzing installation return null; } + + // get the name of the directory and convert to lower case + String erDirName = erDir.getName().toLowerCase(); + + if (erDirName.equals("dist") + && senzingDir.getName().equalsIgnoreCase("build")) + { + // in this case use the "dist" directory as the SENZING_PATH + return erDir; + } + + // if we get here then the er directory should be named "er" + if (!erDirName.equals("er")) { + // not the "dist" directory, but also not the "er" directory + // library found in unrecognized location + return null; + } + + // unexpected location for "lib" directory -- it does not appear to + // be located within the Senzing installation or build try { return senzingDir.getCanonicalFile(); } catch (Exception e) { @@ -494,6 +560,35 @@ static File findSenzingPathFromLib() { */ static final File RUNTIME_SENZING_PATH = inferSenzingPath(findRuntimeSdkJarFile()); + /** + * The Senzing version determined from the runtime native libraries. + */ + static final String RUNTIME_SENZING_VERSION; + + static { + String runtimeVersion = null; + NativeProduct product = null; + try { + product = new NativeProductJni(); + int returnCode = product.init("Get-Version", "{}", false); + if (returnCode == 0) { + String versionJson = product.getVersion(); + + runtimeVersion = parseVersionFromJson(versionJson); + } + + } catch (Exception | UnsatisfiedLinkError e) { + // force null in this case + runtimeVersion = null; + + } finally { + if (product != null) { + product.destroy(); + } + } + RUNTIME_SENZING_VERSION = runtimeVersion; + } + /** * Finds the Senzing build version JSON file. * @@ -506,7 +601,7 @@ static File findBuildVersionFile() { // declare the version file File versionFile = null; - + // check if we might be building the Senzing product if (SENZING_PATH.getName().equalsIgnoreCase("dist")) { versionFile = new File(SENZING_PATH, "szBuildVersion.json"); @@ -568,52 +663,19 @@ static String getInstallBuildVersion() { String fileContent = sb.toString(); - return parseVersionFromJson(fileContent); - } + String buildVersion = parseVersionFromJson(fileContent); - /** - * Parses the "VERSION" property from the - * specified text formatted as a JSON object. - * - * @param jsonText The JSON object text describing the version. - * @return The version value, or null if not found. - */ - static String parseVersionFromJson(String jsonText) { - String jsonKey = QUOTED_JSON_VERSION_KEY; - int index = jsonText.indexOf(jsonKey); - if (index < 0 || ((index + jsonKey.length()) >= jsonText.length())) + if (buildVersion != null && RUNTIME_SENZING_VERSION != null + && !buildVersion.equals(RUNTIME_SENZING_VERSION)) { - return null; - } - - index += jsonKey.length(); - - // eat whitespace - index = eatWhiteSpace(jsonText, index); - - // check for a colon - if (jsonText.charAt(index) != ':') { - return null; - } - index++; - - // eat whitespace again - index = eatWhiteSpace(jsonText, index); - - // check for a double-quote - if (jsonText.charAt(index) != '"') { - return null; - } - - // capture the content within the double quotes - int startIndex = index + 1; - int endIndex = jsonText.indexOf('"', startIndex); - if (endIndex < 0) { - return null; + throw new IllegalStateException( + "Version number from szBuildVersion.json (" + + buildVersion + ") does NOT match " + + "result from SzProduct.getVersion() (" + + RUNTIME_SENZING_VERSION + ")"); } - // return the version - return jsonText.substring(startIndex, endIndex).trim(); + return buildVersion; } /** @@ -1001,7 +1063,6 @@ static File findMaven() { */ static final String TARGET_JAR_MAVEN_VERSION = (RUNTIME_SENZING_PATH == null) ? INSTALL_JAR_MAVEN_VERSION : RUNTIME_JAR_MAVEN_VERSION; - /** * The Senzing library version that was recorded at build time. @@ -1064,35 +1125,6 @@ static File findSourcesJarFile() { return sourcesJarFile; } - /** - * The Senzing version determined from the runtime native libraries. - */ - static final String RUNTIME_SENZING_VERSION; - - static { - String runtimeVersion = null; - NativeProduct product = null; - try { - product = new NativeProductJni(); - int returnCode = product.init("Get-Version", "{}", false); - if (returnCode == 0) { - String versionJson = product.getVersion(); - - runtimeVersion = parseVersionFromJson(versionJson); - } - - } catch (Exception | UnsatisfiedLinkError e) { - // force null in this case - runtimeVersion = null; - - } finally { - if (product != null) { - product.destroy(); - } - } - RUNTIME_SENZING_VERSION = runtimeVersion; - } - /** * Validates the version of the runtime Senzing native library * versus the one that was recorded at build time.