diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java index 7adcb333e..78af02088 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java @@ -21,6 +21,7 @@ import org.hl7.fhir.r5.context.TerminologyCache; import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.TextFile; +import org.hl7.fhir.utilities.ToolGlobalSettings; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; @@ -164,14 +165,10 @@ public class TestingUtilities extends BaseTestingUtilities { public static String checkXMLIsSame(String f1, String f2) throws Exception { String result = compareXml(f1, f2); if (result != null && SHOW_DIFF) { - String diff = Utilities.path(System.getenv("ProgramFiles"), "WinMerge", "WinMergeU.exe"); - if (new File(diff).exists()) { + String diff = ToolGlobalSettings.hasComparePath() ? ToolGlobalSettings.getComparePath() : Utilities.path(System.getenv("ProgramFiles"), "WinMerge", "WinMergeU.exe"); + if (new File(diff).exists() || Utilities.isToken(diff)) { List command = new ArrayList(); - command.add("\"" + diff + "\" \"" + f1 + "\" \"" + f2 + "\""); - - ProcessBuilder builder = new ProcessBuilder(command); - builder.directory(new CSFile("c:\\temp")); - builder.start(); + Process p = Runtime.getRuntime().exec(new String[]{diff, f1, f2}); } } return result; @@ -490,6 +487,8 @@ public class TestingUtilities extends BaseTestingUtilities { String path = Utilities.path("C:\\temp", name); Utilities.createDirectory(path); return path; + } else if (ToolGlobalSettings.hasTempPath()) { + return ToolGlobalSettings.getTempPath(); } else if (new File("/tmp").exists()) { String path = Utilities.path("/tmp", name); Utilities.createDirectory(path); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ToolGlobalSettings.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ToolGlobalSettings.java new file mode 100644 index 000000000..62cd18975 --- /dev/null +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/ToolGlobalSettings.java @@ -0,0 +1,70 @@ +package org.hl7.fhir.utilities; + +import java.io.IOException; + +public class ToolGlobalSettings { + + private static boolean inited = false; + + private static String npmPath; + private static String rubyPath; + private static String testsPath; + private static String comparePath; + private static String tempPath; + + public static String getNpmPath() { + init(); + return npmPath; + } + public static String getRubyPath() { + init(); + return rubyPath; + } + public static String getTestsPath() { + init(); + return testsPath; + } + + public static boolean hasNpmPath() { + init(); + return npmPath != null; + } + public static boolean hasRubyPath() { + init(); + return rubyPath != null; + } + public static boolean hasTestsPath() { + init(); + return testsPath != null; + } + + public static String getComparePath() { + return comparePath; + } + public static boolean hasComparePath() { + return comparePath != null; + } + public static String getTempPath() { + return tempPath; + } + public static boolean hasTempPath() { + return tempPath != null; + } + private static void init() { + if (!inited) { + inited = true; + IniFile ini; + try { + ini = new IniFile(Utilities.path(Utilities.path(System.getProperty("user.home"), ".fhir", "fhir-tool-settings.conf"))); + if (ini.hasSection("paths")) { + npmPath = ini.getStringProperty("paths", "npm"); + rubyPath = ini.getStringProperty("paths", "ruby"); + testsPath = ini.getStringProperty("paths", "tests"); + comparePath = ini.getStringProperty("paths", "compare"); + tempPath = ini.getStringProperty("paths", "temp"); + } + } catch (IOException e) { + } + } + } +} \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index db22d051a..5f9228083 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -596,6 +596,8 @@ public class Utilities { if ("[tmp]".equals(a)) { if (hasCTempDir()) { a = "c:\\temp"; + } else if (ToolGlobalSettings.hasTempPath()) { + a = ToolGlobalSettings.getTempPath(); } else { a = System.getProperty("java.io.tmpdir"); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java index a07b631a5..af45003e4 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/FilesystemPackageCacheManager.java @@ -626,12 +626,12 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple JsonObject json = JsonTrackingParser.fetchJson(Utilities.pathURL(url, "package.manifest.json")); String currDate = JSONUtil.str(json, "date"); String packDate = p.date(); - if (!currDate.equals(packDate)) + if (!currDate.equals(packDate)) { return null; // nup, we need a new copy - return p; + } } catch (Exception e) { - return p; } + return p; } private boolean checkBuildLoaded() { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/tests/BaseTestingUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/tests/BaseTestingUtilities.java index 4ed5ba296..3619d213b 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/tests/BaseTestingUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/tests/BaseTestingUtilities.java @@ -3,6 +3,7 @@ package org.hl7.fhir.utilities.tests; import org.apache.commons.io.IOUtils; import org.hl7.fhir.utilities.CSFile; import org.hl7.fhir.utilities.TextFile; +import org.hl7.fhir.utilities.ToolGlobalSettings; import org.hl7.fhir.utilities.Utilities; import java.io.*; @@ -22,7 +23,11 @@ public class BaseTestingUtilities { * the name of the project directory to something other than 'fhir-test-cases', or move it to another location, not * at the same directory level as the core project. */ + String dir = System.getenv("FHIR-TEST-CASES"); + if (dir == null && ToolGlobalSettings.hasTestsPath()) { + dir = ToolGlobalSettings.getTestsPath(); + } if (dir != null && new CSFile(dir).exists()) { String n = Utilities.path(dir, Utilities.path(paths)); // ok, we'll resolve this locally @@ -44,6 +49,9 @@ public class BaseTestingUtilities { public static InputStream loadTestResourceStream(String... paths) throws IOException { String dir = System.getenv("FHIR-TEST-CASES"); + if (dir == null && ToolGlobalSettings.hasTestsPath()) { + dir = ToolGlobalSettings.getTestsPath(); + } if (dir != null && new File(dir).exists()) { String n = Utilities.path(dir, Utilities.path(paths)); return new FileInputStream(n); @@ -59,6 +67,9 @@ public class BaseTestingUtilities { public static byte[] loadTestResourceBytes(String... paths) throws IOException { String dir = System.getenv("FHIR-TEST-CASES"); + if (dir == null && ToolGlobalSettings.hasTestsPath()) { + dir = ToolGlobalSettings.getTestsPath(); + } if (dir != null && new File(dir).exists()) { String n = Utilities.path(dir, Utilities.path(paths)); return TextFile.fileToBytes(n); @@ -74,6 +85,9 @@ public class BaseTestingUtilities { public static boolean findTestResource(String... paths) throws IOException { String dir = System.getenv("FHIR-TEST-CASES"); + if (dir == null && ToolGlobalSettings.hasTestsPath()) { + dir = ToolGlobalSettings.getTestsPath(); + } if (dir != null && new File(dir).exists()) { String n = Utilities.path(dir, Utilities.path(paths)); return new File(n).exists();