Skip to content

Commit e620f45

Browse files
committed
Updated finding of default paths
1 parent 981b38c commit e620f45

File tree

2 files changed

+48
-51
lines changed

2 files changed

+48
-51
lines changed

csharp/runner/SnippetRunner/InstallLocations.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ private static bool IsDirectory(string path)
180180
/// </summary>
181181
public static InstallLocations? FindLocations()
182182
{
183+
DirectoryInfo homeDir = new DirectoryInfo(Environment.GetFolderPath(
184+
Environment.SpecialFolder.UserProfile));
185+
DirectoryInfo homeSenzing = new DirectoryInfo(
186+
Path.Combine(homeDir.FullName, "senzing"));
187+
DirectoryInfo homeInstall = new DirectoryInfo(
188+
Path.Combine(homeSenzing.FullName, "er"));
189+
DirectoryInfo homeSupport = new DirectoryInfo(
190+
Path.Combine(homeInstall.FullName, "data"));
191+
183192
DirectoryInfo? installDir = null;
184193
DirectoryInfo? configDir = null;
185194
DirectoryInfo? resourceDir = null;
@@ -193,12 +202,12 @@ private static bool IsDirectory(string path)
193202
switch (Environment.OSVersion.Platform)
194203
{
195204
case PlatformID.Win32NT:
196-
defaultInstallPath = "C:\\Program Files\\Senzing\\er";
197-
defaultSupportPath = "C:\\Program Files\\Senzing\\er\\data";
205+
defaultInstallPath = homeInstall.FullName;
206+
defaultSupportPath = homeSupport.FullName;
198207
break;
199208
case PlatformID.MacOSX:
200-
defaultInstallPath = "/opt/senzing/er";
201-
defaultSupportPath = "/opt/senzing/er/data";
209+
defaultInstallPath = homeInstall.FullName;
210+
defaultSupportPath = homeSupport.FullName;
202211
break;
203212
case PlatformID.Unix:
204213
defaultInstallPath = "/opt/senzing/er";

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

+35-47
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public String toString() {
133133
* Finds the install directories and returns the {@link InstallLocations}
134134
* instance describing those locations.
135135
*
136-
* @param senzingDir The optional Senzing installation directory if one has
137-
* been provided, <code>null</code> otherwise.
136+
* @param senzingDir The optional Senzing installation directory if one has been
137+
* provided, <code>null</code> otherwise.
138138
*
139139
* @return The {@link InstallLocations} instance describing the install
140140
* locations.
@@ -148,12 +148,14 @@ public static InstallLocations findLocations() {
148148
String lowerOSName = osName.toLowerCase().trim();
149149
if (lowerOSName.startsWith("windows")) {
150150
windows = true;
151-
} else if (lowerOSName.startsWith("mac")
152-
|| lowerOSName.indexOf("darwin") >= 0)
153-
{
151+
} else if (lowerOSName.startsWith("mac") || lowerOSName.indexOf("darwin") >= 0) {
154152
macOS = true;
155153
}
156154

155+
File homeDir = new File(System.getProperty("user.home"));
156+
File homeSenzing = new File(homeDir, "senzing");
157+
File homeInstall = new File(homeSenzing, "er");
158+
File homeSupport = new File(homeInstall, "data");
157159
File installDir = null;
158160
File configDir = null;
159161
File resourceDir = null;
@@ -165,14 +167,14 @@ public static InstallLocations findLocations() {
165167
String defaultSupportPath = null;
166168

167169
if (windows) {
168-
defaultInstallPath = "C:\\Program Files\\Senzing\\er";
169-
defaultSupportPath = "C:\\Program Files\\Senzing\\er\\data";
170+
defaultInstallPath = homeInstall.getCanonicalPath();
171+
defaultSupportPath = homeSupport.getCanonicalPath();
170172
} else if (macOS) {
171-
defaultInstallPath = "/opt/senzing/er";
172-
defaultSupportPath = "/opt/senzing/er/data";
173+
defaultInstallPath = homeInstall.getCanonicalPath();
174+
defaultSupportPath = homeSupport.getCanonicalPath();
173175
} else {
174176
defaultInstallPath = "/opt/senzing/er";
175-
defaultConfigPath = "/etc/opt/senzing";
177+
defaultConfigPath = "/etc/opt/senzing";
176178
defaultSupportPath = "/opt/senzing/data";
177179
}
178180

@@ -214,22 +216,18 @@ public static InstallLocations findLocations() {
214216
System.err.println(" " + installDir);
215217
System.err.println();
216218
if (installPath != null) {
217-
System.err.println(
218-
"Check the -Dsenzing.install.dir=[path] command line option.");
219+
System.err.println("Check the -Dsenzing.install.dir=[path] command line option.");
219220
} else {
220-
System.err.println(
221-
"Use the -Dsenzing.install.dir=[path] command line option to "
222-
+ "specify a path");
221+
System.err
222+
.println("Use the -Dsenzing.install.dir=[path] command line option to " + "specify a path");
223223
}
224224

225225
return null;
226226
}
227227

228228
// normalize the senzing directory
229229
String dirName = installDir.getName();
230-
if (installDir.isDirectory() && !dirName.equalsIgnoreCase("er")
231-
&& dirName.equalsIgnoreCase("senzing"))
232-
{
230+
if (installDir.isDirectory() && !dirName.equalsIgnoreCase("er") && dirName.equalsIgnoreCase("senzing")) {
233231
// for windows or linux allow the "Senzing" dir as well
234232
installDir = new File(installDir, "er");
235233
}
@@ -239,12 +237,10 @@ public static InstallLocations findLocations() {
239237
System.err.println(" " + installDir);
240238
System.err.println();
241239
if (installPath != null) {
242-
System.err.println(
243-
"Check the -Dsenzing.install.dir=[path] command line option.");
240+
System.err.println("Check the -Dsenzing.install.dir=[path] command line option.");
244241
} else {
245-
System.err.println(
246-
"Use the -Dsenzing.install.dir=[path] command line option to "
247-
+ "specify a path");
242+
System.err
243+
.println("Use the -Dsenzing.install.dir=[path] command line option to " + "specify a path");
248244
}
249245

250246
return null;
@@ -260,7 +256,7 @@ public static InstallLocations findLocations() {
260256
supportDir = new File(installDir, "data");
261257
} else {
262258
// no explicit path, try the default support path
263-
supportDir = new File(defaultSupportPath);
259+
supportDir = new File(defaultSupportPath);
264260
}
265261

266262
} else {
@@ -274,8 +270,8 @@ public static InstallLocations findLocations() {
274270
if (supportPath != null) {
275271
System.err.println("Check the -Dsenzing.support.dir=[path] command line option.");
276272
} else {
277-
System.err.println("Use the -Dsenzing.support.dir=[path] command line option to "
278-
+ "specify a path");
273+
System.err
274+
.println("Use the -Dsenzing.support.dir=[path] command line option to " + "specify a path");
279275
}
280276

281277
throw new IllegalStateException("The support directory does not exist: " + supportDir);
@@ -287,8 +283,8 @@ public static InstallLocations findLocations() {
287283
if (supportPath != null) {
288284
System.err.println("Check the -Dsenzing.support.dir=[path] command line option.");
289285
} else {
290-
System.err.println("Use the -Dsenzing.support.dir=[path] command line option to "
291-
+ "specify a path");
286+
System.err
287+
.println("Use the -Dsenzing.support.dir=[path] command line option to " + "specify a path");
292288
}
293289
throw new IllegalStateException("The support directory is invalid: " + supportDir);
294290

@@ -317,24 +313,21 @@ public static InstallLocations findLocations() {
317313
configDir = new File(installDir, "etc");
318314
if (!configDir.exists()) {
319315
configDir = null;
320-
}
316+
}
321317
}
322318

323319
if (configPath != null && !configDir.exists()) {
324-
System.err.println(
325-
"The -Dsenzing.config.dir=[path] option specifies a path that does not exist:");
320+
System.err.println("The -Dsenzing.config.dir=[path] option specifies a path that does not exist:");
326321
System.err.println(" " + configPath);
327322

328323
throw new IllegalStateException("Explicit config path does not exist: " + configPath);
329324
}
330325
if (configDir != null && configDir.exists()) {
331326
if (!configDir.isDirectory()) {
332-
System.err.println(
333-
"The -Dsenzing.config.dir=[path] option specifies a file, not a directory:");
327+
System.err.println("The -Dsenzing.config.dir=[path] option specifies a file, not a directory:");
334328
System.err.println(" " + configPath);
335329

336-
throw new IllegalStateException(
337-
"Explicit config path is not directory: " + configPath);
330+
throw new IllegalStateException("Explicit config path is not directory: " + configPath);
338331
}
339332

340333
String[] requiredFiles = { "cfgVariant.json" };
@@ -348,13 +341,11 @@ public static InstallLocations findLocations() {
348341
}
349342
}
350343
if (missingFiles.size() > 0 && configPath != null) {
351-
System.err.println(
352-
"The -Dsenzing.config.dir=[path] option specifies an invalid config directory:");
344+
System.err.println("The -Dsenzing.config.dir=[path] option specifies an invalid config directory:");
353345
for (String missing : missingFiles) {
354346
System.err.println(" " + missing + " was not found");
355347
}
356-
throw new IllegalStateException(
357-
"Explicit config path missing required files: " + missingFiles);
348+
throw new IllegalStateException("Explicit config path missing required files: " + missingFiles);
358349
}
359350
}
360351

@@ -372,22 +363,19 @@ public static InstallLocations findLocations() {
372363

373364
if (resourcePath != null) {
374365
if (!resourceDir.exists()) {
375-
System.err.println(
376-
"The -Dsenzing.resource.dir=[path] option specifies a path that does not exist:");
366+
System.err
367+
.println("The -Dsenzing.resource.dir=[path] option specifies a path that does not exist:");
377368
System.err.println(" " + resourcePath);
378369

379-
throw new IllegalStateException(
380-
"Explicit resource path does not exist: " + resourcePath);
370+
throw new IllegalStateException("Explicit resource path does not exist: " + resourcePath);
381371
}
382372

383373
if (!resourceDir.isDirectory() || !templatesDir.exists() || !templatesDir.isDirectory()) {
384374
System.err.println(
385-
"The -Dsenzing.resource.dir=[path] option specifies an invalid "
386-
+ "resource directory:");
375+
"The -Dsenzing.resource.dir=[path] option specifies an invalid " + "resource directory:");
387376
System.err.println(" " + resourcePath);
388377

389-
throw new IllegalStateException(
390-
"Explicit resource path is not valid: " + resourcePath);
378+
throw new IllegalStateException("Explicit resource path is not valid: " + resourcePath);
391379
}
392380

393381
} else if (!resourceDir.exists() || !resourceDir.isDirectory() || !templatesDir.exists()

0 commit comments

Comments
 (0)