From 0bbff8d14d60b2d12b0de96836dba3981cad4d7c Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 2 Apr 2023 23:06:29 +1000 Subject: [PATCH] rework package cache manager - add testing mode --- .../ExtensionDefinitionGenerator.java | 2 +- .../convertors/analytics/PackageVisitor.java | 2 +- .../misc/OIDBasedValueSetImporter.java | 2 +- .../convertors/misc/utg/UTGVersionSorter.java | 6 +-- .../Convertor_Factory_40_50Test.java | 2 +- .../generator/engine/JavaCoreGenerator.java | 2 +- .../fhir/r4/test/utils/TestingUtilities.java | 2 +- .../hl7/fhir/r4/test/CDARoundTripTests.java | 2 +- .../fhir/r4b/test/utils/TestingUtilities.java | 3 +- .../hl7/fhir/r4b/test/CDARoundTripTests.java | 2 +- .../org/hl7/fhir/r4b/test/ParsingTests.java | 2 +- .../r4b/test/SnapShotGenerationTests.java | 2 +- .../r4b/test/StructureMapUtilitiesTest.java | 2 +- .../org/hl7/fhir/r4b/test/XmlParserTests.java | 2 +- .../fhir/r5/test/utils/TestingUtilities.java | 3 +- .../hl7/fhir/r5/test/CDARoundTripTests.java | 3 +- .../org/hl7/fhir/r5/test/ParsingTests.java | 3 +- .../fhir/r5/test/SnapShotGenerationTests.java | 3 +- .../r5/test/StructureMapUtilitiesTest.java | 3 +- .../org/hl7/fhir/r5/test/XmlParserTests.java | 3 +- .../npm/FilesystemPackageCacheManager.java | 49 +++++++++++-------- .../utilities/tests/PackageCacheTests.java | 12 +++-- .../hl7/fhir/validation/ValidationEngine.java | 2 +- .../validation/packages/PackageValidator.java | 2 +- .../comparison/tests/ComparisonTests.java | 4 +- .../conversion/tests/R3R4ConversionTests.java | 2 +- .../conversion/tests/UtilitiesXTests.java | 2 +- 27 files changed, 70 insertions(+), 54 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/ExtensionDefinitionGenerator.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/ExtensionDefinitionGenerator.java index 175b5d3fe..39b6d70d0 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/ExtensionDefinitionGenerator.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/ExtensionDefinitionGenerator.java @@ -387,7 +387,7 @@ public class ExtensionDefinitionGenerator { private List loadSource() throws IOException, FHIRException { List list = new ArrayList<>(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode()); if (sourceVersion == FHIRVersion._4_0_0) context = SimpleWorkerContext.fromPackage(npm); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java index 1881e4553..a457f4f49 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java @@ -109,7 +109,7 @@ public class PackageVisitor { public void visitPackages() throws IOException, ParserConfigurationException, SAXException { System.out.println("Finding packages"); pc = new PackageClient(PackageServer.primaryServer()); - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); Map cpidMap = getAllCIPackages(); Set cpidSet = new HashSet<>(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/OIDBasedValueSetImporter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/OIDBasedValueSetImporter.java index c0147d688..9a57654c8 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/OIDBasedValueSetImporter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/OIDBasedValueSetImporter.java @@ -16,7 +16,7 @@ public class OIDBasedValueSetImporter { protected IWorkerContext context; protected void init() throws FHIRException, IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); NpmPackage npm = pcm.loadPackage("hl7.fhir.r5.core", "current"); SimpleWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).fromPackage(npm); context.loadFromPackage(pcm.loadPackage("hl7.terminology"), null); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGVersionSorter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGVersionSorter.java index 16410b55b..f006b53ab 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGVersionSorter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/utg/UTGVersionSorter.java @@ -90,7 +90,7 @@ public class UTGVersionSorter { private Map loadPackageR2(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); } System.out.println("Load " + id); NpmPackage npm = pcm.loadPackage(id); @@ -104,7 +104,7 @@ public class UTGVersionSorter { private Map loadPackageR3(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); } System.out.println("Load " + id); NpmPackage npm = pcm.loadPackage(id); @@ -118,7 +118,7 @@ public class UTGVersionSorter { private Map loadPackageR4(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); } System.out.println("Load " + id); NpmPackage npm = pcm.loadPackage(id); diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/Convertor_Factory_40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/Convertor_Factory_40_50Test.java index 72cdbb218..5df805f99 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/Convertor_Factory_40_50Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/Convertor_Factory_40_50Test.java @@ -26,7 +26,7 @@ class Convertor_Factory_40_50Test { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); } diff --git a/org.hl7.fhir.core.generator/src/org/hl7/fhir/core/generator/engine/JavaCoreGenerator.java b/org.hl7.fhir.core.generator/src/org/hl7/fhir/core/generator/engine/JavaCoreGenerator.java index bc12e9f23..afe4cbec6 100644 --- a/org.hl7.fhir.core.generator/src/org/hl7/fhir/core/generator/engine/JavaCoreGenerator.java +++ b/org.hl7.fhir.core.generator/src/org/hl7/fhir/core/generator/engine/JavaCoreGenerator.java @@ -75,7 +75,7 @@ public class JavaCoreGenerator { Date ddate = new Date(); String date = config.DATE_FORMAT().format(ddate); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); System.out.println("Cache: "+pcm.getFolder()); System.out.println("Load hl7.fhir."+pid+".core"); NpmPackage npm = pcm.loadPackage("hl7.fhir."+pid+".core", version); diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/test/utils/TestingUtilities.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/test/utils/TestingUtilities.java index d8d3d50ce..3af459ca4 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/test/utils/TestingUtilities.java @@ -81,7 +81,7 @@ public class TestingUtilities { if (fcontext == null) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/CDARoundTripTests.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/CDARoundTripTests.java index 2ea512bd6..621460f1f 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/test/CDARoundTripTests.java @@ -30,7 +30,7 @@ public class CDARoundTripTests { @BeforeAll public void setUp() throws Exception { context = new SimpleWorkerContext(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "current"), null, "StructureDefinition"); context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda", "current"), null, "StructureDefinition"); } diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/test/utils/TestingUtilities.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/test/utils/TestingUtilities.java index 7caf08c5e..204213e58 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/test/utils/TestingUtilities.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/test/utils/TestingUtilities.java @@ -23,6 +23,7 @@ import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.npm.ToolsVersion; import org.hl7.fhir.utilities.tests.BaseTestingUtilities; import org.w3c.dom.Document; @@ -88,7 +89,7 @@ public class TestingUtilities extends BaseTestingUtilities { if (!fcontexts.containsKey(v)) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version)); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/CDARoundTripTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/CDARoundTripTests.java index 735eed77c..17d60f62a 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/CDARoundTripTests.java @@ -26,7 +26,7 @@ public class CDARoundTripTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fp = new FHIRPathEngine(context); diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/ParsingTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/ParsingTests.java index 14ece402f..89f379ab2 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/ParsingTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/ParsingTests.java @@ -35,7 +35,7 @@ public class ParsingTests { } public static Stream data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); npm = pcm.loadPackage("hl7.fhir.r4b.examples", "4.3.0"); List objects = new ArrayList<>(); List names = npm.list("package"); diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java index f6e1add70..7b43e03ad 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/SnapShotGenerationTests.java @@ -555,7 +555,7 @@ public class SnapShotGenerationTests { pu.setDebug(test.isDebug()); pu.setIds(test.getSource(), false); if (!TestingUtilities.context().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) { - NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); + NpmPackage npm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[]{"StructureDefinition"}), new String[]{"StructureDefinition"}); } pu.setXver(new XVerExtensionManager(TestingUtilities.context())); diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/StructureMapUtilitiesTest.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/StructureMapUtilitiesTest.java index 663e1374d..2d505ba83 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/StructureMapUtilitiesTest.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/StructureMapUtilitiesTest.java @@ -24,7 +24,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); } diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/XmlParserTests.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/XmlParserTests.java index 1fa19aa7f..8a64ae5f9 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/XmlParserTests.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/test/XmlParserTests.java @@ -24,7 +24,7 @@ public class XmlParserTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fp = new FHIRPathEngine(context); 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 205e4548b..44d6dfe75 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 @@ -16,6 +16,7 @@ import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.npm.BasePackageCacheManager.InputStreamWithSrc; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.IPackageProvider; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.ToolsVersion; @@ -77,7 +78,7 @@ public class TestingUtilities extends BaseTestingUtilities { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); IWorkerContext fcontext = null; if (VersionUtilities.isR5Ver(version)) { // for purposes of stability, the R5 core package comes from the test case repository diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java index 77c13ad19..c365eb80f 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java @@ -16,6 +16,7 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.npm.ToolsVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -28,7 +29,7 @@ public class CDARoundTripTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fp = new FHIRPathEngine(context); diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ParsingTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ParsingTests.java index fdfc9803a..430754c14 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ParsingTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ParsingTests.java @@ -18,6 +18,7 @@ import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.ToolsVersion; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; @@ -34,7 +35,7 @@ public class ParsingTests { } public static Stream data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); // npm = pcm.loadPackage("hl7.fhir.r5.examples", "5.0.0"); npm = NpmPackage.fromPackage(TestingUtilities.loadTestResourceStream("r5", "packages", "hl7.fhir.r5.examples.tgz")); List objects = new ArrayList<>(); diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java index 78d21d28f..4b551d4c5 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/SnapShotGenerationTests.java @@ -48,6 +48,7 @@ import org.hl7.fhir.utilities.npm.CommonPackages; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.ToolsVersion; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.xml.XMLUtil; @@ -535,7 +536,7 @@ public class SnapShotGenerationTests { pu.setIds(test.getSource(), false); pu.setAllowUnknownProfile(test.allow); if (!TestingUtilities.getSharedWorkerContext().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) { - NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); + NpmPackage npm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); TestingUtilities.getSharedWorkerContext().loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition")), Utilities.strings("StructureDefinition")); } pu.setXver(new XVerExtensionManager(TestingUtilities.getSharedWorkerContext())); diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java index de1506f40..146589681 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java @@ -18,6 +18,7 @@ import org.hl7.fhir.r5.utils.structuremap.ITransformerServices; import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.ToolsVersion; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -28,7 +29,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java index a1415e9da..19d1e4653 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java @@ -14,6 +14,7 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.ToolsVersion; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -25,7 +26,7 @@ public class XmlParserTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fp = new FHIRPathEngine(context); 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 5eb5fd2bb..a246562e0 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 @@ -36,6 +36,7 @@ import org.hl7.fhir.utilities.json.model.JsonArray; import org.hl7.fhir.utilities.json.model.JsonElement; import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.parser.JsonParser; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.IPackageProvider; import org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder; import org.hl7.fhir.utilities.npm.PackageList.PackageListEntry; @@ -88,6 +89,11 @@ import org.slf4j.LoggerFactory; public class FilesystemPackageCacheManager extends BasePackageCacheManager implements IPackageCacheManager { + public enum FilesystemPackageCacheMode { + USER, SYSTEM, TESTING + + } + // When running in testing mode, some packages are provided from the test case repository rather than by the normal means // the PackageProvider is responsible for this. if no package provider is defined, or it declines to handle the package, // then the normal means will be used @@ -111,31 +117,32 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple private JsonArray buildInfo; private boolean suppressErrors; - /** - * Constructor - */ - @Deprecated - public FilesystemPackageCacheManager(boolean userMode, int toolsVersion) throws IOException { - myPackageServers.addAll(PackageServer.publicServers()); - - if (userMode) - cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages"); - else - cacheFolder = Utilities.path("var", "lib", ".fhir", "packages"); - if (!(new File(cacheFolder).exists())) - Utilities.createDirectory(cacheFolder); - if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists())) - TextFile.stringToFile("[cache]\r\nversion=" + CACHE_VERSION + "\r\n\r\n[urls]\r\n\r\n[local]\r\n\r\n", Utilities.path(cacheFolder, "packages.ini"), false); - createIniFile(); - } - + public FilesystemPackageCacheManager(boolean userMode) throws IOException { + init(userMode ? FilesystemPackageCacheMode.USER : FilesystemPackageCacheMode.SYSTEM); + } + + public FilesystemPackageCacheManager(FilesystemPackageCacheMode mode) throws IOException { + init(mode); + } + + public void init(FilesystemPackageCacheMode mode) throws IOException { myPackageServers.addAll(PackageServer.publicServers()); - if (userMode) - cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages"); - else + switch (mode) { + case SYSTEM: cacheFolder = Utilities.path("var", "lib", ".fhir", "packages"); + break; + case USER: + cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages"); + break; + case TESTING: + cacheFolder = Utilities.path("[tmp]", ".fhir", "packages"); + break; + default: + break; + } + if (!(new File(cacheFolder).exists())) Utilities.createDirectory(cacheFolder); if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists())) diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java index 541d536dd..15fb78980 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java @@ -7,6 +7,7 @@ import java.util.List; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.npm.CommonPackages; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.ToolsVersion; import org.junit.jupiter.api.Assertions; @@ -16,14 +17,15 @@ public class PackageCacheTests { @Test public void testPath() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + NpmPackage npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK); cache.clear(); List list = cache.listPackages(); if (!list.isEmpty()) { System.out.println("remaining packages: "+list.toString()); } Assertions.assertTrue(list.isEmpty(), "List should be true but is "+list.toString()); - NpmPackage npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK); + npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK); npm.loadAllFiles(); Assertions.assertNotNull(npm); File dir = new File(Utilities.path("[tmp]", "cache")); @@ -41,7 +43,7 @@ public class PackageCacheTests { @Test public void testPatchWildCard() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); cache.clear(); Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.0").version(), "3.1.0"); Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.1").version(), "3.1.1"); @@ -51,7 +53,7 @@ public class PackageCacheTests { @Test public void testNotCaseSensitive() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); cache.clear(); Assertions.assertEquals(cache.loadPackage("KBV.Basis", "1.1.3").version(), "1.1.3"); Assertions.assertEquals(cache.loadPackage("kbv.basis", "1.1.3").version(), "1.1.3"); @@ -59,7 +61,7 @@ public class PackageCacheTests { @Test public void testLastReleasedVersion() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); cache.clear(); Assertions.assertEquals("0.0.8", cache.loadPackage(CommonPackages.ID_PUBPACK, "0.0.8").version()); Assertions.assertEquals(CommonPackages.VER_PUBPACK, cache.loadPackage(CommonPackages.ID_PUBPACK).version()); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 29b664e21..de492ecf4 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -973,7 +973,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP public FilesystemPackageCacheManager getPcm() throws IOException { if (pcm == null) { //System.out.println("Creating Package manager?"); - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); } return pcm; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageValidator.java index a7cb01f3b..e5130659c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageValidator.java @@ -21,7 +21,7 @@ public class PackageValidator { } private void execute() throws IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); PackageClient pc = new PackageClient(PackageServer.primaryServer()); for (PackageInfo t : pc.search(null, null, null, false)) { diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/comparison/tests/ComparisonTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/comparison/tests/ComparisonTests.java index 542f90863..f0edc74be 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/comparison/tests/ComparisonTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/comparison/tests/ComparisonTests.java @@ -110,7 +110,7 @@ public class ComparisonTests { if (context == null) { System.out.println("---- Load R5 ----------------------------------------------------------------"); context = TestingUtilities.getSharedWorkerContext(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0"); BaseWorkerContext bc = (BaseWorkerContext) context; boolean dupl = bc.isAllowLoadingDuplicates(); @@ -123,7 +123,7 @@ public class ComparisonTests { if (!new File(Utilities.path("[tmp]", "comparison")).exists()) { System.out.println("---- Set up Output ----------------------------------------------------------"); Utilities.createDirectory(Utilities.path("[tmp]", "comparison")); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK); for (String f : npm.list("other")) { TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f)); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java index f0a78967b..d441519e0 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java @@ -309,7 +309,7 @@ public class R3R4ConversionTests implements ITransformerServices, IValidatorReso if (contextR3 != null) return; - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true); System.out.println("loading R3"); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java index befe16d8a..302ac9814 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java @@ -89,7 +89,7 @@ public class UtilitiesXTests { if (!fcontexts.containsKey(version)) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); IWorkerContext fcontext = TestingUtilities.getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version)); fcontext.setUcumService(new UcumEssenceService(UtilitiesXTests.loadTestResourceStream("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters());