support for -show-times in validator

This commit is contained in:
Grahame Grieve 2020-07-14 08:19:11 +10:00
parent fa7de3a308
commit 64d6f24d08
5 changed files with 43 additions and 3 deletions

View File

@ -267,6 +267,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
private boolean crumbTrails;
private Locale locale;
private List<ImplementationGuide> igs = new ArrayList<>();
private boolean showTimes;
private class AsteriskFilter implements FilenameFilter {
String dir;
@ -329,6 +330,15 @@ public class ValidationEngine implements IValidatorResourceFetcher {
this.anyExtensionsAllowed = anyExtensionsAllowed;
}
public boolean isShowTimes() {
return showTimes;
}
public void setShowTimes(boolean showTimes) {
this.showTimes = showTimes;
}
public ValidationEngine(String src, String txsrvr, String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, String vString) throws Exception {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
loadCoreDefinitions(src, false);
@ -1114,6 +1124,9 @@ public class ValidationEngine implements IValidatorResourceFetcher {
}
InstanceValidator validator = getValidator();
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
if (showTimes) {
System.out.println(location+": "+validator.reportTimes());
}
return messagesToOutcome(messages);
}
@ -2113,5 +2126,13 @@ public class ValidationEngine implements IValidatorResourceFetcher {
URLConnection c = url.openConnection();
return TextFile.streamToBytes(c.getInputStream());
}
public void doneLoading(long loadStart) {
if (showTimes) {
String s = String.format("Load Time (ms): %d", (System.nanoTime() - loadStart) / 1000000);
System.out.println(s);
}
}
}

View File

@ -131,6 +131,7 @@ public class Validator {
public static void main(String[] args) throws Exception {
long loadStart = System.nanoTime();
System.out.println("FHIR Validation tool " + VersionUtil.getVersionString());
System.out.println("Detected Java version: " + System.getProperty("java.version") + " from " + System.getProperty("java.home") + " on " + System.getProperty("os.arch") + " (" + System.getProperty("sun.arch.data.model") + "bit). " + toMB(Runtime.getRuntime().maxMemory()) + "MB available");
String proxy = getNamedParam(args, Params.PROXY);
@ -199,7 +200,7 @@ public class Validator {
if (cliContext.getMode() == EngineMode.SCAN) {
ValidationService.validateScan(cliContext, validator);
} else {
ValidationService.validateSources(cliContext, validator);
ValidationService.validateSources(cliContext, validator, loadStart);
}
}
}

View File

@ -68,6 +68,9 @@ public class CliContext {
@JsonProperty("crumbTrails")
private boolean crumbTrails = false;
@JsonProperty("showTimes")
private boolean showTimes = false;
@JsonProperty("locale")
private String locale = Locale.ENGLISH.getDisplayLanguage();
@ -436,6 +439,14 @@ public class CliContext {
this.crumbTrails = crumbTrails;
}
public boolean isShowTimes() {
return showTimes;
}
public void setShowTimes(boolean showTimes) {
this.showTimes = showTimes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -464,6 +475,8 @@ public class CliContext {
Objects.equals(questionnaires, that.questionnaires) &&
Objects.equals(profiles, that.profiles) &&
Objects.equals(sources, that.sources) &&
Objects.equals(crumbTrails, that.crumbTrails) &&
Objects.equals(showTimes, that.showTimes) &&
mode == that.mode &&
Objects.equals(locale, that.locale) &&
Objects.equals(locations, that.locations);
@ -471,6 +484,6 @@ public class CliContext {
@Override
public int hashCode() {
return Objects.hash(doNative, anyExtensionsAllowed, hintAboutNonMustSupport, recursive, doDebug, assumeValidRestReferences, canDoNative, noInternalCaching, noExtensibleBindingMessages, map, output, txServer, sv, txLog, mapLog, lang, fhirpath, snomedCT, targetVer, igs, questionnaires, profiles, sources, mode, locale, locations);
return Objects.hash(doNative, anyExtensionsAllowed, hintAboutNonMustSupport, recursive, doDebug, assumeValidRestReferences, canDoNative, noInternalCaching, noExtensibleBindingMessages, map, output, txServer, sv, txLog, mapLog, lang, fhirpath, snomedCT, targetVer, igs, questionnaires, profiles, sources, mode, locale, locations, crumbTrails, showTimes);
}
}

View File

@ -44,7 +44,8 @@ public class ValidationService {
return response;
}
public static void validateSources(CliContext cliContext, ValidationEngine validator) throws Exception {
public static void validateSources(CliContext cliContext, ValidationEngine validator, long loadStart) throws Exception {
validator.doneLoading(loadStart);
if (cliContext.getProfiles().size() > 0) {
System.out.println(" .. validate " + cliContext.getSources() + " against " + cliContext.getProfiles().toString());
} else {
@ -195,6 +196,7 @@ public class ValidationService {
validator.setNoExtensibleBindingMessages(cliContext.isNoExtensibleBindingMessages());
validator.setSecurityChecks(cliContext.isSecurityChecks());
validator.setCrumbTrails(cliContext.isCrumbTrails());
validator.setShowTimes(cliContext.isShowTimes());
TerminologyCache.setNoCaching(cliContext.isNoInternalCaching());
return validator;
}

View File

@ -51,6 +51,7 @@ public class Params {
public static final String NO_EXTENSIBLE_BINDING_WARNINGS = "-no-extensible-binding-warnings";
public static final String SECURITY_CHECKS = "-security-checks";
public static final String CRUMB_TRAIL = "-crumb-trails";
public static final String SHOW_TIMES = "-show-times";
/**
* Checks the list of passed in params to see if it contains the passed in param.
@ -157,6 +158,8 @@ public class Params {
cliContext.setSecurityChecks(true);
} else if (args[i].equals(CRUMB_TRAIL)) {
cliContext.setCrumbTrails(true);
} else if (args[i].equals(SHOW_TIMES)) {
cliContext.setShowTimes(true);
} else if (args[i].equals(SCAN)) {
cliContext.setMode(Validator.EngineMode.SCAN);
} else if (args[i].equals(TERMINOLOGY)) {