diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index 3b303a035..91e8d46b2 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -193,6 +193,16 @@ public class VersionUtilities { } } + public static String getPatch(String version) { + if (version == null) + return null; + if (Utilities.charCount(version, '.') == 2) { + String[] p = version.split("\\."); + return p[2]; + } + return null; + } + public static boolean isSemVer(String version) { if (Utilities.charCount(version, '.') != 2) { return false; @@ -202,7 +212,7 @@ public class VersionUtilities { } /** - * return true if the current vresion equals test, or later + * return true if the current version equals test, or later * * so if a feature is defined in 4.0, if (VersionUtilities.isThisOrLater("4.0", version))... * @@ -213,10 +223,36 @@ public class VersionUtilities { public static boolean isThisOrLater(String test, String current) { String t = getMajMin(test); String c = getMajMin(current); + if (c.compareTo(t) == 0) { + return isMajMinOrLaterPatch(test, current); + } boolean ok = c.compareTo(t) >= 0; return ok; } + /** + * return true if the current version equals test for major and min, or later patch + * + * @param test + * @param current + * @return + */ + public static boolean isMajMinOrLaterPatch(String test, String current) { + String t = getMajMin(test); + String c = getMajMin(current); + if (c.compareTo(t) == 0) { + String pt = getPatch(test); + String pc = getPatch(current); + if (pt==null || "x".equals(pt)) { + return true; + } + if (pc!=null) { + return pc.compareTo(pt) >= 0; + } + } + return false; + } + public static String incMajorVersion(String v) { assert isSemVer(v); int[] parts = splitParts(v); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/BasePackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/BasePackageCacheManager.java index 82e295e89..5074396bd 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/BasePackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/BasePackageCacheManager.java @@ -69,6 +69,9 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager { if (Utilities.noString(version)) { version = packageClient.getLatestVersion(id); } + if (version.endsWith(".x")) { + version = packageClient.getLatestVersion(id, version); + } InputStream stream = packageClient.fetch(id, version); String url = packageClient.url(id, version); return new InputStreamWithSrc(stream, url, version); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java index bf9bdac65..4415901af 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java @@ -39,6 +39,7 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.utilities.IniFile; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.cache.NpmPackage.NpmPackageFolder; import org.hl7.fhir.utilities.json.JSONUtil; import org.slf4j.Logger; @@ -283,7 +284,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple } /** - * Load the identified package from the cache - it it exists + * Load the identified package from the cache - if it exists *
* This is for special purpose only (testing, control over speed of loading).
* Generally, use the loadPackage method
@@ -307,10 +308,22 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
return p;
}
}
+ String foundPackage = null;
+ String foundVersion = null;
for (String f : sorted(new File(cacheFolder).list())) {
if (f.equals(id + "#" + version) || (Utilities.noString(version) && f.startsWith(id + "#"))) {
return loadPackageInfo(Utilities.path(cacheFolder, f));
}
+ if (version!=null && version.endsWith(".x") && f.contains("#")) {
+ String[] parts = f.split("#");
+ if (parts[0].equals(id) && VersionUtilities.isMajMinOrLaterPatch((foundVersion!=null ? foundVersion : version),parts[1])) {
+ foundVersion = parts[1];
+ foundPackage = f;
+ }
+ }
+ }
+ if (foundPackage!=null) {
+ return loadPackageInfo(Utilities.path(cacheFolder, foundPackage));
}
if ("dev".equals(version))
return loadPackageFromCacheOnly(id, "current");
diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageClient.java
index ac1457b08..16e92ae7b 100644
--- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageClient.java
+++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/PackageClient.java
@@ -208,5 +208,19 @@ public class PackageClient {
}
}
+ public String getLatestVersion(String id, String majMinVersion) throws IOException {
+ List