From fb36294330d522cc63d2bade1d102909b6048d9b Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 16 Mar 2021 13:43:35 -0400 Subject: [PATCH] Add fhirVersions to package creator, auto-selected by --fhir-version --- .../java/ca/uhn/fhir/cli/CreatePackageCommand.java | 13 +++++++++++-- .../ca/uhn/fhir/cli/CreatePackageCommandTest.java | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java index 7077427e0ae..de0ea9f5e16 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java @@ -24,6 +24,8 @@ import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import com.google.common.io.Files; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -37,7 +39,6 @@ import org.hl7.fhir.utilities.npm.PackageGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.print.attribute.standard.MediaSize; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -67,7 +68,7 @@ public class CreatePackageCommand extends BaseCommand { @Override public String getCommandDescription() { - return "Create an NPM package using the FHIR packging format"; + return "Create an NPM package using the FHIR packaging format"; } @Override @@ -129,6 +130,7 @@ public class CreatePackageCommand extends BaseCommand { manifestGenerator.name(myPackageName); manifestGenerator.version(myPackageVersion); manifestGenerator.description(myPackageDescription); + injectFhirVersionsArray(manifestGenerator); if (isNotBlank(myPackageDescription)) { manifestGenerator.description(myPackageDescription); } @@ -177,6 +179,13 @@ public class CreatePackageCommand extends BaseCommand { } } + private void injectFhirVersionsArray(PackageGenerator manifestGenerator) { + JsonObject rootJsonObject = manifestGenerator.getRootJsonObject(); + JsonArray fhirVersionsArray = new JsonArray(); + fhirVersionsArray.add(myFhirCtx.getVersion().getVersion().getFhirVersionString()); + rootJsonObject.add("fhirVersions", fhirVersionsArray); + } + public void addFiles(String[] thePackageValues, String theFolder) throws ParseException, ExecutionException { if (thePackageValues != null) { for (String nextPackageValue : thePackageValues) { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java index fe326f35e67..306230a6a31 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java @@ -101,6 +101,9 @@ public class CreatePackageCommandTest extends BaseTest { String expectedPackageJson = "{\n" + " \"name\": \"com.example.ig\",\n" + " \"version\": \"1.0.1\",\n" + + " \"fhirVersions\": [\n" + + " \"4.0.1\"\n" + + " ],\n" + " \"dependencies\": {\n" + " \"hl7.fhir.core\": \"4.0.1\",\n" + " \"foo.bar\": \"1.2.3\"\n" + @@ -111,7 +114,6 @@ public class CreatePackageCommandTest extends BaseTest { // Try parsing the module again to make sure we can NpmPackage loadedPackage = NpmPackage.fromPackage(new FileInputStream(igArchive)); assertEquals("com.example.ig", loadedPackage.name()); - } @Test