check for latest version of package

This commit is contained in:
Grahame Grieve 2021-09-04 04:41:39 +10:00
parent f8268442d1
commit 4a8d626ab9
2 changed files with 24 additions and 7 deletions

View File

@ -228,11 +228,14 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
public String getLatestVersion(String id) throws IOException {
for (String nextPackageServer : getPackageServers()) {
CachingPackageClient pc = new CachingPackageClient(nextPackageServer);
try {
return pc.getLatestVersion(id);
} catch (IOException e) {
ourLog.info("Failed to determine latest version of package {} from server: {}", id, nextPackageServer);
// special case:
if (!("hl7.fhir.pubpack".equals(id) && PRIMARY_SERVER.equals(nextPackageServer))) {
CachingPackageClient pc = new CachingPackageClient(nextPackageServer);
try {
return pc.getLatestVersion(id);
} catch (IOException e) {
ourLog.info("Failed to determine latest version of package {} from server: {}", id, nextPackageServer);
}
}
}
@ -474,6 +477,13 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
id = id.substring(0, id.indexOf("#"));
}
if (version == null) {
try {
version = getLatestVersion(id);
} catch (Exception e) {
version = null;
}
}
NpmPackage p = loadPackageFromCacheOnly(id, version);
if (p != null) {
if ("current".equals(version)) {

View File

@ -53,7 +53,14 @@ public class PackageCacheTests {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
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");
Assertions.assertEquals(cache.loadPackage("kbv.basis", "1.1.3").version(), "1.1.3");
}
@Test
public void testLastReleasedVersion() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
cache.clear();
Assertions.assertEquals("0.0.8", cache.loadPackage("hl7.fhir.pubpack", "0.0.8").version());
Assertions.assertEquals("0.0.9", cache.loadPackage("hl7.fhir.pubpack").version());
}
}