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 bdfc3c937..2b1611a96 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(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 2adb4ec2a..b75248811 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 @@ -1,6 +1,5 @@ package org.hl7.fhir.convertors.analytics; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -34,6 +33,16 @@ import org.xml.sax.SAXException; public class PackageVisitor { + private PackageServer clientPackageServer = null; + + public void setClientPackageServer(PackageServer packageServer) { + this.clientPackageServer = packageServer; + } + private List cachePackageServers = null; + public void setCachePackageServers(List packageServers) { + this.cachePackageServers = packageServers; + } + public static class PackageContext { private String pid; private NpmPackage npm; @@ -145,8 +154,13 @@ public class PackageVisitor { public void visitPackages() throws IOException, ParserConfigurationException, SAXException, FHIRException, EOperationOutcome { System.out.println("Finding packages"); - pc = new PackageClient(PackageServer.primaryServer()); - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pc = clientPackageServer == null + ? new PackageClient(PackageServer.primaryServer()) + : new PackageClient(clientPackageServer); + + pcm = cachePackageServers == null + ? new FilesystemPackageCacheManager.Builder().build() + : new FilesystemPackageCacheManager.Builder().withPackageServers(cachePackageServers).build(); Set pidList = getAllPackages(); @@ -338,9 +352,14 @@ public class PackageVisitor { String fv = null; try { npm = pcm.loadPackage(pid, v); + } catch (Throwable e) { + System.out.println("Unable to load package: "+pid+"#"+v+": "+e.getMessage()); + } + + try { fv = npm.fhirVersion(); } catch (Throwable e) { - System.out.println("Unable to process: "+pid+"#"+v+": "+e.getMessage()); + System.out.println("Unable to identify package FHIR version:: "+pid+"#"+v+": "+e.getMessage()); } if (corePackages || !corePackage(npm)) { PackageContext ctxt = new PackageContext(pid+"#"+v, npm, fv); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java index 04ca512fc..861e4c53b 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java @@ -37,7 +37,7 @@ public class ExtensionExtractor { private void process(String dst) throws IOException { Set ids = new HashSet<>(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage r5 = pcm.loadPackage("hl7.fhir.r5.core", "current"); CanonicalResourceManager cslist = new CanonicalResourceManager(true, false); for (String r : r5.listResources("CodeSystem")) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionStatusUpgrader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionStatusUpgrader.java index ecdccb2d0..8e12f10a1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionStatusUpgrader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionStatusUpgrader.java @@ -25,7 +25,7 @@ public class ExtensionStatusUpgrader implements IResourceObserver { Map r5 = new HashMap<>(); private void execute(String folder) throws IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); // load R4 NpmPackage npm = pcm.loadPackage("hl7.fhir.r4.core"); 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 35accbd15..b1de1e3c2 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 @@ -15,7 +15,7 @@ public class OIDBasedValueSetImporter { protected IWorkerContext context; protected void init() throws FHIRException, IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pcm.loadPackage("hl7.fhir.r5.core", "5.0.0"); 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/PackageMinifier.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/PackageMinifier.java index 3abecbbc4..be52332f1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/PackageMinifier.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/PackageMinifier.java @@ -18,7 +18,7 @@ public class PackageMinifier { } private void process(String source, String target) throws FileNotFoundException, IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage src = pcm.loadPackage(source); NpmPackage tgt = NpmPackage.empty(); tgt.setNpm(src.getNpm().deepCopy()); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ResourceDependencyPackageBuilder.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ResourceDependencyPackageBuilder.java index 7d1b050d0..aa18f60aa 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ResourceDependencyPackageBuilder.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ResourceDependencyPackageBuilder.java @@ -35,7 +35,7 @@ public class ResourceDependencyPackageBuilder { public static void main(String[] args) throws IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); System.out.println("Load Core"); NpmPackage src = pcm.loadPackage(VersionUtilities.packageForVersion(args[0])); SimpleWorkerContext ctxt = new SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).fromPackage(src); 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 84f29be30..0cbba1d93 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 @@ -89,7 +89,7 @@ public class UTGVersionSorter { private Map loadPackageR2(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); } System.out.println("Load " + id); NpmPackage npm = pcm.loadPackage(id); @@ -103,7 +103,7 @@ public class UTGVersionSorter { private Map loadPackageR3(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); } System.out.println("Load " + id); NpmPackage npm = pcm.loadPackage(id); @@ -117,7 +117,7 @@ public class UTGVersionSorter { private Map loadPackageR4(String id) throws IOException { Map res = new HashMap<>(); if (pcm == null) { - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); } 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 45c1205bf..6695968e6 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 @@ -25,7 +25,7 @@ class Convertor_Factory_40_50Test { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 8e03d5756..7c5d0f9ec 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 @@ -73,7 +73,7 @@ public class JavaCoreGenerator { Date ddate = new Date(); String date = config.DATE_FORMAT().format(ddate); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheManagerBuilder().build(); 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 b71cd6662..a79622e05 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 @@ -79,8 +79,7 @@ public class TestingUtilities { if (fcontext == null) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fcontext .setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml"))); diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java index 1416dfaf6..4c1be75e4 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java @@ -11,7 +11,6 @@ import org.hl7.fhir.r4.context.SimpleWorkerContext; import org.hl7.fhir.r4.fhirpath.FHIRPathEngine; import org.hl7.fhir.r4.formats.IParser.OutputStyle; import org.hl7.fhir.r4.formats.JsonParser; -import org.hl7.fhir.r4.formats.XmlParser; import org.hl7.fhir.r4.model.Base; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.Bundle; @@ -27,8 +26,6 @@ import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Immunization; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; -import org.hl7.fhir.r4.model.HumanName; -import org.hl7.fhir.r4.model.Immunization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Period; import org.hl7.fhir.r4.model.Procedure; @@ -55,7 +52,7 @@ public class CmdLineApp { private void execute() throws IOException { System.out.print("Loading..."); - NpmPackage npm = new FilesystemPackageCacheManager(true).loadPackage("hl7.fhir.r4.core"); + NpmPackage npm = new FilesystemPackageCacheManager.Builder().build().loadPackage("hl7.fhir.r4.core"); context = SimpleWorkerContext.fromPackage(npm); fpe = new FHIRPathEngine(context); System.out.println(" Done"); 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 45bd86ac1..ba73e6d74 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 @@ -29,8 +29,7 @@ public class CDARoundTripTests { @BeforeAll public void setUp() throws Exception { context = new SimpleWorkerContext(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 1940a103a..260d5ee6c 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 @@ -20,8 +20,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; import org.w3c.dom.Element; @@ -85,8 +84,7 @@ public class TestingUtilities extends BaseTestingUtilities { if (!fcontexts.containsKey(v)) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); IWorkerContext fcontext = SimpleWorkerContext .fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version)); fcontext.setUcumService( 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 dde4d1961..9c085ddac 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 @@ -1,7 +1,6 @@ package org.hl7.fhir.r4b.test; import java.io.IOException; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -18,7 +17,6 @@ import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; -import org.hl7.fhir.utilities.npm.ToolsVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; @@ -36,8 +34,7 @@ public class ParsingTests { public static Stream data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 5c711a875..81dc492c4 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 @@ -46,7 +46,6 @@ 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.NpmPackage; -import org.hl7.fhir.utilities.npm.ToolsVersion; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.xml.XMLUtil; @@ -581,8 +580,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( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER) + NpmPackage npm = new FilesystemPackageCacheManager.Builder().build() .loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[] { "StructureDefinition" }), new String[] { "StructureDefinition" }); 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 b204f575e..fae52a446 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 @@ -10,7 +10,6 @@ import org.hl7.fhir.r4b.test.utils.TestingUtilities; import org.hl7.fhir.r4b.utils.structuremap.StructureMapUtilities; import org.hl7.fhir.r4b.utils.structuremap.ITransformerServices; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; -import org.hl7.fhir.utilities.npm.ToolsVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -24,8 +23,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 d84b86b86..63fff57cf 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 @@ -1,21 +1,11 @@ package org.hl7.fhir.r4b.test; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - import org.hl7.fhir.r4b.context.SimpleWorkerContext; -import org.hl7.fhir.r4b.elementmodel.Element; -import org.hl7.fhir.r4b.elementmodel.Manager; -import org.hl7.fhir.r4b.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r4b.fhirpath.FHIRPathEngine; -import org.hl7.fhir.r4b.formats.IParser.OutputStyle; import org.hl7.fhir.r4b.model.StructureDefinition; import org.hl7.fhir.r4b.test.utils.TestingUtilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; -import org.hl7.fhir.utilities.npm.ToolsVersion; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; public class XmlParserTests { @@ -24,8 +14,7 @@ public class XmlParserTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager( - org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 742927e48..43b7c9f03 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 @@ -13,15 +13,12 @@ import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache; -import org.hl7.fhir.r5.utils.R5Hacker; 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; import org.hl7.fhir.utilities.tests.BaseTestingUtilities; import org.hl7.fhir.utilities.tests.TestConfig; @@ -80,7 +77,7 @@ public class TestingUtilities extends BaseTestingUtilities { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); 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/profiles/GeneratedPEModelTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/GeneratedPEModelTest.java index 64a9dfc25..c12d8e975 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/GeneratedPEModelTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/GeneratedPEModelTest.java @@ -3,23 +3,13 @@ package org.hl7.fhir.r5.profiles; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; import java.util.TimeZone; -import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; -import org.hl7.fhir.r5.model.CodeableConcept; -import org.hl7.fhir.r5.model.Identifier; import org.hl7.fhir.r5.model.Observation; -import org.hl7.fhir.r5.model.Patient; -import org.hl7.fhir.r5.model.Reference; -import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.XmlParser; -import org.hl7.fhir.r5.profilemodel.PEBuilder; import org.hl7.fhir.r5.test.utils.CompareUtilities; import org.hl7.fhir.r5.test.utils.TestPackageLoader; import org.hl7.fhir.r5.test.utils.TestingUtilities; @@ -36,7 +26,7 @@ public class GeneratedPEModelTest { public void load() throws Exception { if (ctxt == null) { ctxt = TestingUtilities.getSharedWorkerContext(); - FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pc.loadPackage("hl7.fhir.us.core", "5.0.0"); ctxt.loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition" ))); diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PEModelTest1343.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PEModelTest1343.java index a394fc140..8d466a641 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PEModelTest1343.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PEModelTest1343.java @@ -1,7 +1,6 @@ package org.hl7.fhir.r5.profiles; -import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.Patient; import org.hl7.fhir.r5.context.SimpleWorkerContext; @@ -22,7 +21,7 @@ public class PEModelTest1343 { public void Load() throws Exception { if (ctxt == null) { ctxt = TestingUtilities.getSharedWorkerContext("4.0.1"); - FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pc.loadPackage("hl7.fhir.fr.core", "1.1.0"); ctxt.loadFromPackage(npm, new TestPackageLoader(Utilities.strings(SimpleWorkerContext.defaultTypesToLoad().stream().toArray(String[]::new)))); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PETests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PETests.java index 0812934fc..556a1eb7c 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PETests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/profiles/PETests.java @@ -28,20 +28,14 @@ package org.hl7.fhir.r5.profiles; POSSIBILITY OF SUCH DAMAGE. */ -import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.model.Coding; -import org.hl7.fhir.r5.model.Comparison; -import org.hl7.fhir.r5.model.Enumerations.ObservationStatus; import org.hl7.fhir.r5.model.Observation; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.profilemodel.PEDefinition; @@ -71,7 +65,7 @@ public class PETests { public void load() throws IOException { if (ctxt == null) { ctxt = TestingUtilities.getSharedWorkerContext(); - FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pc.loadPackage("hl7.fhir.us.core", "5.0.0"); ctxt.loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition" ))); 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 8b7667dda..a0b8c3c80 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 @@ -5,20 +5,15 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.List; -import org.hl7.fhir.r5.context.ContextUtilities; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.fhirpath.FHIRPathEngine; import org.hl7.fhir.r5.formats.IParser.OutputStyle; -import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.test.utils.TestingUtilities; -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.NpmPackage; -import org.hl7.fhir.utilities.npm.ToolsVersion; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -30,11 +25,11 @@ public class CDARoundTripTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); fp = new FHIRPathEngine(context); - NpmPackage npm = new FilesystemPackageCacheManager(true).loadPackage("hl7.cda.uv.core", "current"); + NpmPackage npm = new FilesystemPackageCacheManager.Builder().build().loadPackage("hl7.cda.uv.core", "current"); context.loadFromPackage(npm, null); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java index 269f29aab..aefedf7f6 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/FHIRPathTests.java @@ -41,7 +41,6 @@ import org.xml.sax.SAXException; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class FHIRPathTests { @@ -111,7 +110,7 @@ public class FHIRPathTests { @BeforeAll public static void setUp() throws FileNotFoundException, FHIRException, IOException { if (!TestingUtilities.getSharedWorkerContext().hasPackage("hl7.cda.us.ccda", null)) { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pcm.loadPackage("hl7.cda.uv.core", "2.0.0"); TestingUtilities.getSharedWorkerContext().loadFromPackage(npm, null); npm = pcm.loadPackage("hl7.cda.us.ccda", "current"); diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java index 6f8de6438..8abefd912 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java @@ -213,7 +213,7 @@ public class NarrativeGenerationTests { @BeforeAll public static void setUp() throws IOException { context = TestingUtilities.getSharedWorkerContext("5.0.0"); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage ips = pcm.loadPackage("hl7.fhir.uv.ips#1.1.0"); context.loadFromPackage(ips, new TestPackageLoader(Utilities.strings("StructureDefinition", "ValueSet" ))); } 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 3a14f83d1..afc7abf81 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 @@ -17,8 +17,6 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities; 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; @@ -35,7 +33,7 @@ public class ParsingTests { } public static Stream data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); // 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 c7b7aaba1..4a8ed4198 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 @@ -540,7 +540,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(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER); + NpmPackage npm = new FilesystemPackageCacheManager.Builder().build().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 3d920e59a..3b49fbe32 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 @@ -17,8 +17,6 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities; 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; @@ -29,7 +27,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 de5e34aaa..65c0387d6 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 @@ -13,8 +13,6 @@ import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.test.utils.TestingUtilities; 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; @@ -26,7 +24,7 @@ public class XmlParserTests { @BeforeAll public static void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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/utils/structuremap/FHIRPathHostServicesTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/structuremap/FHIRPathHostServicesTest.java index 5bb2b8a80..695d3b98c 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/structuremap/FHIRPathHostServicesTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/utils/structuremap/FHIRPathHostServicesTest.java @@ -16,7 +16,7 @@ class FHIRPathHostServicesTest { @BeforeAll static public void setUp() throws Exception { - FilesystemPackageCacheManager pcm = new org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager(true); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1")); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java index d7a177b7e..56461c690 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java @@ -44,6 +44,29 @@ public class SimpleHTTPClient { private static final int MAX_REDIRECTS = 5; private static int counter = 1; + public static class HTTPResultException extends Exception{ + public final int httpCode; + + public final String message; + + public final String url; + public final String logPath; + + public HTTPResultException(int httpCode, String message, String url, String logPath) { + this.httpCode = httpCode; + this.message = message; + this.url = url; + this.logPath = logPath; + } + + public String getMessage() { + return "Invalid HTTP response "+httpCode+" from "+url+" ("+message+") (" + ( + logPath != null ? "Response in " + logPath : "No response content") + + ")"; + } + + } + public static class HTTPResult { private int code; private String contentType; @@ -79,11 +102,13 @@ public class SimpleHTTPClient { if (code >= 300) { String filename = Utilities.path("[tmp]", "http-log", "fhir-http-"+(++counter)+".log"); if (content == null || content.length == 0) { - throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (no content)"); + HTTPResultException exception = new HTTPResultException(code, message, source, null); + throw new IOException(exception.message, exception); } else { Utilities.createDirectory(Utilities.path("[tmp]", "http-log")); TextFile.bytesToFile(content, filename); - throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (content in "+filename+")"); + HTTPResultException exception = new HTTPResultException(code, message, source, filename); + throw new IOException(exception.message, exception); } } } 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 561058aec..faac5c236 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 @@ -22,6 +22,8 @@ import java.util.UUID; import javax.annotation.Nonnull; +import lombok.Getter; +import lombok.With; import org.apache.commons.io.FileUtils; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.utilities.IniFile; @@ -84,13 +86,8 @@ import org.slf4j.LoggerFactory; */ public class FilesystemPackageCacheManager extends BasePackageCacheManager implements IPackageCacheManager { - public static final String INI_TIMESTAMP_FORMAT = "yyyyMMddHHmmss"; - public enum FilesystemPackageCacheMode { - USER, SYSTEM, TESTING, CUSTOM - } - // 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 @@ -99,8 +96,6 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple InputStreamWithSrc provide(String id, String version) throws IOException; } private static IPackageProvider packageProvider; - - // private static final String SECONDARY_SERVER = "http://local.fhir.org:8080/packages"; public static final String PACKAGE_REGEX = "^[a-zA-Z][A-Za-z0-9\\_\\-]*(\\.[A-Za-z0-9\\_\\-]+)+$"; public static final String PACKAGE_VERSION_REGEX = "^[A-Za-z][A-Za-z0-9\\_\\-]*(\\.[A-Za-z0-9\\_\\-]+)+\\#[A-Za-z0-9\\-\\_\\$]+(\\.[A-Za-z0-9\\-\\_\\$]+)*$"; public static final String PACKAGE_VERSION_REGEX_OPT = "^[A-Za-z][A-Za-z0-9\\_\\-]*(\\.[A-Za-z0-9\\_\\-]+)+(\\#[A-Za-z0-9\\-\\_]+(\\.[A-Za-z0-9\\-\\_]+)*)?$"; @@ -115,52 +110,78 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple private boolean suppressErrors; private boolean minimalMemory; - public FilesystemPackageCacheManager(boolean userMode) throws IOException { - init(userMode ? FilesystemPackageCacheMode.USER : FilesystemPackageCacheMode.SYSTEM); - } - - public FilesystemPackageCacheManager(FilesystemPackageCacheMode mode) throws IOException { - init(mode); - } - - /** - * Defined for use on Android - * - * @param customFolder - * @throws IOException - */ - public FilesystemPackageCacheManager(String customFolder) throws IOException { - this.cacheFolder = new File(customFolder); - init(FilesystemPackageCacheMode.CUSTOM); - } + public static class Builder { - protected void init(FilesystemPackageCacheMode mode) throws IOException { - initPackageServers(); + @Getter + private final File cacheFolder; - if (mode == FilesystemPackageCacheMode.CUSTOM) { - if (!this.cacheFolder.exists()) { - throw new FHIRException("The folder ''"+cacheFolder+"' could not be found"); + @With @Getter + private final List packageServers; + + public Builder() throws IOException { + this.cacheFolder = getUserCacheFolder(); + this.packageServers = getPackageServersFromFHIRSettings(); + } + + private File getUserCacheFolder() throws IOException { + return new File(Utilities.path(System.getProperty("user.home"), ".fhir", "packages")); + } + private List getPackageServersFromFHIRSettings() { + List packageServers = new ArrayList<>(getConfiguredServers()); + if (!isIgnoreDefaultPackageServers()) { + packageServers.addAll(getDefaultServers()); } - } else { - this.cacheFolder = getCacheFolder(mode); + return packageServers; + } + + protected boolean isIgnoreDefaultPackageServers() { + return FhirSettings.isIgnoreDefaultPackageServers(); + } + + @Nonnull + protected List getDefaultServers() { + return PackageServer.defaultServers(); + } + + protected List getConfiguredServers() { + return PackageServer.getConfiguredServers(); + } + private Builder(File cacheFolder, List packageServers) { + this.cacheFolder = cacheFolder; + this.packageServers = packageServers; + } + + public Builder withCacheFolder (String cacheFolderPath) throws IOException { + File cacheFolder = new File(cacheFolderPath); + if (!cacheFolder.exists()) { + throw new FHIRException("The folder '"+cacheFolder+"' could not be found"); + } + return new Builder(cacheFolder, this.packageServers); + } + + public Builder withSystemCacheFolder() throws IOException { + final File systemCacheFolder; + if (Utilities.isWindows()) { + systemCacheFolder = new File(Utilities.path(System.getenv("ProgramData"), ".fhir", "packages")); + } else { + systemCacheFolder = new File(Utilities.path("/var", "lib", ".fhir", "packages")); + } + return new Builder(systemCacheFolder, this.packageServers); + } + + public Builder withTestingCacheFolder() throws IOException { + return new Builder(new File(Utilities.path("[tmp]", ".fhir", "packages")), this.packageServers); + } + + public FilesystemPackageCacheManager build() throws IOException { + return new FilesystemPackageCacheManager(cacheFolder, packageServers); } - initCacheFolder(); } - public static File getCacheFolder(FilesystemPackageCacheMode mode) throws IOException { - switch (mode) { - case SYSTEM: - if (Utilities.isWindows()) { - return new File(Utilities.path(System.getenv("ProgramData"), ".fhir", "packages")); - } else { - return new File(Utilities.path("/var", "lib", ".fhir", "packages")); - } - case USER: - return new File(Utilities.path(System.getProperty("user.home"), ".fhir", "packages")); - case TESTING: - return new File(Utilities.path("[tmp]", ".fhir", "packages")); - } - return null; + private FilesystemPackageCacheManager(File cacheFolder, List packageServers) throws IOException { + this.cacheFolder = cacheFolder; + this.myPackageServers = packageServers; + initCacheFolder(); } protected void initCacheFolder() throws IOException { diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java index 4f6e49cc5..ae5843dc0 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java @@ -56,7 +56,8 @@ public class FilesystemPackageManagerTests { @Nonnull private FilesystemPackageCacheManager getFilesystemPackageCacheManager(final boolean ignoreDefaultPackageServers) throws IOException { - return new FilesystemPackageCacheManager(FilesystemPackageCacheManager.FilesystemPackageCacheMode.TESTING) { + + FilesystemPackageCacheManager.Builder builder = new FilesystemPackageCacheManager.Builder() { protected boolean isIgnoreDefaultPackageServers() { return ignoreDefaultPackageServers; } @@ -70,14 +71,14 @@ public class FilesystemPackageManagerTests { return dummyPrivateServers; } }; + + return builder.build(); + } @Test public void testUserCacheDirectory() throws IOException { - FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager(true) { - protected void initCacheFolder() throws IOException { - } - }; + FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager.Builder().build(); assertEquals(System.getProperty("user.home") + File.separator + ".fhir" + File.separator + "packages", filesystemPackageCacheManager.getFolder()); } @@ -87,27 +88,22 @@ public class FilesystemPackageManagerTests { @Test @DisabledOnOs(OS.WINDOWS) public void testSystemCacheDirectory() throws IOException { - FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager(false) { - protected void initCacheFolder() throws IOException { - } - }; - assertEquals( "/var/lib/.fhir/packages", filesystemPackageCacheManager.getFolder()); + File folder = new FilesystemPackageCacheManager.Builder().withSystemCacheFolder().getCacheFolder(); + + assertEquals( "/var/lib/.fhir/packages", folder.getAbsolutePath()); } @Test @EnabledOnOs(OS.WINDOWS) public void testSystemCacheDirectoryWin() throws IOException { - FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager(false) { - protected void initCacheFolder() throws IOException { - } - }; - assertEquals( System.getenv("ProgramData") + "\\.fhir\\packages", filesystemPackageCacheManager.getFolder()); + File folder = new FilesystemPackageCacheManager.Builder().withSystemCacheFolder().getCacheFolder(); + assertEquals( System.getenv("ProgramData") + "\\.fhir\\packages", folder.getAbsolutePath()); } @Test public void multithreadingTest() throws IOException { String pcmPath = Files.createTempDirectory("fpcm-multithreadingTest").toFile().getAbsolutePath(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(pcmPath); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().withCacheFolder(pcmPath).build(); final AtomicInteger totalSuccessful = new AtomicInteger(); diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/MinimalMemoryTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/MinimalMemoryTests.java index e89dc795e..951951387 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/MinimalMemoryTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/MinimalMemoryTests.java @@ -17,7 +17,7 @@ public class MinimalMemoryTests { } else { Utilities.createDirectory(folder.getAbsolutePath()); } - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(folder.getAbsolutePath()); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().withCacheFolder(folder.getAbsolutePath()).build(); pcm.setMinimalMemory(true); NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core", "5.0.0"); Assertions.assertTrue(npm.isMinimalMemory()); 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 fefee5d3a..c0fdef551 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 @@ -8,7 +8,6 @@ import org.hl7.fhir.utilities.TextFile; 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.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -17,7 +16,7 @@ public class PackageCacheTests { @Test public void testPath() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager.Builder().withTestingCacheFolder().build(); NpmPackage npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK); cache.clear(); List list = cache.listPackages(); @@ -43,7 +42,7 @@ public class PackageCacheTests { @Test public void testPatchWildCard() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager.Builder().withTestingCacheFolder().build(); 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"); @@ -53,7 +52,7 @@ public class PackageCacheTests { @Test public void testNotCaseSensitive() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager.Builder().withTestingCacheFolder().build(); 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"); @@ -61,7 +60,7 @@ public class PackageCacheTests { @Test public void testLastReleasedVersion() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager.Builder().withTestingCacheFolder().build(); 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()); @@ -69,7 +68,7 @@ public class PackageCacheTests { @Test public void testMinimal() throws IOException { - FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING); + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager.Builder().withTestingCacheFolder().build(); cache.clear(); NpmPackage uscore = cache.loadPackage("hl7.fhir.us.core", "3.1.0"); cache.setMinimalMemory(true); 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 345f69c4c..18ab260e1 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 @@ -29,7 +29,6 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.profile.ProfileUtilities; import org.hl7.fhir.r5.context.ContextUtilities; import org.hl7.fhir.r5.context.ILoggingService; -import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.IWorkerContextManager; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SystemOutLoggingService; @@ -1055,7 +1054,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP public FilesystemPackageCacheManager getPcm() throws IOException { if (pcm == null) { //System.out.println("Creating Package manager?"); - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); } return pcm; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java index 19c8b8aa8..a74ad28dc 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorCli.java @@ -74,25 +74,7 @@ import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.settings.FhirSettings; import org.hl7.fhir.validation.cli.model.CliContext; import org.hl7.fhir.validation.cli.services.ValidationService; -import org.hl7.fhir.validation.cli.tasks.CliTask; -import org.hl7.fhir.validation.cli.tasks.CompareTask; -import org.hl7.fhir.validation.cli.tasks.CompileTask; -import org.hl7.fhir.validation.cli.tasks.ConvertTask; -import org.hl7.fhir.validation.cli.tasks.FhirpathTask; -import org.hl7.fhir.validation.cli.tasks.InstallTask; -import org.hl7.fhir.validation.cli.tasks.LangTransformTask; -import org.hl7.fhir.validation.cli.tasks.NarrativeTask; -import org.hl7.fhir.validation.cli.tasks.ScanTask; -import org.hl7.fhir.validation.cli.tasks.SnapshotTask; -import org.hl7.fhir.validation.cli.tasks.SpecialTask; -import org.hl7.fhir.validation.cli.tasks.SpreadsheetTask; -import org.hl7.fhir.validation.cli.tasks.StandaloneTask; -import org.hl7.fhir.validation.cli.tasks.TestsTask; -import org.hl7.fhir.validation.cli.tasks.TransformTask; -import org.hl7.fhir.validation.cli.tasks.TxTestsTask; -import org.hl7.fhir.validation.cli.tasks.ValidateTask; -import org.hl7.fhir.validation.cli.tasks.ValidationEngineTask; -import org.hl7.fhir.validation.cli.tasks.VersionTask; +import org.hl7.fhir.validation.cli.tasks.*; import org.hl7.fhir.validation.cli.utils.Display; import org.hl7.fhir.validation.cli.utils.Params; @@ -144,6 +126,7 @@ public class ValidatorCli { new InstallTask(), new LangTransformTask(), new NarrativeTask(), + new PreloadCacheTask(), new ScanTask(), new SnapshotTask(), new SpecialTask(), diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index ae0a9bb6f..91b2a6c86 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -33,7 +33,6 @@ import org.hl7.fhir.r5.model.ConceptMap; import org.hl7.fhir.r5.model.OperationOutcome; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.StructureDefinition; -import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r5.model.StructureMap; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.renderers.spreadsheets.CodeSystemSpreadsheetGenerator; @@ -154,7 +153,7 @@ public class ValidationService { public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception { VersionSourceInformation versions = new VersionSourceInformation(); IgLoader igLoader = new IgLoader( - new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER), + new FilesystemPackageCacheManager.Builder().build(), new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(), null); for (String src : cliContext.getIgs()) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/PreloadCacheTask.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/PreloadCacheTask.java new file mode 100644 index 000000000..d2cac9626 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/PreloadCacheTask.java @@ -0,0 +1,57 @@ +package org.hl7.fhir.validation.cli.tasks; + +import org.hl7.fhir.convertors.analytics.PackageVisitor; +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r5.utils.EOperationOutcome; +import org.hl7.fhir.utilities.SystemExitManager; +import org.hl7.fhir.utilities.TimeTracker; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.json.JsonException; +import org.hl7.fhir.utilities.json.model.JsonObject; +import org.hl7.fhir.utilities.json.parser.JsonParser; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.PackageServer; +import org.hl7.fhir.utilities.settings.FhirSettings; +import org.hl7.fhir.validation.cli.model.CliContext; +import org.hl7.fhir.validation.cli.utils.Params; +import org.hl7.fhir.validation.packages.PackageCacheDownloader; +import org.hl7.fhir.validation.special.TxTester; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.List; + +public class PreloadCacheTask extends StandaloneTask { + @Override + public String getName() { + return "preloadCache"; + } + + @Override + public String getDisplayName() { + return "Pre-load Package Cache"; + } + + @Override + public boolean isHidden() { + return true; + } + + @Override + public boolean shouldExecuteTask(CliContext cliContext, String[] args) { + return Params.hasParam(args, Params.PRELOAD_CACHE); + } + + @Override + public void printHelp(PrintStream out) { + + } + + @Override + public void executeTask(CliContext cliContext, String[] args, TimeTracker tt, TimeTracker.Session tts) throws Exception { + PackageVisitor pv = new PackageCacheDownloader(); + pv.visitPackages(); + } + + +} diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java index fc093f556..568963099 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Display.java @@ -21,7 +21,7 @@ public class Display { } public static void printCliParamsAndInfo(String[] args) throws IOException { - System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).getFolder()); + System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager.Builder().build().getFolder()); System.out.print(" Params:"); for (String s : args) { System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Params.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Params.java index 29983d61e..cd70055f4 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Params.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/Params.java @@ -69,6 +69,8 @@ public class Params { public static final String LEFT = "-left"; public static final String RIGHT = "-right"; public static final String NO_INTERNAL_CACHING = "-no-internal-caching"; + + public static final String PRELOAD_CACHE = "-preload-cache"; public static final String NO_EXTENSIBLE_BINDING_WARNINGS = "-no-extensible-binding-warnings"; public static final String NO_UNICODE_BIDI_CONTROL_CHARS = "-no_unicode_bidi_control_chars"; public static final String NO_INVARIANTS = "-no-invariants"; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageCacheDownloader.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageCacheDownloader.java new file mode 100644 index 000000000..6b9ec6239 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/packages/PackageCacheDownloader.java @@ -0,0 +1,58 @@ +package org.hl7.fhir.validation.packages; + +import org.hl7.fhir.convertors.analytics.PackageVisitor; +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r5.utils.EOperationOutcome; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.npm.PackageServer; + +import java.io.IOException; +import java.util.List; + +/** + * A PackageVisitor that is intended to visit each available package from + * https://packages2.fhir.org/packages aka PackageServer.secondaryServer() + *

+ * A useful side effect of this is that it fills the package cache on the disk + * with all available packages. Aside from this, it does nothing but write to + * console out. + *

+ * It targets the secondary server to avoid loading the primary server. + * + */ +public class PackageCacheDownloader extends PackageVisitor implements PackageVisitor.IPackageVisitorProcessor{ + + public PackageCacheDownloader() throws IOException { + super(); + setClientPackageServer(PackageServer.secondaryServer()); + setCachePackageServers(List.of(PackageServer.secondaryServer())); + + String taskCache = Utilities.path("[tmp]", "package-cache-task"); + + setProcessor(this); + setCache(taskCache); + setOldVersions(true); + setCorePackages(true); + } + + @Override + public Object startPackage(PackageVisitor.PackageContext context) throws FHIRException { + System.out.println("Currently loading " + context.getPid()); + return null; + } + + @Override + public void processResource(PackageVisitor.PackageContext context, Object clientContext, String type, String id, byte[] content) throws FHIRException { + + } + + @Override + public void finishPackage(PackageVisitor.PackageContext context) throws FHIRException { + + } + + @Override + public void alreadyVisited(String pid) throws FHIRException { + + } +} 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 720635aea..e1ff6bb37 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 @@ -20,7 +20,7 @@ public class PackageValidator { } private void execute() throws IOException { - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); PackageClient pc = new PackageClient(PackageServer.primaryServer()); for (PackageInfo t : pc.search(null, null, null, false)) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/R4R5MapTester.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/R4R5MapTester.java index 3cf17d529..35d9e1ad8 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/R4R5MapTester.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/special/R4R5MapTester.java @@ -167,7 +167,7 @@ public class R4R5MapTester implements IValidatorResourceFetcher { log("Load Test Outcomes"); JsonObject json = JsonParser.parseObjectFromFile(Utilities.path(src, "input", "_data", "conversions.json")); log("Load R5"); - pcm = new FilesystemPackageCacheManager(true); + pcm = new FilesystemPackageCacheManager.Builder().build(); context = new SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).fromPackage(pcm.loadPackage("hl7.fhir.r5.core#current")); log("Load Maps"); // context.loadFromPackage(pcm.loadPackage(), null); 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 8ec4c7b1c..37b5ba176 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 @@ -64,7 +64,6 @@ import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.json.model.*; -import org.hl7.fhir.utilities.json.parser.*; import org.hl7.fhir.utilities.npm.CommonPackages; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; @@ -127,7 +126,7 @@ public class ComparisonTests { if (context == null) { System.out.println("---- Load R5 ----------------------------------------------------------------"); context = TestingUtilities.getSharedWorkerContext(); - FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0"); BaseWorkerContext bc = (BaseWorkerContext) context; boolean dupl = bc.isAllowLoadingDuplicates(); @@ -140,7 +139,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(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager.Builder().build(); 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 16d140d8b..8c5171621 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 @@ -308,7 +308,7 @@ public class R3R4ConversionTests implements ITransformerServices, IValidatorReso if (contextR3 != null) return; - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); 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 fe6a7f8d1..9f168dc71 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 @@ -87,7 +87,7 @@ public class UtilitiesXTests { if (!fcontexts.containsKey(version)) { FilesystemPackageCacheManager pcm; try { - pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER); + pcm = new FilesystemPackageCacheManager.Builder().build(); 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()); diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/ValidatorCliTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/ValidatorCliTests.java index efada366f..cea88b6d7 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/ValidatorCliTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/ValidatorCliTests.java @@ -16,23 +16,7 @@ import org.hl7.fhir.utilities.TimeTracker; import org.hl7.fhir.validation.cli.model.CliContext; import org.hl7.fhir.validation.cli.services.ValidationService; import org.hl7.fhir.validation.cli.services.ValidatorWatchMode; -import org.hl7.fhir.validation.cli.tasks.CliTask; -import org.hl7.fhir.validation.cli.tasks.CompareTask; -import org.hl7.fhir.validation.cli.tasks.CompileTask; -import org.hl7.fhir.validation.cli.tasks.ConvertTask; -import org.hl7.fhir.validation.cli.tasks.FhirpathTask; -import org.hl7.fhir.validation.cli.tasks.InstallTask; -import org.hl7.fhir.validation.cli.tasks.LangTransformTask; -import org.hl7.fhir.validation.cli.tasks.NarrativeTask; -import org.hl7.fhir.validation.cli.tasks.ScanTask; -import org.hl7.fhir.validation.cli.tasks.SnapshotTask; -import org.hl7.fhir.validation.cli.tasks.SpecialTask; -import org.hl7.fhir.validation.cli.tasks.SpreadsheetTask; -import org.hl7.fhir.validation.cli.tasks.TestsTask; -import org.hl7.fhir.validation.cli.tasks.TransformTask; -import org.hl7.fhir.validation.cli.tasks.TxTestsTask; -import org.hl7.fhir.validation.cli.tasks.ValidateTask; -import org.hl7.fhir.validation.cli.tasks.VersionTask; +import org.hl7.fhir.validation.cli.tasks.*; import org.hl7.fhir.validation.cli.utils.Params; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -74,6 +58,12 @@ public class ValidatorCliTests { @Spy SpreadsheetTask spreadsheetTask; + @Spy + PreloadCacheTask preloadCacheTask = new PreloadCacheTask() { + @Override + public void executeTask(CliContext cliContext, String[] args, TimeTracker tt, TimeTracker.Session tts) {} + }; + @Spy TestsTask testsTask = new TestsTask() { @Override @@ -119,6 +109,7 @@ public class ValidatorCliTests { installTask, langTransformTask, narrativeTask, + preloadCacheTask, scanTask, snapshotTask, specialTask, @@ -304,6 +295,16 @@ public class ValidatorCliTests { Mockito.verify(compareTask).executeTask(same(validationService), same(validationEngine), same(cliContext), eq(args), any(TimeTracker.class), any(TimeTracker.Session.class)); } + @Test + public void preloadCacheTest() throws Exception { + final String[] args = new String[]{"-preload-cache"}; + CliContext cliContext = Params.loadCliContext(args); + ValidatorCli cli = mockValidatorCli(); + cli.readParamsAndExecuteTask(cliContext, args); + + Mockito.verify(preloadCacheTask).executeTask(same(cliContext), eq(args), any(TimeTracker.class), any(TimeTracker.Session.class)); + } + @Test public void txTestsTest() throws Exception { final String[] args = new String[]{"-txTests"}; diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java index e406ae3a1..79d038e2e 100644 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java @@ -22,7 +22,6 @@ import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; @@ -39,7 +38,6 @@ import org.hl7.fhir.r5.fhirpath.TypeDetails; import org.hl7.fhir.r5.fhirpath.FHIRPathEngine.IEvaluationContext; import org.hl7.fhir.r5.fhirpath.FHIRPathUtilityClasses.FunctionDetails; import org.hl7.fhir.r5.elementmodel.ObjectConverter; -import org.hl7.fhir.r5.elementmodel.SHLParser; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.XmlParser; @@ -445,7 +443,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe private NpmPackage loadPackage(String idAndVer) throws IOException { - var pcm = new FilesystemPackageCacheManager(true); + var pcm = new FilesystemPackageCacheManager.Builder().build(); return pcm.loadPackage(idAndVer); }