Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patch wildcard for ig dependencies #340

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ public static String getMajMin(String version) {
}
}

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;
Expand All @@ -202,7 +212,7 @@ public static boolean isSemVer(String version) {
}

/**
* 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))...
*
Expand All @@ -213,10 +223,36 @@ public static boolean isSemVer(String version) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ protected InputStreamWithSrc loadFromPackageServer(String id, String version) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
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;
Expand Down Expand Up @@ -283,7 +284,7 @@ public void removePackage(String id, String ver) throws IOException {
}

/**
* Load the identified package from the cache - it it exists
* Load the identified package from the cache - if it exists
* <p>
* This is for special purpose only (testing, control over speed of loading).
* Generally, use the loadPackage method
Expand All @@ -307,10 +308,22 @@ public NpmPackage loadPackageFromCacheOnly(String id, String version) throws IOE
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,19 @@ public String getLatestVersion(String id) throws IOException {
}
}

public String getLatestVersion(String id, String majMinVersion) throws IOException {
List<PackageInfo> list = getVersions(id);
if (list.isEmpty()) {
throw new IOException("Package not found: "+id);
} else {
String v = majMinVersion;
for (PackageInfo p : list) {
if (VersionUtilities.isMajMinOrLaterPatch(v, p.version)) {
v = p.version;
}
}
return v;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,18 @@ public Map<String, byte[]> loadPackage(NpmPackage pi) throws FHIRException, IOEx
context.getLoadedPackages().add(pi.name()+"#"+pi.version());
Map<String, byte[]> res = new HashMap<String, byte[]>();
for (String s : pi.dependencies()) {
if (s.endsWith(".x") && s.length()>2) {
String packageMajorMinor = s.substring(0, s.length()-2);
boolean found = false;
for (int i=0; i<context.getLoadedPackages().size() && !found; ++i) {
String loadedPackage = context.getLoadedPackages().get(i);
if (loadedPackage.startsWith(packageMajorMinor)) {
found = true;
}
}
if (found)
continue ;
}
if (! context.getLoadedPackages().contains(s)) {
if (!VersionUtilities.isCorePackage(s)) {
System.out.println("+ .. load IG from "+s);
Expand Down