res = new ArrayList<>();
if (folder != null) {
- for (File f : folder.listFiles()) {
- if (!f.isDirectory() && !Utilities.existsInList(f.getName(), "package.json", ".index.json", ".index.db", ".oids.json", ".oids.db")) {
- res.add(f.getName());
+ if (folder.exists()) {
+ for (File f : folder.listFiles()) {
+ if (!f.isDirectory() && !Utilities.existsInList(f.getName(), "package.json", ".index.json", ".index.db", ".oids.json", ".oids.db")) {
+ res.add(f.getName());
+ }
}
}
} else {
@@ -648,7 +650,17 @@ public class NpmPackage {
}
-
+ /**
+ * Create a package .index.json file for a package folder.
+ *
+ * See the FHIR specification for details on .index.json
+ * format and usage.
+ *
+ * @param desc
+ * @param folder
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
public void indexFolder(String desc, NpmPackageFolder folder) throws FileNotFoundException, IOException {
List remove = new ArrayList<>();
NpmPackageIndexBuilder indexer = new NpmPackageIndexBuilder();
diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java
index 6aba70e60..225bdd409 100644
--- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java
+++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java
@@ -30,61 +30,74 @@ public class PackageHacker {
private static boolean useSecureReferences = false;
public static void main(String[] args) throws FileNotFoundException, IOException {
- new PackageHacker().massEdit(new File("/Users/grahamegrieve/web/hl7.org/fhir"));
- // new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/us/vitals/2020Sep/package.tgz");
+// new PackageHacker().massEdit(new File("/Users/grahamegrieve/web/hl7.org/fhir"));
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.core.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.corexml.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.examples.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.expansions.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.search.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.core.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.corexml.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.examples.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.expansions.tgz");
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.search.tgz");
+
+// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/us/core/v311/package.tgz", "http://hl7.org/fhir/us/core/STU3.1.1");
+ new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/us/core/v700/package.tgz", "http://hl7.org/fhir/us/core/STU7");
}
- private void massEdit(File dir) throws IOException {
- System.out.println("process "+dir.getAbsolutePath());
- for (File f : dir.listFiles()) {
- if (f.isDirectory()) {
- massEdit(f);
- } else if (f.getName().equals("package.tgz")) {
- try {
- FileInputStream fs = ManagedFileAccess.inStream(f);
- NpmPackage pck = NpmPackage.fromPackage(fs);
- if ("fhir.core".equals(pck.getNpm().str("type"))) {
- System.out.println("!!change "+f.getAbsolutePath());
- pck.getNpm().remove("type");
- pck.getNpm().set("type", "Core");
- FileOutputStream fso = ManagedFileAccess.outStream(f);
- try {
- pck.save(fso);
- } finally {
- fso.close();
- }
- }
- } catch (Exception e) {
- System.out.println("!!Error: "+e.getMessage());
- }
- } else if (f.getName().startsWith("hl7.fhir.r") && f.getName().endsWith(".examples.tgz")) {
- try {
- FileInputStream fs = ManagedFileAccess.inStream(f);
- NpmPackage pck = NpmPackage.fromPackage(fs);
- if ("fhir.examples".equals(pck.getNpm().str("type"))) {
- System.out.println("!!change "+f.getAbsolutePath());
- pck.getNpm().remove("type");
- pck.getNpm().set("type", "Examples");
- FileOutputStream fso = ManagedFileAccess.outStream(f);
- try {
- pck.save(fso);
- } finally {
- fso.close();
- }
- }
- } catch (Exception e) {
- System.out.println("!!Error: "+e.getMessage());
- }
+// private void massEdit(File dir) throws IOException {
+// System.out.println("process "+dir.getAbsolutePath());
+// for (File f : dir.listFiles()) {
+// if (f.isDirectory()) {
+// massEdit(f);
+// } else if (f.getName().equals("package.tgz")) {
+// try {
+// FileInputStream fs = ManagedFileAccess.inStream(f);
+// NpmPackage pck = NpmPackage.fromPackage(fs);
+// if ("fhir.core".equals(pck.getNpm().str("type"))) {
+// System.out.println("!!change "+f.getAbsolutePath());
+// pck.getNpm().remove("type");
+// pck.getNpm().set("type", "Core");
+// FileOutputStream fso = ManagedFileAccess.outStream(f);
+// try {
+// pck.save(fso);
+// } finally {
+// fso.close();
+// }
+// }
+// } catch (Exception e) {
+// System.out.println("!!Error: "+e.getMessage());
+// }
+// } else if (f.getName().startsWith("hl7.fhir.r") && f.getName().endsWith(".examples.tgz")) {
+// try {
+// FileInputStream fs = ManagedFileAccess.inStream(f);
+// NpmPackage pck = NpmPackage.fromPackage(fs);
+// if ("fhir.examples".equals(pck.getNpm().str("type"))) {
+// System.out.println("!!change "+f.getAbsolutePath());
+// pck.getNpm().remove("type");
+// pck.getNpm().set("type", "Examples");
+// FileOutputStream fso = ManagedFileAccess.outStream(f);
+// try {
+// pck.save(fso);
+// } finally {
+// fso.close();
+// }
+// }
+// } catch (Exception e) {
+// System.out.println("!!Error: "+e.getMessage());
+// }
+//
+// }
+// }
+// }
- }
- }
- }
-
- private void edit(String name) throws FileNotFoundException, IOException {
+ private void edit(String name, String path) throws FileNotFoundException, IOException {
File f = ManagedFileAccess.file(name);
if (!f.exists())
throw new Error("Unable to find "+f.getAbsolutePath());
+ System.out.println("Loading Package "+f.getAbsolutePath());
NpmPackage pck = null;
FileInputStream fs = ManagedFileAccess.inStream(f);
try {
@@ -95,7 +108,7 @@ public class PackageHacker {
System.out.println("Altering Package "+f.getAbsolutePath());
System.out.println(nice(pck.getNpm()));
- change(pck.getNpm());
+ if (change(pck.getNpm(), path)) {
System.out.println("Revised Package");
System.out.println("=======================");
@@ -111,7 +124,8 @@ public class PackageHacker {
} finally {
fso.close();
}
- }
+ }
+ }
}
private void fixExampleContent(Map content) {
@@ -129,10 +143,15 @@ public class PackageHacker {
return JsonParser.compose(json, true);
}
- private void change(JsonObject npm) throws FileNotFoundException, IOException {
- // fixVersions(npm, ver);
- npm.remove("notForPublication");
- npm.set("name", "hl7.fhir.us.vitals");
+ private boolean change(JsonObject npm, String path) throws FileNotFoundException, IOException {
+ npm.remove("url");
+ npm.add("url", path);
+ return true;
+// if (npm.has("notForPublication")) {
+// npm.remove("notForPublication");
+// return true;
+// }
+// return false;
}
private void fixVersionInContent(Map content) {
diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java
index 9fc5f29ff..b4cb4bc5d 100644
--- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java
+++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/HierarchicalTableGenerator.java
@@ -560,7 +560,6 @@ public class HierarchicalTableGenerator {
}
return b.toString();
}
-
}
public class TableModel {
diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties
index bae41d4af..35811c33e 100644
--- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties
+++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties
@@ -1140,4 +1140,6 @@ XHTML_XHTML_ATTRIBUTE_XML_SPACE = The attribute 'xml:space' is legal but has a f
VALIDATION_HL7_PUBLISHER_MULTIPLE_WGS = This resource has more than workgroup extension (http://hl7.org/fhir/StructureDefinition/structuredefinition-wg)
NO_VALID_DISPLAY_FOUND_NONE_FOR_LANG = Wrong Display Name ''{0}'' for {1}#{2}. There are no valid display names found for language(s) ''{3}''. Default display is ''{4}''
NO_VALID_DISPLAY_AT_ALL = Cannot validate display Name ''{0}'' for {1}#{2}: No displays are known
-
+SD_BASE_EXPERIMENTAL = The definition builds on ''{0}'' which is experimental, but this definition is not labeled as experimental
+SD_ED_EXPERIMENTAL_BINDING = The definition for the element ''{0}'' binds to the value set ''{1}'' which is experimental, but this structure is not labeled as experimental
+VALIDATION_NO_EXPERIMENTAL_CONTENT = Experimental content is not allowed in this context
diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java
index 96754c2b8..eba7b198a 100644
--- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java
+++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java
@@ -1,22 +1,25 @@
package org.hl7.fhir.utilities.npm;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
+import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
-import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
@@ -100,7 +103,6 @@ public class FilesystemPackageManagerTests {
@DisabledOnOs(OS.WINDOWS)
public void testSystemCacheDirectory() throws IOException {
File folder = new FilesystemPackageCacheManager.Builder().withSystemCacheFolder().getCacheFolder();
-
assertEquals( "/var/lib/.fhir/packages", folder.getAbsolutePath());
}
@@ -124,6 +126,118 @@ public class FilesystemPackageManagerTests {
return params.stream();
}
+ private void createDummyTemp(File cacheDirectory, String lowerCase) throws IOException {
+ createDummyPackage(cacheDirectory, lowerCase);
+ }
+
+ private void createDummyPackage(File cacheDirectory, String packageName, String packageVersion) throws IOException {
+ String directoryName = packageName + "#" + packageVersion;
+ createDummyPackage(cacheDirectory, directoryName);
+ }
+
+ private static void createDummyPackage(File cacheDirectory, String directoryName) throws IOException {
+ File packageDirectory = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), directoryName);
+ packageDirectory.mkdirs();
+
+ File dummyContentFile = ManagedFileAccess.file(packageDirectory.getAbsolutePath(), "dummy.txt");
+ FileWriter wr = new FileWriter(dummyContentFile);
+ wr.write("Ain't nobody here but us chickens");
+ wr.flush();
+ wr.close();
+ }
+
+ private void assertThatDummyTempExists(File cacheDirectory, String dummyTempPackage) throws IOException {
+ File dummyTempDirectory = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), dummyTempPackage);
+ assertThat(dummyTempDirectory).exists();
+
+ File dummyContentFile = ManagedFileAccess.file(dummyTempDirectory.getAbsolutePath(), "dummy.txt");
+ assertThat(dummyContentFile).exists();
+ }
+
+ @Test
+ public void testCreatesIniIfDoesntExistAndCacheStaysIntact() throws IOException {
+ File cacheDirectory = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-multithreadingTest"));
+ File cacheIni = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "packages.ini");
+
+ createDummyPackage(cacheDirectory, "example.fhir.uv.myig", "1.2.3");
+
+ String dummyTempPackage = UUID.randomUUID().toString().toLowerCase();
+ createDummyTemp(cacheDirectory, dummyTempPackage);
+ assertThatDummyTempExists(cacheDirectory, dummyTempPackage);
+
+ assertThat(cacheIni).doesNotExist();
+ FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager.Builder().withCacheFolder(cacheDirectory.getAbsolutePath()).build();
+ assertInitializedTestCacheIsValid(cacheDirectory, true);
+ }
+
+
+
+ @Test
+ public void testClearsCacheIfVersionIsWrong() throws IOException {
+ File cacheDirectory = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-multithreadingTest"));
+ File cacheIni = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "packages.ini");
+
+ createDummyPackage(cacheDirectory, "example.fhir.uv.myig", "1.2.3");
+ String dummyTempPackage = UUID.randomUUID().toString().toLowerCase();
+ createDummyTemp(cacheDirectory, dummyTempPackage);
+ assertThatDummyTempExists(cacheDirectory, dummyTempPackage);
+
+
+ IniFile ini = new IniFile(cacheIni.getAbsolutePath());
+ ini.setStringProperty("cache", "version", "2", null);
+ ini.save();
+
+ assertThat(cacheIni).exists();
+ FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager.Builder().withCacheFolder(cacheDirectory.getAbsolutePath()).build();
+ assertInitializedTestCacheIsValid(cacheDirectory, false);
+ }
+
+ @Test
+ public void testCacheStaysIntactIfVersionIsTheSame() throws IOException {
+ File cacheDirectory = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-multithreadingTest"));
+ File cacheIni = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "packages.ini");
+
+ createDummyPackage(cacheDirectory, "example.fhir.uv.myig", "1.2.3");
+ String dummyTempPackage = UUID.randomUUID().toString().toLowerCase();
+ createDummyTemp(cacheDirectory, dummyTempPackage);
+ assertThatDummyTempExists(cacheDirectory, dummyTempPackage);
+
+
+ IniFile ini = new IniFile(cacheIni.getAbsolutePath());
+ ini.setStringProperty("cache", "version", "3", null);
+ ini.save();
+
+ assertThat(cacheIni).exists();
+ FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager.Builder().withCacheFolder(cacheDirectory.getAbsolutePath()).build();
+ assertInitializedTestCacheIsValid(cacheDirectory, true);
+ }
+
+ private void assertInitializedTestCacheIsValid(File cacheDirectory, boolean dummyPackageShouldExist) throws IOException {
+ assertThat(cacheDirectory).exists();
+ File iniFile = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "packages.ini");
+ assertThat(ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "packages.ini")).exists();
+ IniFile ini = new IniFile(iniFile.getAbsolutePath());
+ String version = ini.getStringProperty("cache", "version");
+ assertThat(version).isEqualTo("3");
+
+ File[] files = cacheDirectory.listFiles();
+ if (dummyPackageShouldExist) {
+ // Check that only packages.ini and our dummy package are in the cache. Our previous temp should be deleted.
+ assertThat(files).hasSize(2); // packages.ini and example.fhir.uv.myig#1.2.3 (directory)
+
+ File dummyPackage = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "example.fhir.uv.myig#1.2.3");
+ assertThat(dummyPackage).exists();
+
+ File dummyContentFile = ManagedFileAccess.file(dummyPackage.getAbsolutePath(), "dummy.txt");
+ assertThat(dummyContentFile).exists();
+ } else {
+ // Check that only packages.ini is in the cache.
+ assertThat(files).hasSize(1);
+ }
+
+
+ }
+
@MethodSource("packageCacheMultiThreadTestParams")
@ParameterizedTest
public void packageCacheMultiThreadTest(final int threadTotal, final int packageCacheManagerTotal) throws IOException {
diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml
index e6da91b3d..de8286041 100644
--- a/org.hl7.fhir.validation.cli/pom.xml
+++ b/org.hl7.fhir.validation.cli/pom.xml
@@ -5,7 +5,7 @@
ca.uhn.hapi.fhir
org.hl7.fhir.core
- 6.3.24-SNAPSHOT
+ 6.3.27-SNAPSHOT
../pom.xml
@@ -405,7 +405,7 @@
org.sonatype.plugins
nexus-staging-maven-plugin
- true
+ true