mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
Resolve "Make report filenames customizable"
This commit is contained in:
parent
592a1e87da
commit
3f361bf48b
7 changed files with 104 additions and 9 deletions
|
|
@ -13,6 +13,7 @@ do not reflect actual schematron validation result
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- engine info contains version number of the validator (configurations can output this in the report for maintainance puposes)
|
- engine info contains version number of the validator (configurations can output this in the report for maintainance puposes)
|
||||||
|
- Options to customize serialized report file names (cmdline only) via `--report-prefix` and `--report-postfix`
|
||||||
|
|
||||||
## 1.3.0
|
## 1.3.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,12 @@ public class CommandLineApplication {
|
||||||
private static final Option DISABLE_GUI = Option.builder("G").longOpt("disable-gui").desc("Disables the GUI of the daemon mode")
|
private static final Option DISABLE_GUI = Option.builder("G").longOpt("disable-gui").desc("Disables the GUI of the daemon mode")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
private static final Option REPORT_POSTFIX = Option.builder(null).longOpt("report-postfix").hasArg()
|
||||||
|
.desc("Postfix of the generated report name").build();
|
||||||
|
|
||||||
|
private static final Option REPORT_PREFIX = Option.builder(null).longOpt("report-prefix").hasArg()
|
||||||
|
.desc("Prefix of the generated report name").build();
|
||||||
|
|
||||||
public static final int DAEMON_SIGNAL = 100;
|
public static final int DAEMON_SIGNAL = 100;
|
||||||
|
|
||||||
private static final Option PRINT_MEM_STATS = Option.builder("m").longOpt("memory-stats").desc("Prints some memory stats").build();
|
private static final Option PRINT_MEM_STATS = Option.builder("m").longOpt("memory-stats").desc("Prints some memory stats").build();
|
||||||
|
|
@ -173,7 +179,7 @@ public class CommandLineApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int startDaemonMode(final CommandLine cmd) {
|
private static int startDaemonMode(final CommandLine cmd) {
|
||||||
final Option[] unavailable = new Option[] { PRINT, CHECK_ASSERTIONS, DEBUG, OUTPUT, EXTRACT_HTML };
|
final Option[] unavailable = new Option[] { PRINT, CHECK_ASSERTIONS, DEBUG, OUTPUT, EXTRACT_HTML, REPORT_POSTFIX, REPORT_PREFIX };
|
||||||
warnUnusedOptions(cmd, unavailable, true);
|
warnUnusedOptions(cmd, unavailable, true);
|
||||||
final ConfigurationLoader config = Configuration.load(determineDefinition(cmd), determineRepository(cmd));
|
final ConfigurationLoader config = Configuration.load(determineDefinition(cmd), determineRepository(cmd));
|
||||||
final Daemon validDaemon = new Daemon(determineHost(cmd), determinePort(cmd), determineThreads(cmd));
|
final Daemon validDaemon = new Daemon(determineHost(cmd), determinePort(cmd), determineThreads(cmd));
|
||||||
|
|
@ -210,7 +216,7 @@ public class CommandLineApplication {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
final Option[] unavailable = new Option[] { HOST, PORT, WORKER_COUNT };
|
final Option[] unavailable = new Option[] { HOST, PORT, WORKER_COUNT, DISABLE_GUI };
|
||||||
warnUnusedOptions(cmd, unavailable, false);
|
warnUnusedOptions(cmd, unavailable, false);
|
||||||
final Configuration config = Configuration.load(determineDefinition(cmd), determineRepository(cmd)).build();
|
final Configuration config = Configuration.load(determineDefinition(cmd), determineRepository(cmd)).build();
|
||||||
|
|
||||||
|
|
@ -221,7 +227,7 @@ public class CommandLineApplication {
|
||||||
if (cmd.hasOption(EXTRACT_HTML.getOpt())) {
|
if (cmd.hasOption(EXTRACT_HTML.getOpt())) {
|
||||||
check.getCheckSteps().add(new ExtractHtmlContentAction(processor, outputDirectory));
|
check.getCheckSteps().add(new ExtractHtmlContentAction(processor, outputDirectory));
|
||||||
}
|
}
|
||||||
check.getCheckSteps().add(new SerializeReportAction(outputDirectory, processor));
|
check.getCheckSteps().add(new SerializeReportAction(outputDirectory, processor, determineNamingStrategy(cmd)));
|
||||||
if (cmd.hasOption(SERIALIZE_REPORT_INPUT.getOpt())) {
|
if (cmd.hasOption(SERIALIZE_REPORT_INPUT.getOpt())) {
|
||||||
check.getCheckSteps().add(new SerializeReportInputAction(outputDirectory, check.getConversionService()));
|
check.getCheckSteps().add(new SerializeReportInputAction(outputDirectory, check.getConversionService()));
|
||||||
}
|
}
|
||||||
|
|
@ -260,6 +266,18 @@ public class CommandLineApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static NamingStrategy determineNamingStrategy(final CommandLine cmd) {
|
||||||
|
final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
|
||||||
|
if (cmd.hasOption(REPORT_PREFIX.getLongOpt())) {
|
||||||
|
namingStrategy.setPrefix(cmd.getOptionValue(REPORT_PREFIX.getLongOpt()));
|
||||||
|
}
|
||||||
|
if (cmd.hasOption(REPORT_POSTFIX.getLongOpt())) {
|
||||||
|
namingStrategy.setPostfix(cmd.getOptionValue(REPORT_POSTFIX.getLongOpt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return namingStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
private static Assertions loadAssertions(final String optionValue) {
|
private static Assertions loadAssertions(final String optionValue) {
|
||||||
final Path p = Paths.get(optionValue);
|
final Path p = Paths.get(optionValue);
|
||||||
Assertions a = null;
|
Assertions a = null;
|
||||||
|
|
@ -385,6 +403,8 @@ public class CommandLineApplication {
|
||||||
options.addOption(PRINT_MEM_STATS);
|
options.addOption(PRINT_MEM_STATS);
|
||||||
options.addOption(WORKER_COUNT);
|
options.addOption(WORKER_COUNT);
|
||||||
options.addOption(DISABLE_GUI);
|
options.addOption(DISABLE_GUI);
|
||||||
|
options.addOption(REPORT_POSTFIX);
|
||||||
|
options.addOption(REPORT_PREFIX);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A default {@link NamingStrategy} supporting prefix and postfix configurations for generating report names
|
||||||
|
*
|
||||||
|
* @author Andreas Penski
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
|
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
private String postfix = "report";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createName(final String base) {
|
||||||
|
if (StringUtils.isEmpty(base)) {
|
||||||
|
throw new IllegalArgumentException("Can not generate name based on null input");
|
||||||
|
}
|
||||||
|
final int index = base.lastIndexOf(".");
|
||||||
|
final StringBuilder result = new StringBuilder();
|
||||||
|
if (isNotEmpty(this.prefix)) {
|
||||||
|
result.append(this.prefix).append("-");
|
||||||
|
}
|
||||||
|
result.append(base, 0, index > 0 ? index : base.length());
|
||||||
|
if (isNotEmpty(this.postfix)) {
|
||||||
|
result.append("-").append(this.postfix);
|
||||||
|
}
|
||||||
|
if (index > 0) {
|
||||||
|
result.append(base.substring(index));
|
||||||
|
} else {
|
||||||
|
result.append(".xml");
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strategy for creating names. This is used for generating the report result name.
|
||||||
|
*
|
||||||
|
* @author Andreas Penski
|
||||||
|
*/
|
||||||
|
public interface NamingStrategy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a name based on a base name
|
||||||
|
*
|
||||||
|
* @param base the base name
|
||||||
|
* @return the generated name
|
||||||
|
*/
|
||||||
|
String createName(String base);
|
||||||
|
}
|
||||||
|
|
@ -43,20 +43,22 @@ class SerializeReportAction implements CheckAction {
|
||||||
|
|
||||||
private final Processor processor;
|
private final Processor processor;
|
||||||
|
|
||||||
|
private final NamingStrategy namingStrategy;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(Bag results) {
|
public void check(final Bag results) {
|
||||||
final Path file = outputDirectory.resolve(results.getName() + "-report.xml");
|
final Path file = this.outputDirectory.resolve(this.namingStrategy.createName(results.getName()));
|
||||||
try {
|
try {
|
||||||
log.info("Serializing result to {}", file.toAbsolutePath());
|
log.info("Serializing result to {}", file.toAbsolutePath());
|
||||||
final Serializer serializer = processor.newSerializer(file.toFile());
|
final Serializer serializer = this.processor.newSerializer(file.toFile());
|
||||||
serializer.serializeNode(results.getReport());
|
serializer.serializeNode(results.getReport());
|
||||||
} catch (SaxonApiException e) {
|
} catch (final SaxonApiException e) {
|
||||||
log.error("Can not serialize result report to {}", file.toAbsolutePath(), e);
|
log.error("Can not serialize result report to {}", file.toAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSkipped(Bag results) {
|
public boolean isSkipped(final Bag results) {
|
||||||
if (results.getReport() == null) {
|
if (results.getReport() == null) {
|
||||||
log.warn("Can not serialize result report. No document found");
|
log.warn("Can not serialize result report. No document found");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,16 @@ public class CommandlineApplicationTest {
|
||||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidNamingConfiguration() {
|
||||||
|
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||||
|
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), "--report-prefix", "somePrefix",
|
||||||
|
"--report-postfix", "somePostfix" };
|
||||||
|
CommandLineApplication.mainProgram(args);
|
||||||
|
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||||
|
assertThat(this.commandLine.getErrorOutput()).contains("somePrefix-simple-somePostfix");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidMultipleInput() {
|
public void testValidMultipleInput() {
|
||||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
|
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ public class SerializeReportActionTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
this.tmpDirectory = Files.createTempDirectory("checktool");
|
this.tmpDirectory = Files.createTempDirectory("checktool");
|
||||||
this.action = new SerializeReportAction(this.tmpDirectory, TestObjectFactory.createProcessor());
|
final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
|
||||||
|
this.action = new SerializeReportAction(this.tmpDirectory, TestObjectFactory.createProcessor(), namingStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue