Skip to content

Commit 00f2e16

Browse files
committed
Updated finding of default support path
1 parent e097e7e commit 00f2e16

File tree

2 files changed

+30
-190
lines changed

2 files changed

+30
-190
lines changed

csharp/runner/SnippetRunner/InstallLocations.cs

Lines changed: 17 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -188,46 +188,22 @@ private static bool IsDirectory(string path)
188188

189189
string defaultInstallPath;
190190
string? defaultConfigPath = null;
191-
192-
// check if we are building within the dev structure
193-
string[] directoryStructure = ["net8.0", "*", "bin", "Senzing.Sdk.Tests", "sz-sdk-csharp", "csharp", "g2", "apps", "dev"];
194-
DirectoryInfo? workingDir = new DirectoryInfo(Environment.CurrentDirectory);
195-
DirectoryInfo? previousDir = null;
196-
bool devStructure = true;
197-
foreach (var dirName in directoryStructure)
198-
{
199-
if (workingDir == null) break;
200-
if (!dirName.Equals("*", OrdinalIgnoreCase) && !workingDir.Name.Equals(dirName, OrdinalIgnoreCase))
201-
{
202-
devStructure = false;
203-
break;
204-
}
205-
previousDir = workingDir;
206-
workingDir = workingDir.Parent;
207-
}
208-
DirectoryInfo? devDistDir = (devStructure && previousDir != null)
209-
? new DirectoryInfo(Path.Combine(previousDir.FullName, "dist")) : null;
191+
string defaultSupportPath;
210192

