diff --git a/.github/workflows/csharp-darwin-snippets.yaml b/.github/workflows/csharp-darwin-snippets.yaml
index 5b0d0d3..7b9cfe0 100644
--- a/.github/workflows/csharp-darwin-snippets.yaml
+++ b/.github/workflows/csharp-darwin-snippets.yaml
@@ -31,10 +31,9 @@ jobs:
- name: configure environment
run: |
- SENZING_DIR="${HOME}/senzing/er"
+ SENZING_PATH="${HOME}/senzing"
{
- echo "SENZING_DIR=${SENZING_DIR}"
- echo "DYLD_LIBRARY_PATH=${SENZING_DIR}/lib"
+ echo "DYLD_LIBRARY_PATH=${SENZING_PATH}/er/lib"
} >> "$GITHUB_ENV"
- name: configure local nuget repo
diff --git a/.github/workflows/csharp-windows-snippets.yaml b/.github/workflows/csharp-windows-snippets.yaml
index 496e6fe..77ac591 100644
--- a/.github/workflows/csharp-windows-snippets.yaml
+++ b/.github/workflows/csharp-windows-snippets.yaml
@@ -41,10 +41,9 @@ jobs:
- name: Add to "Path" environment variable
run: |
- Add-Content $env:GITHUB_PATH "$Env:USERPROFILE\Senzing\er\lib"
+ Add-Content $env:GITHUB_PATH "$Env:USERPROFILE\senzing\er\lib"
- name: run csharp snippets
run: |
- $Env:SENZING_DIR = "$Env:USERPROFILE\Senzing\er"
cd ${Env:GITHUB_WORKSPACE}/csharp/runner
dotnet run --project SnippetRunner all
diff --git a/.github/workflows/java-darwin-snippets.yaml b/.github/workflows/java-darwin-snippets.yaml
index ea05fd5..c378b40 100644
--- a/.github/workflows/java-darwin-snippets.yaml
+++ b/.github/workflows/java-darwin-snippets.yaml
@@ -33,10 +33,10 @@ jobs:
- name: configure environment
run: |
- SENZING_DIR="${HOME}/senzing/er"
+ SENZING_PATH="${HOME}/senzing"
{
- echo "SENZING_DIR=${SENZING_DIR}"
- echo "DYLD_LIBRARY_PATH=${SENZING_DIR}/lib:${SENZING_DIR}/lib/macos"
+ echo "SENZING_PATH=${SENZING_PATH}"
+ echo "DYLD_LIBRARY_PATH=${SENZING_PATH}/er/lib:${SENZING_PATH}/er/lib/macos"
} >> "$GITHUB_ENV"
- name: build with Maven
diff --git a/.github/workflows/java-linux-snippets.yaml b/.github/workflows/java-linux-snippets.yaml
index a25cd50..594e314 100644
--- a/.github/workflows/java-linux-snippets.yaml
+++ b/.github/workflows/java-linux-snippets.yaml
@@ -39,7 +39,7 @@ jobs:
- name: build with Maven
env:
- SENZING_DIR: "/opt/senzing/er"
+ SENZING_PATH: "/opt/senzing"
run: |
cd "${GITHUB_WORKSPACE}"/java
mvn clean package
diff --git a/.github/workflows/java-windows-snippets.yaml b/.github/workflows/java-windows-snippets.yaml
index 20086d5..829e2a2 100644
--- a/.github/workflows/java-windows-snippets.yaml
+++ b/.github/workflows/java-windows-snippets.yaml
@@ -33,15 +33,15 @@ jobs:
- name: build with Maven
run: |
- $Env:SENZING_DIR = "$Env:USERPROFILE\Senzing\er"
+ $Env:SENZING_PATH = "$Env:USERPROFILE\senzing"
cd "${Env:GITHUB_WORKSPACE}/java"
mvn clean install
- name: Add to "Path" environment variable
run: |
- Add-Content $env:GITHUB_PATH "$Env:USERPROFILE\Senzing\er\lib"
+ Add-Content $env:GITHUB_PATH "$Env:USERPROFILE\senzing\er\lib"
- name: run java snippets
run: |
cd "${Env:GITHUB_WORKSPACE}/java"
- java "-Dsenzing.install.dir=$Env:USERPROFILE\Senzing\er" -jar target/sz-sdk-snippets.jar all
+ java -jar target/sz-sdk-snippets.jar all
diff --git a/csharp/README.md b/csharp/README.md
index 847cebe..b52c549 100644
--- a/csharp/README.md
+++ b/csharp/README.md
@@ -9,6 +9,29 @@ Before attempting to build the snippets you will need to make the make the
`Senzing.Sdk.[version].nupkg` file available to the `dotnet` executable so
it can be used as a dependency. This is done via these [instructions](https://github.com/senzing-garage/sz-sdk-csharp/blob/main/README.md#Usage).
+Further, you will need to set environment variables so the Senzing installation can be located:
+
+- Linux:
+
+ ```console
+ export SENZING_PATH=/opt/senzing/
+ export LD_LIBRARY_PATH=$SENZING_PATH/er/lib:$LD_LIBRARY_PATH
+ ```
+
+- macOS:
+
+ ```console
+ export SENZING_PATH=$HOME/senzing
+ export DYLD_LIBRARY_PATH=$SENZING_PATH/er/lib:$SENZING_PATH/er/lib/macos:$DYLD_LIBRARY_PATH
+ ```
+
+- Windows:
+
+ ```console
+ set SENZING_PATH=%USERPROFILE%\senzing
+ set Path=%SENZING_PATH%\er\lib;%Path%
+ ```
+
## Building
The C# snippets can built using the `dotnet build [project-name]` command under each directory. They can be run using `dotnet run --project [project-name]` command. Attempting to run a snippet will also trigger building it.
@@ -23,22 +46,21 @@ You may run any individual Snippet class directly providing you have a Senzing r
1. Run a snippet that takes no command-line arguments.
- ```[shell]
+ ```console
cd snippets
dotnet run --project loading/LoadRecords
```
2. Run a snippet and override the input file using command-line arguments
- ```[shell]
+ ```console
dotnet run --project loading/LoadRecordsViaLoop ../../resources/data/load-500-with-errors.jsonl
```
### Run via Runner
The `SnippetRunner` project will run one or more snippets for you and create a temporary Senzing repository to run then against. This can be executed using:
-
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner
```
@@ -47,42 +69,42 @@ The `SnippetRunner` project will run one or more snippets for you and create a t
1. Execute all code snippets:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner all
```
2. Execute all code snippets in a group:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner loading
```
3. Execute all code snippets from multiple groups:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner loading redo
```
4. Execute specific code snippets:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner loading.LoadViaLoop loading.LoadViaQueue
```
5. Mix and match packages with individual snippets:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner redo loading.LoadViaLoop
```
6. Generate a help message by specifying no arguments:
- ```[shell]
+ ```console
cd runner
dotnet run --project SnippetRunner
diff --git a/csharp/runner/SnippetRunner/InstallLocations.cs b/csharp/runner/SnippetRunner/InstallLocations.cs
index d02c802..e1ba735 100644
--- a/csharp/runner/SnippetRunner/InstallLocations.cs
+++ b/csharp/runner/SnippetRunner/InstallLocations.cs
@@ -10,11 +10,6 @@
///
public class InstallLocations
{
- ///
- /// UTF8 encoding constant.
- ///
- private static readonly Encoding UTF8 = new UTF8Encoding();
-
///
/// The installation location.
///
@@ -187,33 +182,46 @@ private static bool IsDirectory(string path)
DirectoryInfo homeInstall = new DirectoryInfo(
Path.Combine(homeSenzing.FullName, "er"));
DirectoryInfo homeSupport = new DirectoryInfo(
- Path.Combine(homeInstall.FullName, "data"));
+ Path.Combine(homeSenzing.FullName, "data"));
+ DirectoryInfo? senzingDir = null;
DirectoryInfo? installDir = null;
DirectoryInfo? configDir = null;
DirectoryInfo? resourceDir = null;
DirectoryInfo? supportDir = null;
DirectoryInfo? templatesDir = null;
+ string? defaultSenzingPath = null;
string defaultInstallPath;
string? defaultConfigPath = null;
- string defaultSupportPath;
+ string? defaultSupportPath = null;
+
+ // get the senzing path
+ string? senzingPath = Environment.GetEnvironmentVariable("SENZING_PATH");
+ if (senzingPath != null && senzingPath.Trim().Length == 0)
+ {
+ senzingPath = null;
+ }
+ // check if we are in the dev structure with no senzing path defined
if (OperatingSystem.IsWindows())
{
+ defaultSenzingPath = homeSenzing.FullName;
defaultInstallPath = homeInstall.FullName;
defaultSupportPath = homeSupport.FullName;
}
else if (OperatingSystem.IsMacOS())
{
+ defaultSenzingPath = homeSenzing.FullName;
defaultInstallPath = homeInstall.FullName;
defaultSupportPath = homeSupport.FullName;
}
else if (OperatingSystem.IsLinux())
{
- defaultInstallPath = "/opt/senzing/er";
+ defaultSenzingPath = "/opt/senzing";
+ defaultInstallPath = defaultSenzingPath + "/er";
+ defaultSupportPath = defaultSenzingPath + "/data";
defaultConfigPath = "/etc/opt/senzing";
- defaultSupportPath = "/opt/senzing/data";
}
else
{
@@ -222,13 +230,13 @@ private static bool IsDirectory(string path)
+ Environment.OSVersion.Platform);
}
- // check for senzing system properties
+ // check for senzing environment variables
string? installPath = Environment.GetEnvironmentVariable(
"SENZING_DIR");
string? configPath = Environment.GetEnvironmentVariable(
- "SENZING_ETC_DIR");
+ "SENZING_CONFIG_DIR");
string? supportPath = Environment.GetEnvironmentVariable(
- "SENZING_DATA_DIR");
+ "SENZING_SUPPORT_DIR");
string? resourcePath = Environment.GetEnvironmentVariable(
"SENZING_RESOURCE_DIR");
@@ -250,131 +258,211 @@ private static bool IsDirectory(string path)
resourcePath = null;
}
- // check the senzing directory
- installDir = new DirectoryInfo(
- installPath == null ? defaultInstallPath : installPath);
- if (!installDir.Exists)
+ // check for the root senzing directory
+ senzingDir = new DirectoryInfo(senzingPath == null ? defaultSenzingPath : senzingPath);
+ if (!senzingDir.Exists)
{
- Console.WriteLine("Could not find Senzing installation directory:");
- Console.WriteLine(" " + installDir);
- Console.WriteLine();
- if (installPath != null)
+ senzingDir = null;
+ }
+
+ // check the senzing install directory
+ installDir = (installPath != null)
+ ? new DirectoryInfo(installPath)
+ : ((senzingDir == null)
+ ? new DirectoryInfo(defaultInstallPath)
+ : ("dist".Equals(senzingDir.Name, OrdinalIgnoreCase)
+ ? senzingDir : new DirectoryInfo(Path.Combine(senzingDir.FullName, "er"))));
+
+ if (!installDir.Exists || !IsDirectory(installDir.FullName))
+ {
+ if (!installDir.Exists)
{
- Console.WriteLine(
- "Check the SENZING_DIR environment variable.");
+ Console.Error.WriteLine("Could not find Senzing ER installation directory:");
}
else
{
- Console.WriteLine(
- "Use the SENZING_DIR environment variable to specify a path");
+ Console.Error.WriteLine("Senzing ER installation directory appears invalid:");
}
-
- return null;
- }
-
- // normalize the senzing directory
- string installDirName = installDir.Name;
- if (installDir.Exists && IsDirectory(installDir.FullName)
- && !installDirName.Equals("er", OrdinalIgnoreCase)
- && installDirName.Equals("senzing", OrdinalIgnoreCase))
- {
- // for windows or linux allow the "Senzing" dir as well
- installDir = new DirectoryInfo(Path.Combine(installDir.FullName, "er"));
- }
-
- if (!IsDirectory(installDir.FullName))
- {
- Console.Error.WriteLine("Senzing installation directory appears invalid:");
- Console.Error.WriteLine(" " + installDir);
+ Console.Error.WriteLine(" " + installDir.FullName);
Console.Error.WriteLine();
if (installPath != null)
{
Console.Error.WriteLine(
- "Check the SENZING_DIR environment variable.");
+ "Check the SENZING_DIR environment variable.");
+
+ }
+ else if (senzingPath != null)
+ {
+ Console.Error.WriteLine(
+ "Check the SENZING_PATH environment variable.");
+
}
else
{
Console.Error.WriteLine(
- "Use the SENZING_DIR environment variable to specify a path");
+ "Use the SENZING_PATH environment variable to specify a "
+ + "base Senzing path.");
+ Console.Error.WriteLine();
+ Console.Error.WriteLine(
+ "Alternatively, use the SENZING_DIR environment variable to "
+ + "specify a Senzing ER path");
}
return null;
}
- // check if an explicit support path has been specified
- if (supportPath == null || supportPath.Trim().Length == 0)
+ // check the senzing support path
+ supportDir = (supportPath != null) ? new DirectoryInfo(supportPath) : null;
+
+ // check if support dir is not defined AND we have a local dev build
+ if (supportDir == null && installDir != null
+ && "dist".Equals(installDir.Name, OrdinalIgnoreCase))
{
- // check if using a dev build
- if ("dist".Equals(installDir.Name, OrdinalIgnoreCase))
+ supportDir = new DirectoryInfo(Path.Combine(installDir.FullName, "data"));
+ if (!supportDir.Exists)
{
- // use the "data" sub-directory of the dev build
- supportDir = new DirectoryInfo(
- Path.Combine(installDir.FullName, "data"));
+ supportDir = null;
}
- else
+ }
+
+ // check if support dir is not defined BUT senzing path is defined
+ if (supportDir == null && senzingPath != null && senzingDir != null)
+ {
+ supportDir = new DirectoryInfo(Path.Combine(senzingDir.FullName, "data"));
+ if (!supportDir.Exists)
{
- // no explicit path, try the default support path
- supportDir = new DirectoryInfo(defaultSupportPath);
+ supportDir = null;
}
-
}
- else
+
+ // fall back to whatever the default support directory path is
+ if (supportDir == null && defaultSupportPath != null)
{
- // use the specified explicit path
- supportDir = new DirectoryInfo(supportPath);
+ supportDir = new DirectoryInfo(defaultSupportPath);
}
- if (!supportDir.Exists)
+ // verify the discovered support directory
+ if ((supportDir != null)
+ && ((!supportDir.Exists) || (!IsDirectory(supportDir.FullName))))
{
- Console.Error.WriteLine("The support directory does not exist:");
- Console.Error.WriteLine(" " + supportDir);
+ if (!supportDir.Exists)
+ {
+ Console.Error.WriteLine("Could not find Senzing support directory:");
+ }
+ else
+ {
+ Console.Error.WriteLine("Senzing support directory appears invalid:");
+ }
+ Console.Error.WriteLine(" " + supportDir.FullName);
+ Console.Error.WriteLine();
if (supportPath != null)
{
Console.Error.WriteLine(
- "Check the SENZING_DATA_DIR environment variable.");
+ "Check the SENZING_SUPPORT_DIR environment variable.");
+
+ }
+ else if (senzingPath != null)
+ {
+ Console.Error.WriteLine(
+ "Check the SENZING_PATH environment variable.");
+
}
else
{
Console.Error.WriteLine(
- "Use the SENZING_DATA_DIR environment variable to specify a path");
+ "Use the SENZING_PATH environment variable to specify a "
+ + "base Senzing path.");
+ Console.Error.WriteLine();
+ Console.Error.WriteLine(
+ "Alternatively, use the SENZING_SUPPORT_DIR environment variable to "
+ + "specify a Senzing ER path.");
}
throw new InvalidOperationException(
- "The support directory does not exist: " + supportDir);
+ "The support directory does not exist or is invalid: " + supportDir.FullName);
}
- if (!IsDirectory(supportDir.FullName))
+ // now determine the resource path
+ resourceDir = (resourcePath != null) ? new DirectoryInfo(resourcePath) : null;
+
+ // try the "resources" sub-directory of the installation
+ if (resourceDir == null && installDir != null)
{
- Console.Error.WriteLine("The support directory is invalid:");
- Console.Error.WriteLine(" " + supportDir);
- if (supportPath != null)
+ resourceDir = new DirectoryInfo(Path.Combine(installDir.FullName, "resources"));
+ if (!resourceDir.Exists)
+ {
+ resourceDir = null;
+ }
+ }
+
+ // set the templates directory if we have the resource directory
+ if (resourceDir != null && resourceDir.Exists
+ && IsDirectory(resourceDir.FullName))
+ {
+ templatesDir = new DirectoryInfo(Path.Combine(resourceDir.FullName, "templates"));
+ }
+
+ // verify the discovered resource path
+ if ((resourceDir == null) || (!resourceDir.Exists)
+ || (!IsDirectory(resourceDir.FullName)))
+ {
+ if (resourceDir == null || !resourceDir.Exists)
+ {
+ Console.Error.WriteLine("Could not find Senzing resource directory:");
+ }
+ else
+ {
+ Console.Error.WriteLine("Senzing resource directory appears invalid:");
+ }
+ if (resourceDir != null) Console.Error.WriteLine(" " + resourceDir);
+
+ Console.Error.WriteLine();
+
+ if (resourcePath != null)
+ {
+ Console.Error.WriteLine(
+ "Check the SENZING_RESOURCE_DIR environment variable.");
+
+ }
+ else if (senzingPath != null)
{
Console.Error.WriteLine(
- "Check the SENZING_DATA_DIR environment variable.");
+ "Check the SENZING_PATH environment variable.");
+
+ }
+ else if (installPath != null)
+ {
+ Console.Error.WriteLine(
+ "Check the SENZING_DIR environment variable.");
+
}
else
{
Console.Error.WriteLine(
- "Use the SENZING_DATA_DIR environment variable to specify a path");
+ "Use the or SENZING_PATH environment variable to specify a "
+ + "valid base Senzing path.");
+ Console.Error.WriteLine();
+ Console.Error.WriteLine(
+ "Alternatively, use the SENZING_RESOURCE_DIR environment variable to "
+ + "specify a Senzing resource path.");
}
- throw new InvalidOperationException(
- "The support directory is invalid: " + supportDir);
+ throw new InvalidOperationException(
+ "The resource directory does not exist or is invalid: " + resourceDir?.FullName);
}
- // check the config path
- if (configPath != null)
- {
- configDir = new DirectoryInfo(configPath);
- }
- // check for a dev build installation
- if (configDir == null && installDir != null && "dist".Equals(installDir.Name, OrdinalIgnoreCase))
+ // check the senzing config path
+ configDir = (configPath != null) ? new DirectoryInfo(configPath) : null;
+
+ // check if config dir is not defined AND we have a local dev build
+ if (configDir == null && installDir != null && templatesDir != null
+ && "dist".Equals(installDir.Name, OrdinalIgnoreCase))
{
- configDir = new DirectoryInfo(Path.Combine(installDir.FullName, "data"));
+ configDir = templatesDir;
}
- // if still null and there is a default, then use it
+ // check if config dir is still not defined and fall back to default
if (configDir == null && defaultConfigPath != null)
{
configDir = new DirectoryInfo(defaultConfigPath);
@@ -387,112 +475,94 @@ private static bool IsDirectory(string path)
// if still null, try to use the install's etc directory
if (configDir == null && installDir != null)
{
- configDir = new DirectoryInfo(Path.Combine(installDir.FullName, "etc"));
+ configDir = new DirectoryInfo(
+ Path.Combine(installDir.FullName, "etc"));
if (!configDir.Exists)
{
configDir = null;
}
}
- if (configPath != null && configDir != null && !configDir.Exists)
- {
- Console.Error.WriteLine(
- "The SENZING_ETC_DIR environment variable specifies a path that does not exist:");
- Console.Error.WriteLine(
- " " + configPath);
+ // validate the contents of the config directory
+ List missingFiles = new List();
+ string missingFilesString = "";
- throw new InvalidOperationException(
- "Explicit config path does not exist: " + configPath);
- }
- if (configDir != null && configDir.Exists)
+ // check if the config directory does not exist
+ if (configDir != null && supportDir != null && configDir.Exists)
{
- if (!IsDirectory(configDir.FullName))
- {
- Console.Error.WriteLine(
- "The SENZING_ETC_DIR environment variable specifies a file, not a directory:");
- Console.Error.WriteLine(
- " " + configPath);
-
- throw new InvalidOperationException(
- "Explicit config path is not directory: " + configPath);
- }
-
String[] requiredFiles = ["cfgVariant.json"];
- List missingFiles = new List(requiredFiles.Length);
foreach (string fileName in requiredFiles)
{
- DirectoryInfo? configFile = new DirectoryInfo(
+ FileInfo? configFile = new FileInfo(
Path.Combine(configDir.FullName, fileName));
- DirectoryInfo? supportFile = new DirectoryInfo(
+ FileInfo? supportFile = new FileInfo(
Path.Combine(supportDir.FullName, fileName));
if (!configFile.Exists && !supportFile.Exists)
{
missingFiles.Add(fileName);
+ missingFilesString = (missingFilesString.Length == 0)
+ ? fileName : missingFiles + ", " + fileName;
}
}
- if (missingFiles.Count > 0 && configPath != null)
+ }
+
+ // verify the discovered config directory
+ if ((configDir == null) || (!configDir.Exists)
+ || (!IsDirectory(configDir.FullName)) || (missingFiles.Count > 0))
+ {
+ if (configDir == null || !configDir.Exists)
+ {
+ Console.Error.WriteLine("Could not find Senzing config directory:");
+ }
+ else
+ {
+ Console.Error.WriteLine("Senzing config directory appears invalid:");
+ }
+ if (configDir != null) Console.Error.WriteLine(" " + configDir);
+
+ if (missingFiles.Count > 0)
{
- Console.Error.WriteLine(
- "The SENZING_ETC_DIR environment variable specifies an invalid config directory:");
foreach (string missing in missingFiles)
{
Console.Error.WriteLine(
- " " + missing + " was not found");
+ " " + missing + " was not found in config directory");
}
- throw new InvalidOperationException(
- "Explicit config path missing required files: " + missingFiles);
}
- }
-
- // now determine the resource path
- resourceDir = (resourcePath == null) ? null : new DirectoryInfo(resourcePath);
- if (resourceDir == null && installDir != null)
- {
- resourceDir = new DirectoryInfo(
- Path.Combine(installDir.FullName, "resources"));
- if (!resourceDir.Exists) resourceDir = null;
- }
- if (resourceDir != null && resourceDir.Exists
- && IsDirectory(resourceDir.FullName))
- {
- templatesDir = new DirectoryInfo(
- Path.Combine(resourceDir.FullName, "templates"));
- }
-
- if (resourcePath != null)
- {
- if (resourceDir != null && !resourceDir.Exists)
+ Console.Error.WriteLine();
+ if (configPath != null)
{
Console.Error.WriteLine(
- "The SENZING_RESOURCE_DIR environment variable specifies a path that does not exist:");
- Console.Error.WriteLine(
- " " + resourcePath);
+ "Check the SENZING_CONFIG_DIR environment variable.");
- throw new InvalidOperationException(
- "Explicit resource path does not exist: " + resourcePath);
}
+ else if (senzingPath != null)
+ {
+ Console.Error.WriteLine(
+ "Check the SENZING_PATH environment variable.");
- if (resourceDir == null || !IsDirectory(resourceDir.FullName)
- || templatesDir == null || !templatesDir.Exists
- || !IsDirectory(templatesDir.FullName))
+ }
+ else if (installPath != null)
{
Console.Error.WriteLine(
- "The SENZING_RESOURCE_DIR environment variable specifies an invalid "
- + "resource directory:");
- Console.Error.WriteLine(" " + resourcePath);
+ "Check the SENZING_DIR environment variable.");
- throw new InvalidOperationException(
- "Explicit resource path is not valid: " + resourcePath);
+ }
+ else
+ {
+ Console.Error.WriteLine(
+ "Use the SENZING_PATH environment variable to specify a "
+ + "valid base Senzing path.");
+ Console.Error.WriteLine();
+ Console.Error.WriteLine(
+ "Alternatively, use the SENZING_CONFIG_DIR environment variable "
+ + "to specify a Senzing config path.");
}
- }
- else if (resourceDir == null || !resourceDir.Exists || !IsDirectory(resourceDir.FullName)
- || templatesDir == null || !templatesDir.Exists || !IsDirectory(templatesDir.FullName))
- {
- resourceDir = null;
- templatesDir = null;
+ throw new InvalidOperationException(
+ "The config directory does not exist or is invalid: " + configDir
+ + (missingFiles.Count == 0 ? "" : ", missingFiles=[ " + missingFilesString + " ]"));
}
// construct and initialize the result
diff --git a/java/README.md b/java/README.md
index f47b23e..3f8c9c1 100644
--- a/java/README.md
+++ b/java/README.md
@@ -2,30 +2,41 @@
The Java snippets are contained in the `snippets` directory under various Java package directories.
-## Building
+## Prerequisites
-The Java snippets can built using the `pom.xml` in this directory using `mvn package`. The result will be the `sz-sdk-snippets.jar` file in the `target` directory.
+FurYou will need to set environment variables so the Senzing installation can be located for building and for running the snippets:
-1. First, set the `SENZING_DIR` environment variable so the `pom.xml` can locate
-the `sz-sdk.jar`.
- - Linux/macOS:
+- Linux:
- ```console
- export SENZING_DIR=/opt/senzing/er
- ```
+ ```console
+ export SENZING_PATH=/opt/senzing/
+ export LD_LIBRARY_PATH=$SENZING_PATH/er/lib:$LD_LIBRARY_PATH
+ ```
- - Windows:
+- macOS:
- ```console
- set SENZING_DIR=C:\Program Files\Senzing\er
- ```
+ ```console
+ export SENZING_PATH=$HOME/senzing
+ export DYLD_LIBRARY_PATH=$SENZING_PATH/er/lib:$SENZING_PATH/er/lib/macos:$DYLD_LIBRARY_PATH
+ ```
-1. Run the maven build:
+- Windows:
```console
- mvn package
+ set SENZING_PATH=%USERPROFILE%\senzing
+ set Path=%SENZING_PATH%\er\lib;%Path%
```
+## Building
+
+The Java snippets can built using the `pom.xml` in this directory using `mvn package`. The result will be the `sz-sdk-snippets.jar` file in the `target` directory.
+
+Run the maven build via the following:
+
+```console
+mvn package
+```
+
## Running
There are several ways to run the code snippets.
@@ -51,6 +62,8 @@ You may run any individual Snippet class directly providing you have a Senzing r
The `com.senzing.runner.SnippetRunner` class will run one or more snippets for you and create a temporary Senzing repository to run
then against. This is the `Main-Class` of the `sz-sdk-snippets.jar` file so it can be executed using `java -jar target/sz-sdk-snippets.jar`.
+The runner will need to know the path to the Senzing installation. This is accomplished by setting the `SENZING_PATH` environment variable as documented above.
+
**NOTE:** When code snippets are run this way you cannot specify command-line arguments for individual snippets, nor can you respond to command-line input requests (they will be automatically be responded by the runner -- including forced termination of a snippet that is intended to run indefinitely).
1. Execute all code snippets:
diff --git a/java/pom.xml b/java/pom.xml
index 9c7c5a3..cbe517c 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -20,7 +20,7 @@
sz-sdk
4.0.0-beta.2.0
system
- ${SENZING_DIR}/sdk/java/sz-sdk.jar
+ ${SENZING_PATH}/er/sdk/java/sz-sdk.jar
org.glassfish
@@ -39,7 +39,7 @@
17
UTF-8
UTF-8
- ${SENZING_DIR}
+ ${SENZING_PATH}
snippets
@@ -89,7 +89,7 @@
false
- ${SENZING_DIR}/sdk/java/sz-sdk.jar
+ ${SENZING_PATH}/er/sdk/java/sz-sdk.jar
diff --git a/java/runner/java/com/senzing/runner/InstallLocations.java b/java/runner/java/com/senzing/runner/InstallLocations.java
index 1fa14a5..181ab66 100644
--- a/java/runner/java/com/senzing/runner/InstallLocations.java
+++ b/java/runner/java/com/senzing/runner/InstallLocations.java
@@ -3,9 +3,11 @@
import java.io.File;
import java.io.StringWriter;
import java.io.PrintWriter;
-import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
+import static com.senzing.runner.OperatingSystemFamily.RUNTIME_OS_FAMILY;
+
/**
* Describes the directories on disk used to find the Senzing product
* installation and the support directories.
@@ -101,8 +103,8 @@ public File getTemplatesDirectory() {
/**
* Checks if the installation is actually a development build.
*
- * @return true
if this installation represents a development
- * build, otherwise false
.
+ * @return true
if this installation represents a
+ * development build, otherwise false
.
*/
public boolean isDevelopmentBuild() {
return this.devBuild;
@@ -133,52 +135,60 @@ public String toString() {
* Finds the install directories and returns the {@link InstallLocations}
* instance describing those locations.
*
- * @param senzingDir The optional Senzing installation directory if one has been
- * provided, null
otherwise.
- *
* @return The {@link InstallLocations} instance describing the install
* locations.
*/
public static InstallLocations findLocations() {
- final String osName = System.getProperty("os.name");
-
- boolean windows = false;
- boolean macOS = false;
-
- String lowerOSName = osName.toLowerCase().trim();
- if (lowerOSName.startsWith("windows")) {
- windows = true;
- } else if (lowerOSName.startsWith("mac") || lowerOSName.indexOf("darwin") >= 0) {
- macOS = true;
- }
-
- File homeDir = new File(System.getProperty("user.home"));
- File homeSenzing = new File(homeDir, "senzing");
- File homeInstall = new File(homeSenzing, "er");
- File homeSupport = new File(homeInstall, "data");
- File installDir = null;
- File configDir = null;
- File resourceDir = null;
- File supportDir = null;
- File templatesDir = null;
+ File homeDir = new File(System.getProperty("user.home"));
+ File homeSenzing = new File(homeDir, "senzing");
+ File homeInstall = new File(homeSenzing, "er");
+ File homeSupport = new File(homeSenzing, "data");
+
+ File senzingDir = null;
+ File installDir = null;
+ File configDir = null;
+ File resourceDir = null;
+ File supportDir = null;
+ File templatesDir = null;
try {
+ String defaultSenzingPath = null;
String defaultInstallPath;
String defaultConfigPath = null;
String defaultSupportPath = null;
+
+ // get the senzing path
+ String senzingPath = System.getProperty("senzing.path");
+ if (senzingPath == null || senzingPath.trim().length() == 0) {
+ senzingPath = System.getenv("SENZING_PATH");
+ }
+ if (senzingPath != null && senzingPath.trim().length() == 0) {
+ senzingPath = null;
+ }
- if (windows) {
- defaultInstallPath = homeInstall.getCanonicalPath();
- defaultSupportPath = homeSupport.getCanonicalPath();
- } else if (macOS) {
- defaultInstallPath = homeInstall.getCanonicalPath();
- defaultSupportPath = homeSupport.getCanonicalPath();
- } else {
- defaultInstallPath = "/opt/senzing/er";
- defaultConfigPath = "/etc/opt/senzing";
- defaultSupportPath = "/opt/senzing/data";
+ // check if we are in the dev structure with no senzing path defined
+ switch (RUNTIME_OS_FAMILY) {
+ case WINDOWS:
+ defaultSenzingPath = homeSenzing.getCanonicalPath();
+ defaultInstallPath = homeInstall.getCanonicalPath();
+ defaultSupportPath = homeSupport.getCanonicalPath();
+ break;
+ case MAC_OS:
+ defaultSenzingPath = homeSenzing.getCanonicalPath();
+ defaultInstallPath = homeInstall.getCanonicalPath();
+ defaultSupportPath = homeSupport.getCanonicalPath();
+ break;
+ case UNIX:
+ defaultSenzingPath = "/opt/senzing";
+ defaultInstallPath = defaultSenzingPath + "/er";
+ defaultSupportPath = defaultSenzingPath + "/data";
+ defaultConfigPath = "/etc/opt/senzing";
+ break;
+ default:
+ throw new IllegalStateException(
+ "Unrecognized Operating System: " + RUNTIME_OS_FAMILY);
}
- // set the install path if one has been provided
+ // check for senzing system properties
String installPath = System.getProperty("senzing.install.dir");
String configPath = System.getProperty("senzing.config.dir");
String supportPath = System.getProperty("senzing.support.dir");
@@ -189,10 +199,13 @@ public static InstallLocations findLocations() {
installPath = System.getenv("SENZING_DIR");
}
if (configPath == null || configPath.trim().length() == 0) {
- configPath = System.getenv("SENZING_ETC_DIR");
+ configPath = System.getenv("SENZING_CONFIG_DIR");
}
if (supportPath == null || supportPath.trim().length() == 0) {
- supportPath = System.getenv("SENZING_DATA_DIR");
+ supportPath = System.getenv("SENZING_SUPPORT_DIR");
+ }
+ if (resourcePath == null || resourcePath.trim().length() == 0) {
+ resourcePath = System.getenv("SENZING_RESOURCE_DIR");
}
// normalize empty strings as null
@@ -209,98 +222,185 @@ public static InstallLocations findLocations() {
resourcePath = null;
}
- // check the senzing directory
- installDir = new File(installPath == null ? defaultInstallPath : installPath);
- if (!installDir.exists()) {
- System.err.println("Could not find Senzing installation directory:");
+ // check for the root senzing dir
+ senzingDir = new File((senzingPath == null) ? defaultSenzingPath : senzingPath);
+
+ if (!senzingDir.exists()) {
+ senzingDir = null;
+ }
+
+ // check the senzing install directory
+ installDir = (installPath != null)
+ ? new File(installPath)
+ : ((senzingDir == null)
+ ? new File(defaultInstallPath)
+ : (senzingDir.getName().equalsIgnoreCase("dist")
+ ? senzingDir : new File(senzingDir, "er")));
+
+ if ((!installDir.exists()) || (!installDir.isDirectory())) {
+ if (!installDir.exists()) {
+ System.err.println("Could not find Senzing ER installation directory:");
+ } else {
+ System.err.println("Senzing ER installation directory appears invalid:");
+ }
System.err.println(" " + installDir);
System.err.println();
if (installPath != null) {
- System.err.println("Check the -Dsenzing.install.dir=[path] command line option.");
+ System.err.println(
+ "Check the -Dsenzing.install.dir=[path] command line option "
+ + "or SENZING_DIR environment variable.");
+
+ } else if (senzingPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.path=[path] command line option "
+ + "or SENZING_PATH environment variable.");
+
} else {
- System.err
- .println("Use the -Dsenzing.install.dir=[path] command line option to " + "specify a path");
+ System.err.println(
+ "Use the -Dsenzing.path=[path] command line option or SENZING_PATH "
+ + "environment variable to specify a base Senzing path.");
+ System.err.println();
+ System.err.println(
+ "Alternatively, use the -Dsenzing.install.dir=[path] command line option "
+ + "or SENZING_DIR environment variable to specify a Senzing ER path");
}
return null;
}
- // normalize the senzing directory
- String dirName = installDir.getName();
- if (installDir.isDirectory() && !dirName.equalsIgnoreCase("er") && dirName.equalsIgnoreCase("senzing")) {
- // for windows or linux allow the "Senzing" dir as well
- installDir = new File(installDir, "er");
+
+ // check the senzing support path
+ supportDir = (supportPath != null) ? new File(supportPath) : null;
+
+ // check if support dir is not defined AND we have a local dev build
+ if (supportDir == null && installDir != null
+ && installDir.getName().equalsIgnoreCase("dist"))
+ {
+ supportDir = new File(installDir, "data");
+ if (!supportDir.exists()) {
+ supportDir = null;
+ }
}
- if (!installDir.isDirectory()) {
- System.err.println("Senzing installation directory appears invalid:");
- System.err.println(" " + installDir);
+ // check if support dir is not defined BUT senzing path is defined
+ if (supportDir == null && senzingPath != null && senzingDir != null)
+ {
+ supportDir = new File(senzingDir, "data");
+ if (!supportDir.exists()) {
+ supportDir = null;
+ }
+ }
+
+ // fall back to whatever the default support directory path is
+ if (supportDir == null)
+ {
+ supportDir = new File(defaultSupportPath);
+ }
+
+ // verify the discovered support directory
+ if ((!supportDir.exists()) || (!supportDir.isDirectory())) {
+ if (!supportDir.exists()) {
+ System.err.println("Could not find Senzing support directory:");
+ } else {
+ System.err.println("Senzing support directory appears invalid:");
+ }
+ System.err.println(" " + supportDir);
System.err.println();
- if (installPath != null) {
- System.err.println("Check the -Dsenzing.install.dir=[path] command line option.");
+ if (supportPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.support.dir=[path] command line option "
+ + "or SENZING_SUPPORT_DIR environment variable.");
+
+ } else if (senzingPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.path=[path] command line option "
+ + "or SENZING_PATH environment variable.");
+
} else {
- System.err
- .println("Use the -Dsenzing.install.dir=[path] command line option to " + "specify a path");
+ System.err.println(
+ "Use the -Dsenzing.path=[path] command line option or SENZING_PATH "
+ + "environment variable to specify a base Senzing path.");
+ System.err.println();
+ System.err.println(
+ "Alternatively, use the -Dsenzing.support.dir=[path] command line option or "
+ + "SENZING_SUPPORT_DIR environment variable to specify a Senzing ER path.");
}
- return null;
+ throw new IllegalStateException(
+ "The support directory does not exist or is invalid: " + supportDir);
}
- // check if an explicit support path has been specified
- if (supportPath == null || supportPath.trim().length() == 0) {
- // check if using a dev build
- if ("dist".equals(installDir.getName())) {
- // use the "data" sub-directory of the dev build
- supportDir = new File(installDir, "data");
- } else if (windows || macOS) {
- supportDir = new File(installDir, "data");
- } else {
- // no explicit path, try the default support path
- supportDir = new File(defaultSupportPath);
+ // now determine the resource path
+ resourceDir = (resourcePath != null) ? new File(resourcePath) : null;
+
+ // try the "resources" sub-directory of the installation
+ if (resourceDir == null && installDir != null) {
+ resourceDir = new File(installDir, "resources");
+ if (!resourceDir.exists()) {
+ resourceDir = null;
}
+ }
- } else {
- // use the specified explicit path
- supportDir = new File(supportPath);
+ // set the templates directory if we have the resource directory
+ if (resourceDir != null && resourceDir.exists()
+ && resourceDir.isDirectory())
+ {
+ templatesDir = new File(resourceDir, "templates");
}
- if (!supportDir.exists()) {
- System.err.println("The support directory does not exist:");
- System.err.println(" " + supportDir);
- if (supportPath != null) {
- System.err.println("Check the -Dsenzing.support.dir=[path] command line option.");
+ // verify the discovered resource path
+ if ((resourceDir == null) || (!resourceDir.exists())
+ || (!resourceDir.isDirectory()))
+ {
+ if (resourceDir == null || !resourceDir.exists()) {
+ System.err.println("Could not find Senzing resource directory:");
} else {
- System.err
- .println("Use the -Dsenzing.support.dir=[path] command line option to " + "specify a path");
+ System.err.println("Senzing resource directory appears invalid:");
}
+ if (resourceDir != null) System.err.println(" " + resourceDir);
+
+ System.err.println();
- throw new IllegalStateException("The support directory does not exist: " + supportDir);
- }
+ if (resourcePath != null) {
+ System.err.println(
+ "Check the -Dsenzing.resource.dir=[path] command line option "
+ + "or SENZING_RESOURCE_DIR environment variable.");
+
+ } else if (senzingPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.path=[path] command line option "
+ + "or SENZING_PATH environment variable.");
+
+ } else if (installPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.install.dir=[path] command line option "
+ + "or SENZING_DIR environment variable.");
- if (!supportDir.isDirectory()) {
- System.err.println("The support directory is invalid:");
- System.err.println(" " + supportDir);
- if (supportPath != null) {
- System.err.println("Check the -Dsenzing.support.dir=[path] command line option.");
} else {
- System.err
- .println("Use the -Dsenzing.support.dir=[path] command line option to " + "specify a path");
+ System.err.println(
+ "Use the -Dsenzing.path=[path] command line option or SENZING_PATH "
+ + "environment variable to specify a valid base Senzing path.");
+ System.err.println();
+ System.err.println(
+ "Alternatively, use the -Dsenzing.resource.dir=[path] command line option or "
+ + "SENZING_RESOURCE_DIR environment variable to specify a Senzing resource path.");
}
- throw new IllegalStateException("The support directory is invalid: " + supportDir);
+ throw new IllegalStateException(
+ "The resource directory does not exist or is invalid: " + resourceDir);
}
- // check the config path
- if (configPath != null) {
- configDir = new File(configPath);
- }
+ // check the senzing config path
+ configDir = (configPath != null) ? new File(configPath) : null;
- // check for a dev build installation
- if (configDir == null && installDir != null && "dist".equals(installDir.getName())) {
- configDir = new File(installDir, "data");
+ // check if config dir is not defined AND we have a local dev build
+ if (configDir == null && installDir != null && templatesDir != null
+ && installDir.getName().equalsIgnoreCase("dist"))
+ {
+ configDir = templatesDir;
}
- // if still null and there is a default, then use it
+ // check if config dir is still not defined and fall back to default
if (configDir == null && defaultConfigPath != null) {
configDir = new File(defaultConfigPath);
if (!configDir.exists()) {
@@ -313,25 +413,15 @@ public static InstallLocations findLocations() {
configDir = new File(installDir, "etc");
if (!configDir.exists()) {
configDir = null;
- }
+ }
}
- if (configPath != null && !configDir.exists()) {
- System.err.println("The -Dsenzing.config.dir=[path] option specifies a path that does not exist:");
- System.err.println(" " + configPath);
+ // validate the contents of the config directory
+ List missingFiles = new LinkedList<>();
- throw new IllegalStateException("Explicit config path does not exist: " + configPath);
- }
+ // check if the config directory does not exist
if (configDir != null && configDir.exists()) {
- if (!configDir.isDirectory()) {
- System.err.println("The -Dsenzing.config.dir=[path] option specifies a file, not a directory:");
- System.err.println(" " + configPath);
-
- throw new IllegalStateException("Explicit config path is not directory: " + configPath);
- }
-
String[] requiredFiles = { "cfgVariant.json" };
- List missingFiles = new ArrayList<>(requiredFiles.length);
for (String fileName : requiredFiles) {
File configFile = new File(configDir, fileName);
@@ -340,48 +430,55 @@ public static InstallLocations findLocations() {
missingFiles.add(fileName);
}
}
- if (missingFiles.size() > 0 && configPath != null) {
- System.err.println("The -Dsenzing.config.dir=[path] option specifies an invalid config directory:");
- for (String missing : missingFiles) {
- System.err.println(" " + missing + " was not found");
- }
- throw new IllegalStateException("Explicit config path missing required files: " + missingFiles);
- }
- }
-
- // now determine the resource path
- resourceDir = (resourcePath == null) ? null : new File(resourcePath);
- if (resourceDir == null) {
- resourceDir = new File(installDir, "resources");
- if (!resourceDir.exists())
- resourceDir = null;
}
- if (resourceDir != null && resourceDir.exists() && resourceDir.isDirectory()) {
- templatesDir = new File(resourceDir, "templates");
- }
-
- if (resourcePath != null) {
- if (!resourceDir.exists()) {
- System.err
- .println("The -Dsenzing.resource.dir=[path] option specifies a path that does not exist:");
- System.err.println(" " + resourcePath);
+ // verify the discovered config directory
+ if ((configDir == null) || (!configDir.exists())
+ || (!configDir.isDirectory()) || (missingFiles.size() > 0))
+ {
+ if (configDir == null || !configDir.exists()) {
+ System.err.println("Could not find Senzing config directory:");
+ } else {
+ System.err.println("Senzing config directory appears invalid:");
+ }
+ if (configDir != null) System.err.println(" " + configDir);
- throw new IllegalStateException("Explicit resource path does not exist: " + resourcePath);
+ if (missingFiles.size() > 0) {
+ for (String missing : missingFiles) {
+ System.err.println(
+ " " + missing + " was not found in config directory");
+ }
}
- if (!resourceDir.isDirectory() || !templatesDir.exists() || !templatesDir.isDirectory()) {
+ System.err.println();
+ if (configPath != null) {
System.err.println(
- "The -Dsenzing.resource.dir=[path] option specifies an invalid " + "resource directory:");
- System.err.println(" " + resourcePath);
+ "Check the -Dsenzing.config.dir=[path] command line option "
+ + "or SENZING_CONFIG_DIR environment variable.");
+
+ } else if (senzingPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.path=[path] command line option "
+ + "or SENZING_PATH environment variable.");
+
+ } else if (installPath != null) {
+ System.err.println(
+ "Check the -Dsenzing.install.dir=[path] command line option "
+ + "or SENZING_DIR environment variable.");
- throw new IllegalStateException("Explicit resource path is not valid: " + resourcePath);
+ } else {
+ System.err.println(
+ "Use the -Dsenzing.path=[path] command line option or SENZING_PATH "
+ + "environment variable to specify a valid base Senzing path.");
+ System.err.println();
+ System.err.println(
+ "Alternatively, use the -Dsenzing.config.dir=[path] command line option or "
+ + "SENZING_CONFIG_DIR environment variable to specify a Senzing config path.");
}
- } else if (!resourceDir.exists() || !resourceDir.isDirectory() || !templatesDir.exists()
- || !templatesDir.isDirectory()) {
- resourceDir = null;
- templatesDir = null;
+ throw new IllegalStateException(
+ "The config directory does not exist or is invalid: " + configDir
+ + (missingFiles.size() == 0 ? "" : ", missingFiles=[ " + missingFiles + " ]"));
}
// construct and initialize the result
diff --git a/java/runner/java/com/senzing/runner/OperatingSystemFamily.java b/java/runner/java/com/senzing/runner/OperatingSystemFamily.java
new file mode 100644
index 0000000..6e5acea
--- /dev/null
+++ b/java/runner/java/com/senzing/runner/OperatingSystemFamily.java
@@ -0,0 +1,77 @@
+package com.senzing.runner;
+
+/**
+ * Identifies the various types of operating systems.
+ */
+public enum OperatingSystemFamily {
+ /**
+ * Microsoft Windows operating systems.
+ */
+ WINDOWS,
+
+ /**
+ * Apple Macintosh operating systems.
+ */
+ MAC_OS,
+
+ /**
+ * Unix, Linux and Linux-like operating systems.
+ */
+ UNIX;
+
+ /**
+ * Check to see if this is {@link #WINDOWS}.
+ *
+ * @return true
if windows, otherwise false
.
+ */
+ public boolean isWindows() {
+ return (this == WINDOWS);
+ }
+
+ /**
+ * Check to see if this is {@link #MAC_OS}.
+ *
+ * @return true
if macOS, otherwise false
.
+ */
+ public boolean isMacOS() {
+ return (this == MAC_OS);
+ }
+
+ /**
+ * Check to see if this is {@link #UNIX}.
+ *
+ * @return true
if Unix, otherwise false
.
+ */
+ public boolean isUnix() {
+ return (this == UNIX);
+ }
+
+ /**
+ * The {@link OperatingSystemFamily} on which the process is currently
+ * executing.
+ */
+ public static final OperatingSystemFamily RUNTIME_OS_FAMILY;
+
+ static {
+ try {
+ OperatingSystemFamily osFamily = null;
+
+ final String osName = System.getProperty("os.name");
+ String lowerOSName = osName.toLowerCase().trim();
+ if (lowerOSName.startsWith("windows")) {
+ osFamily = WINDOWS;
+ } else if (lowerOSName.startsWith("mac")
+ || lowerOSName.indexOf("darwin") >= 0) {
+ osFamily = MAC_OS;
+ } else {
+ osFamily = UNIX;
+ }
+
+ RUNTIME_OS_FAMILY = osFamily;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+ }
+
\ No newline at end of file