Merge remote-tracking branch 'origin/master'

This commit is contained in:
Grahame Grieve 2022-10-01 02:38:17 +10:00
commit 7950ded6e4
4 changed files with 61 additions and 2 deletions

View File

@ -1,7 +1,7 @@
## Validator Changes
* no changes
* Warning in Validator CLI when character encoding is not UTF-8
## Other code changes
* no changes
* no changes

View File

@ -0,0 +1,21 @@
package org.hl7.fhir.utilities;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class FileFormat {
public static boolean fileEncodingIsUtf8() {
return Charset.defaultCharset().equals(StandardCharsets.UTF_8);
}
public static void checkCharsetAndWarnIfNotUTF8(PrintStream out) {
if (fileEncodingIsUtf8()) return;
out.println("");
out.println("WARNING: Default file encoding is " + Charset.defaultCharset() + " which may cause unexpected results. ");
out.println(" To fix this issue, run this program with the parameter '-Dfile.encoding=UTF-8'");
out.println(" Future releases may not be able to run at all with encoding " + Charset.defaultCharset());
out.println("");
}
}

View File

@ -0,0 +1,35 @@
package org.hl7.fhir.utilities;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
public class FileFormatTest {
@Test
public void testCurrentFileFormat() throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
FileFormat.checkCharsetAndWarnIfNotUTF8(new PrintStream(bo));
bo.flush();
String allWrittenLines = new String(bo.toByteArray());
assertAWarningIsGivenWhenNotUTF8(allWrittenLines);
}
private static void assertAWarningIsGivenWhenNotUTF8(String allWrittenLines) {
if (Charset.defaultCharset().equals(StandardCharsets.UTF_8)) {
assertEquals(0, allWrittenLines.length());
} else {
assertThat(allWrittenLines, containsString("WARNING"));
}
}
}

View File

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.terminologies.JurisdictionUtilities;
import org.hl7.fhir.utilities.FileFormat;
import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
@ -154,6 +155,8 @@ public class ValidatorCli {
CliContext cliContext = Params.loadCliContext(args);
FileFormat.checkCharsetAndWarnIfNotUTF8(System.out);
if (shouldDisplayHelpToUser(args)) {
Display.displayHelpDetails();
} else if (Params.hasParam(args, Params.COMPARE)) {