Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/java/com/senzing/sdk/core/GenerateTestJVMScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
188 changes: 110 additions & 78 deletions src/main/java/com/senzing/sdk/core/InstallUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,52 @@ static PrintStream getOut() {

EXECUTABLE_PATH_ENV_VARIABLE = pathVar;
}

/**
* Parses the <code>"VERSION"</code> property from the
* specified text formatted as a JSON object.
*
* @param jsonText The JSON object text describing the version.
* @return The version value, or <code>null</code> 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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
*
Expand All @@ -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");
Expand Down Expand Up @@ -568,52 +663,19 @@ static String getInstallBuildVersion() {

String fileContent = sb.toString();

return parseVersionFromJson(fileContent);
}
String buildVersion = parseVersionFromJson(fileContent);

/**
* Parses the <code>"VERSION"</code> property from the
* specified text formatted as a JSON object.
*
* @param jsonText The JSON object text describing the version.
* @return The version value, or <code>null</code> 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;
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading