Merge pull request #713 from hapifhir/dotasek-missing-constants-in-cli-help

Fix literal inclusion of Java constants in static text file in cli help
This commit is contained in:
dotasek 2022-01-17 12:08:42 -05:00 committed by GitHub
commit 4c66dbaca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 7 deletions

View File

@ -0,0 +1,7 @@
## Validator Changes
* fix inclusion of Java constants in CLI help text.
## Other code changes
n/a

View File

@ -134,7 +134,7 @@ public class VersionUtilities {
}
public static String listSupportedVersions() {
return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, "+CURRENT_FULL_VERSION;
return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, " + CURRENT_FULL_VERSION;
}
public static boolean isR5Ver(String ver) {

View File

@ -235,6 +235,24 @@
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven_surefire_version}</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes combine.children="override">
<exclude>org/hl7/fhir/validation/cli/services/ValidationServiceTest.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>

View File

@ -2,12 +2,16 @@ package org.hl7.fhir.validation.cli.utils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
/**
* Class for displaying output to the cli user.
@ -16,6 +20,7 @@ import java.io.InputStream;
*/
public class Display {
private static String toMB(long maxMemory) {
return Long.toString(maxMemory / (1024 * 1024));
}
@ -29,6 +34,29 @@ public class Display {
System.out.println();
}
final static String CURLY_START = "\\{\\{";
final static String CURLY_END = "\\}\\}";
final static String getMoustacheString(final String string) {
return CURLY_START + string + CURLY_END;
}
final static String[][] PLACEHOLDERS = {
{ getMoustacheString("XML_AND_JSON_FHIR_VERSIONS"), "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM },
{ getMoustacheString("TURTLE_FHIR_VERSIONS"), "3.0, 4.0, " + Constants.VERSION_MM },
{ getMoustacheString("FHIR_MAJOR_VERSIONS"), "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION},
{ getMoustacheString("FHIR_MINOR_VERSIONS"), "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION },
{ getMoustacheString("FHIR_CURRENT_VERSION"), VersionUtilities.CURRENT_VERSION},
};
final static String replacePlaceholders(final String input, final String[][] placeholders) {
String output = input;
for (String[] placeholder : placeholders) {
output = output.replaceAll(placeholder[0], placeholder[1]);
}
return output;
}
/**
* Loads the help details from resources/help.txt, and displays them on the command line to the user.
*/
@ -37,12 +65,15 @@ public class Display {
InputStream help = classLoader.getResourceAsStream("help.txt");
try {
String data = IOUtils.toString(help, "UTF-8");
System.out.println(data);
System.out.println(replacePlaceholders(data, PLACEHOLDERS));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Prints out system info to the command line.
*/

View File

@ -6,8 +6,8 @@ command line
The FHIR validation tool validates a FHIR resource or bundle.
Schema and schematron checking is performed, then some additional checks are performed.
* XML & Json (FHIR versions 1.0, 1.4, 3.0, 4.0, " + Constants.VERSION_MM + ")
* Turtle (FHIR versions 3.0, 4.0, " + Constants.VERSION_MM + ")
* XML & Json (FHIR versions {{XML_AND_JSON_FHIR_VERSIONS}})
* Turtle (FHIR versions {{TURTLE_FHIR_VERSIONS}})
If requested, instances will also be verified against the appropriate schema
W3C XML Schema, JSON schema or ShEx, as appropriate
@ -22,8 +22,8 @@ The following parameters are supported:
Patterns are limited to a directory followed by a filename with an embedded
asterisk. E.g. foo*-examples.xml or someresource.*, etc.
-version [ver]: The FHIR version to use. This can only appear once.
valid values 1.0 | 1.4 | 3.0 | " + VersionUtilities.CURRENT_VERSION + " or 1.0.2 | 1.4.0 | 3.0.2 | 4.0.1 | " + VersionUtilities.CURRENT_FULL_VERSION);
Default value is " + VersionUtilities.CURRENT_VERSION);
valid values {{FHIR_MAJOR_VERSIONS}} or {{FHIR_MINOR_VERSIONS}}
Default value is {{FHIR_CURRENT_VERSION}}
-ig [package|file|folder|url]: an IG or profile definition to load. Can be
the URL of an implementation guide or a package ([id]-[ver]) for
a built implementation guide or a local folder that contains a
@ -48,7 +48,7 @@ The following parameters are supported:
-showReferenceMessages
Includes validation messages resulting from validating target resources
against profiles defined on a reference. This increases the volume of
validationmessages, but may allow easier debugging. If not specified,
validation messages, but may allow easier debugging. If not specified,
then only a high-level message indicating that the referenced item wasn't
valid against the listed profile(s) will be provided.
-questionnaire mode: what to do with when validating QuestionnaireResponse resources

View File

@ -0,0 +1,58 @@
package org.hl7.fhir.validation.cli.utils;
import org.hl7.fhir.validation.cli.utils.Display;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.*;
public class DisplayTests {
@Test
@DisplayName("Check for placeholder replacement in help output")
public void displayHelpDetails() {
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
final PrintStream originalOut = System.out;
final PrintStream originalErr = System.err;
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
try {
Display.displayHelpDetails();
String output = outContent.toString();
for (String[] placeHolder: Display.PLACEHOLDERS) {
assertTrue(output.contains(placeHolder[1]), placeHolder[1] + " is not contained in output:\n" + output);
assertFalse(output.contains(placeHolder[0]), placeHolder[0] + " found in output:\n" + output);
}
}
finally {
System.setOut(originalOut);
System.setErr(originalErr);
}
}
@Test
@DisplayName("Test replacePlaceholder base case")
public void testReplacePlaceholdersBaseCase() {
final String myTestString = "The {{DUMMY_A}} jumps over the {{DUMMY_B}}.";
final String[][] placeHolders = {
{ "\\{\\{DUMMY_A\\}\\}", "quick brown fox"},
{ "\\{\\{DUMMY_B\\}\\}", "lazy dog"},
};
final String expectedOutput = "The quick brown fox jumps over the lazy dog.";
final String output = Display.replacePlaceholders(myTestString, placeHolders);
assertEquals(expectedOutput, output);
}
}