From 364ed14c2a65141fc8a7eb18e8edbb624a44608d Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 1 Feb 2019 06:09:03 +1100 Subject: [PATCH] rename package cache operations for clarity + upgrade for version release --- org.hl7.fhir.convertors/pom.xml | 2 +- .../ExtensionDefinitionGenerator.java | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- .../fhir/r4/test/utils/TestingUtilities.java | 2 +- .../hl7/fhir/r4/test/CDARoundTripTests.java | 4 +- org.hl7.fhir.utilities/pom.xml | 2 +- .../utilities/cache/PackageCacheManager.java | 48 +++++++++++++------ org.hl7.fhir.validation/pom.xml | 2 +- .../fhir/r4/validation/ValidationEngine.java | 6 +-- pom.xml | 2 +- 13 files changed, 49 insertions(+), 29 deletions(-) diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 96e8a97eb..a62c0a3bc 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml 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 efce572b4..bb79f168f 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 @@ -383,7 +383,7 @@ public class ExtensionDefinitionGenerator { private List loadSource() throws IOException, FHIRException { List list = new ArrayList<>(); PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - NpmPackage npm = pcm.loadPackageCache("hl7.fhir.core", sourceVersion.toCode()); + NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode()); if (sourceVersion == FHIRVersion._4_0_0) context = SimpleWorkerContext.fromPackage(npm); else if (sourceVersion == FHIRVersion._3_0_1) diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 29b0ee034..ef33c80b2 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index 77bf3df1a..76baaca56 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index ac775b0a1..4f1e22a18 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index 5a8e93b0a..2e218a361 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml 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 f3dbad616..047fbcffc 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 @@ -66,7 +66,7 @@ public class TestingUtilities { PackageCacheManager pcm; try { pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackageCache("hl7.fhir.core", "4.0.0")); + fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0")); fcontext.setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml"))); fcontext.setExpansionProfile(new Parameters()); } catch (Exception e) { 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 23ce9aab4..a262689ff 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 @@ -26,8 +26,8 @@ public class CDARoundTripTests { public void setUp() throws Exception { context = new SimpleWorkerContext(); PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); - context.loadFromPackage(pcm.loadPackageCacheLatest("hl7.fhir.core"), null, "StructureDefinition"); - context.loadFromPackage(pcm.loadPackageCacheLatest("hl7.fhir.cda"), null, "StructureDefinition"); + context.loadFromPackage(pcm.loadPackage("hl7.fhir.core"), null, "StructureDefinition"); + context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda"), null, "StructureDefinition"); } @Test diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index 91bea8f91..31506c1e6 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageCacheManager.java index e4d7b5560..736b1c9de 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageCacheManager.java @@ -162,7 +162,7 @@ public class PackageCacheManager { boolean del = true; NpmPackage pck; try { - pck = resolvePackage(id, ver, "xx"); + pck = loadPackageFromCacheOnly(id, ver); if (pck.getNpm().has("tools-version")) { del = pck.getNpm().get("tools-version").getAsInt() < minVer; } @@ -247,7 +247,13 @@ public class PackageCacheManager { return names; } - public NpmPackage loadPackageCacheLatest(String id) throws IOException { + /** + * get the latest version of the package from what is in the cache + * @param id + * @return + * @throws IOException + */ + public NpmPackage loadPackageFromCacheOnly(String id) throws IOException { String match = null; List l = sorted(new File(cacheFolder).list()); for (int i = l.size()-1; i >= 0; i--) { @@ -259,7 +265,17 @@ public class PackageCacheManager { return null; } - public NpmPackage loadPackageCache(String id, String version) throws IOException { + /** + * Load the identified package from the cache - it it exists + * + * This is for special purpose only. Generally, use the loadPackage method + * + * @param id + * @param version + * @return + * @throws IOException + */ + public NpmPackage loadPackageFromCacheOnly(String id, String version) throws IOException { for (NpmPackage p : temporaryPackages) { if (p.name().equals(id) && ("current".equals(version) || "dev".equals(version) || p.version().equals(version))) return p; @@ -271,7 +287,7 @@ public class PackageCacheManager { } } if ("dev".equals(version)) - return loadPackageCache(id, "current"); + return loadPackageFromCacheOnly(id, "current"); else return null; } @@ -515,13 +531,17 @@ public class PackageCacheManager { return false; } - public NpmPackage resolvePackage(String id, String v, String currentVersion) throws FHIRException, IOException { - NpmPackage p = loadPackageCache(id, v); + public NpmPackage loadPackage(String id) throws FHIRException, IOException { + throw new Error("Not done yet"); + } + + public NpmPackage loadPackage(String id, String v) throws FHIRException, IOException { + NpmPackage p = loadPackageFromCacheOnly(id, v); if (p != null) return p; if ("dev".equals(v)) { - p = loadPackageCache(id, "current"); + p = loadPackageFromCacheOnly(id, "current"); if (p != null) return p; v = "current"; @@ -560,13 +580,13 @@ public class PackageCacheManager { return addPackageToCache(id, v, stream); } } - // special case: current version - if (id.equals("hl7.fhir.core") && v.equals(currentVersion)) { - InputStream stream = fetchFromUrlSpecific(Utilities.pathURL("http://build.fhir.org", "package.tgz"), true); - if (stream == null) - throw new FHIRException("Unable to find the package source for '"+id+"#"+v+"' at "+Utilities.pathURL("http://build.fhir.org", "package.tgz")); - return addPackageToCache(id, v, stream); - } +// // special case: current version +// if (id.equals("hl7.fhir.core") && v.equals(currentVersion)) { +// InputStream stream = fetchFromUrlSpecific(Utilities.pathURL("http://build.fhir.org", "package.tgz"), true); +// if (stream == null) +// throw new FHIRException("Unable to find the package source for '"+id+"#"+v+"' at "+Utilities.pathURL("http://build.fhir.org", "package.tgz")); +// return addPackageToCache(id, v, stream); +// } throw new FHIRException("Unable to resolve version "+v+" for package "+id); } } diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index e8d98f19f..cf05e242f 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java index 7317980d0..c4c0cf989 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java @@ -540,11 +540,11 @@ public class ValidationEngine { } NpmPackage pi = null; if (version == null) { - pi = pcm.loadPackageCacheLatest(id); + pi = pcm.loadPackageFromCacheOnly(id); if (pi != null) log(" ... Using version "+pi.version()); } else - pi = pcm.loadPackageCache(id, version); + pi = pcm.loadPackageFromCacheOnly(id, version); if (pi == null) { return resolvePackage(id, version); } else @@ -557,7 +557,7 @@ public class ValidationEngine { } catch (IOException e) { log("Unable to connect to build.fhir.org to check on packages"); } - NpmPackage pi = pcm.resolvePackage(id, v, Constants.VERSION); + NpmPackage pi = pcm.loadPackage(id, v); if (pi != null && v == null) log(" ... Using version "+pi.version()); return loadPackage(pi); diff --git a/pom.xml b/pom.xml index cb09a3427..ef206bc7e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ each other. It is fine to bump the point version of this POM without affecting HAPI FHIR. --> - 3.7.1-SNAPSHOT + 3.7.2-SNAPSHOT 3.7.0-SNAPSHOT