From 576be235d7c8174ecdcd345137c54e145b12fe43 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 10 May 2023 07:32:49 -0500 Subject: [PATCH] Allow NPM package versions to have the form {id}#{url} for direct access to packages --- RELEASE_NOTES.md | 1 + .../hl7/fhir/utilities/MarkDownProcessor.java | 1 - .../npm/FilesystemPackageCacheManager.java | 21 ++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index ef3a79ac7..b97098a6e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -6,6 +6,7 @@ * Slight improvement in performance * Fix FHIRPath split function (parameter is not regex) * Stop warning that Markdown autolinks need to be escaped +* Allow NPM package versions to have the form {id}#{url} for direct access to packages ## Other code changes diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/MarkDownProcessor.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/MarkDownProcessor.java index 818960411..6d11a1b69 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/MarkDownProcessor.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/MarkDownProcessor.java @@ -262,7 +262,6 @@ public class MarkDownProcessor { } } - public static String makeMarkdownForString(String content) { StringBuilder b = new StringBuilder(); for (int i = 0; i < content.length(); i++) { 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 cc74fabfb..bc72a2778 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 @@ -402,11 +402,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple @Override public NpmPackage addPackageToCache(String id, String version, InputStream packageTgzInputStream, String sourceDesc) throws IOException { checkValidVersionString(version, id); - if (progress) { - log("Installing " + id + "#" + (version == null ? "?" : version) + " to the package cache"); - log(" Fetching:"); - } - + NpmPackage npm = NpmPackage.fromPackage(packageTgzInputStream, sourceDesc, true); if (progress) { @@ -414,8 +410,8 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple logn(" Installing: "); } - if (!suppressErrors && npm.name() == null || id == null || !id.equalsIgnoreCase(npm.name())) { - if (!id.equals("hl7.fhir.r5.core") && !id.equals("hl7.fhir.us.immds")) {// temporary work around + if ((npm.name() != null && id != null && !id.equals(npm.name()))) { + if (!suppressErrors && (!id.equals("hl7.fhir.r5.core") && !id.equals("hl7.fhir.us.immds"))) {// temporary work around throw new IOException("Attempt to import a mis-identified package. Expected " + id + ", got " + npm.name()); } } @@ -569,10 +565,17 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple version = "current"; } + if (progress) { + log("Installing " + id + "#" + (version == null ? "?" : version) + " to the package cache"); + log(" Fetching:"); + } + // nup, don't have it locally (or it's expired) FilesystemPackageCacheManager.InputStreamWithSrc source; if (false && packageProvider != null && packageProvider.handlesPackage(id, version)) { source = packageProvider.provide(id, version); + } else if (Utilities.isAbsoluteUrl(version)) { + source = fetchSourceFromUrlSpecific(version); } else if ("current".equals(version) || (version!= null && version.startsWith("current$"))) { // special case - fetch from ci-build server source = loadFromCIBuild(id, version.startsWith("current$") ? version.substring(8) : null); @@ -585,6 +588,10 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple return addPackageToCache(id, source.version, source.stream, source.url); } + private InputStreamWithSrc fetchSourceFromUrlSpecific(String url) { + return new InputStreamWithSrc(fetchFromUrlSpecific(url, false), url, "current"); + } + private InputStream fetchFromUrlSpecific(String source, boolean optional) throws FHIRException { try { SimpleHTTPClient http = new SimpleHTTPClient();