211193
switch (Environment.OSVersion.Platform)
212194
{
213195
case PlatformID.Win32NT:
214-
defaultInstallPath = (devDistDir == null)
215-
? "C:\\Program Files\\Senzing\\er" : devDistDir.FullName;
196+
defaultInstallPath = "C:\\Program Files\\Senzing\\er";
197+
defaultSupportPath = "C:\\Program Files\\Senzing\\er\\data";
216198
break;
217199
case PlatformID.MacOSX:
218-
defaultInstallPath = (devDistDir == null)
219-
? "/opt/senzing/er" : devDistDir.FullName;
200+
defaultInstallPath = "/opt/senzing/er";
201+
defaultSupportPath = "/opt/senzing/er/data";
220202
break;
221203
case PlatformID.Unix:
222-
if (devDistDir == null)
223-
{
224-
defaultInstallPath = "/opt/senzing/er";
225-
defaultConfigPath = "/etc/opt/senzing";
226-
}
227-
else
228-
{
229-
defaultInstallPath = devDistDir.FullName;
230-
}
204+
defaultInstallPath = "/opt/senzing/er";
205+
defaultConfigPath = "/etc/opt/senzing";
206+
defaultSupportPath = "/opt/senzing/data";
231207
break;
232208
default:
233209
throw new NotSupportedException(
@@ -314,109 +290,19 @@ private static bool IsDirectory(string path)
314290
return null;
315291
}
316292

317-
if (supportPath == null || supportPath.Trim().Length == 0)
318-
{
319-
// try to determine the support path
320-
DirectoryInfo? installParent = installDir.Parent;
321-
DirectoryInfo? dataRoot = (installParent != null)
322-
? new DirectoryInfo(Path.Combine(installParent.FullName, "data"))
323-
: null;
324-
325-
if (dataRoot != null && dataRoot.Exists && IsDirectory(dataRoot.FullName))
326-
{
327-
DirectoryInfo? versionFile
328-
= new DirectoryInfo(
329-
Path.Combine(installDir.FullName, "szBuildVersion.json"));
330-
331-
string? dataVersion = null;
332-
if (versionFile != null && versionFile.Exists)
333-
{
334-
335-
String text = File.ReadAllText(versionFile.FullName, UTF8);
336-
JsonDocument jsonDoc = JsonDocument.Parse(text);
337-
JsonElement rootElem = jsonDoc.RootElement;
338-
JsonElement dataVerElem = rootElem.GetProperty("DATA_VERSION");
339-
dataVersion = dataVerElem.GetString();
340-
}
341-
342-
// try the data version directory
343-
supportDir = (dataVersion == null)
344-
? null
345-
: new DirectoryInfo(
346-
Path.Combine(dataRoot.FullName, dataVersion.Trim()));
347-
348-
// check if data version was not found
349-
if (supportDir == null || !supportDir.Exists)
350-
{
351-
Regex regex = new Regex("\\d+\\.\\d+\\.\\d+");
352-
// look to see if we only have one data version installed
353-
string[] dirs = Directory.GetDirectories(dataRoot.FullName);
354-
List<DirectoryInfo> versionDirs
355-
= new List<DirectoryInfo>();
356-
foreach (string dir in dirs)
357-
{
358-
DirectoryInfo versionDir = new DirectoryInfo(dir);
359-
if (!regex.IsMatch(versionDir.Name)) continue;
360-
versionDirs.Add(versionDir);
361-
}
362-
if (versionDirs.Count == 1 && supportDir == null)
363-
{
364-
// use the single data version found
365-
supportDir = versionDirs[0];
366-
}
367-
else if (versionDirs.Count > 1)
368-
{
369-
Console.Error.WriteLine(
370-
"Could not infer support directory. Multiple data "
371-
+ "directory versions at: ");
372-
Console.Error.WriteLine(" " + dataRoot);
373-
if (supportDir != null)
374-
{
375-
Console.Error.WriteLine();
376-
Console.Error.WriteLine("Expected to find: " + supportDir);
377-
}
378-
throw new InvalidOperationException(
379-
((supportDir == null)
380-
? "Could not infer support directory."
381-
: "Could not find support directory (" + supportDir + ").")
382-
+ " Multiple data directory versions found at: "
383-
+ dataRoot);
384-
}
385-
else
386-
{
387-
// no version directories were found, maybe the data root is
388-
// the actual support directory (mapped in a docker image)
389-
string[] files = Directory.GetFiles(dataRoot.FullName);
390-
List<FileInfo> ibmFiles = new List<FileInfo>();
391-
foreach (string file in files)
392-
{
393-
if (file.EndsWith(".ibm", OrdinalIgnoreCase))
394-
{
395-
ibmFiles.Add(new FileInfo(file));
396-
}
397-
}
398-
DirectoryInfo? libPostalDir = new DirectoryInfo(
399-
Path.Combine(dataRoot.FullName, "libpostal"));
400-
401-
// require the .ibm files and libpostal to exist
402-
if (ibmFiles.Count > 0 && libPostalDir.Exists)
403-
{
404-
supportDir = dataRoot;
405-
}
406-
}
407-
}
408-
409-
}
410-
if (supportDir == null)
411-
{
412-
// use the default path
293+
// check if an explicit support path has been specified
294+
if (supportPath == null || supportPath.Trim().Length == 0) {
295+
// check if using a dev build
296+
if ("dist".Equals(installDir.Name, OrdinalIgnoreCase)) {
297+
// use the "data" sub-directory of the dev build
413298
supportDir = new DirectoryInfo(
414299
Path.Combine(installDir.FullName, "data"));
300+
} else {
301+
// no explicit path, try the default support path
302+
supportDir = new DirectoryInfo(defaultSupportPath);
415303
}
416304

417-
}
418-
else
419-
{
305+
} else {
420306
// use the specified explicit path
421307
supportDir = new DirectoryInfo(supportPath);
422308
}

java/runner/java/com/senzing/runner/InstallLocations.java

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,18 @@ public static InstallLocations findLocations() {
165165
try {
166166
String defaultInstallPath;
167167
String defaultConfigPath = null;
168+
String defaultSupportPath = null;
168169

169170
if (windows) {
170-
defaultInstallPath = "C:\\\\Program Files\\Senzing\\er";
171+
defaultInstallPath = "C:\\Program Files\\Senzing\\er";
172+
defaultSupportPath = "C:\\Program Files\\Senzing\\er\\data";
171173
} else if (macOS) {
172174
defaultInstallPath = "/opt/senzing/er";
175+
defaultSupportPath = "/opt/senzing/er/data";
173176
} else {
174177
defaultInstallPath = "/opt/senzing/er";
175-
defaultConfigPath = "/etc/opt/senzing";
178+
defaultConfigPath = "/etc/opt/senzing";
179+
defaultSupportPath = "/opt/senzing/data";
176180
}
177181

178182
// set the install path if one has been provided
@@ -249,65 +253,15 @@ public static InstallLocations findLocations() {
249253
return null;
250254
}
251255

256+
// check if an explicit support path has been specified
252257
if (supportPath == null || supportPath.trim().length() == 0) {
253-
// try to determine the support path
254-
File installParent = installDir.getParentFile();
255-
File dataRoot = new File(installParent, "data");
256-
if (dataRoot.exists() && dataRoot.isDirectory()) {
257-
File versionFile = new File(installDir, "szBuildVersion.json");
258-
String dataVersion = null;
259-
if (versionFile.exists()) {
260-
String text = readTextFileAsString(versionFile, UTF_8);
261-
JsonObject jsonObject = parseJsonObject(text);
262-
dataVersion = (jsonObject.containsKey("DATA_VERSION")
263-
? jsonObject.getString("DATA_VERSION") : null);
264-
}
265-
266-
// try the data version directory
267-
supportDir = (dataVersion == null) ? null : new File(dataRoot, dataVersion.trim());
268-
269-
// check if data version was not found
270-
if (supportDir == null || !supportDir.exists()) {
271-
// look to see if we only have one data version installed
272-
File[] versionDirs = dataRoot.listFiles(f -> {
273-
return f.getName().matches("\\d+\\.\\d+\\.\\d+");
274-
});
275-
if (versionDirs.length == 1 && supportDir == null) {
276-
// use the single data version found
277-
supportDir = versionDirs[0];
278-
279-
} else if (versionDirs.length > 1) {
280-
System.err.println(
281-
"Could not infer support directory. Multiple data "
282-
+ "directory versions at: ");
283-
System.err.println(" " + dataRoot);
284-
if (supportDir != null) {
285-
System.err.println();
286-
System.err.println("Expected to find: " + supportDir);
287-
}
288-
throw new IllegalStateException(
289-
((supportDir == null) ? "Could not infer support directory."
290-
: "Could not find support directory (" + supportDir + ").")
291-
+ " Multiple data directory versions found at: " + dataRoot);
292-
} else {
293-
// no version directories were found, maybe the data root is
294-
// the actual support directory (mapped in a docker image)
295-
File[] ibmFiles = dataRoot.listFiles(f -> {
296-
return f.getName().toLowerCase().endsWith(".ibm");
297-
});
298-
File libPostalDir = new File(dataRoot, "libpostal");
299-
300-
// require the .ibm files and libpostal to exist
301-
if (ibmFiles.length > 0 && libPostalDir.exists()) {
302-
supportDir = dataRoot;
303-
}
304-
}
305-
}
306-
307-
}
308-
if (supportDir == null) {
309-
// use the default path
258+
// check if using a dev build
259+
if ("dist".equals(installDir.getName())) {
260+
// use the "data" sub-directory of the dev build
310261
supportDir = new File(installDir, "data");
262+
} else {
263+
// no explicit path, try the default support path
264+
supportDir = new File(defaultSupportPath);
311265
}
312266

313267
} else {

0 commit comments

Comments
 (0)