mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
#19 Sequentialisierung der Verarbeitung
Dateien werden erst gelesen, wenn sie verarbeitet werden. Ergebnisse von vorherigen Läufen werden nicht mehr Speicher gehalten bis alle Dateien verarbeitet sind
This commit is contained in:
parent
7992024451
commit
5e5f7df700
2 changed files with 28 additions and 28 deletions
|
|
@ -28,10 +28,15 @@ import java.nio.file.Paths;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -151,9 +156,12 @@ public class CommandLineApplication {
|
|||
|
||||
final Collection<Path> targets = determineTestTargets(cmd);
|
||||
start = System.currentTimeMillis();
|
||||
final List<Input> input = targets.stream().map(InputFactory::read).collect(Collectors.toList());
|
||||
boolean result = check.checkInput(input);
|
||||
log.info("Processing {} object(s) completed in {}ms", input.size(), System.currentTimeMillis() - start);
|
||||
for (Path p : targets) {
|
||||
final Input input = InputFactory.read(p);
|
||||
check.checkInput(input);
|
||||
}
|
||||
boolean result = check.printAndEvaluate();
|
||||
log.info("Processing {} object(s) completed in {}ms", targets.size(), System.currentTimeMillis() - start);
|
||||
return result ? 0 : 1;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -19,16 +19,12 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.impl.DefaultCheck;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Simple Erweiterung der Klasse {@link DefaultCheck} um das Ergebnis der Assertion-Prüfung auszwerten und auszugeben.
|
||||
|
|
@ -39,12 +35,16 @@ import java.util.stream.Collectors;
|
|||
@Slf4j
|
||||
class InternalCheck extends DefaultCheck {
|
||||
|
||||
private int checkAssertions = 0;
|
||||
|
||||
private int failedAssertions = 0;
|
||||
|
||||
/**
|
||||
* Erzeugt eine neue Instanz mit der angegebenen Konfiguration.
|
||||
*
|
||||
* @param configuration die Konfiguration
|
||||
*/
|
||||
public InternalCheck(CheckConfiguration configuration) {
|
||||
InternalCheck(CheckConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
|
|
@ -54,24 +54,16 @@ class InternalCheck extends DefaultCheck {
|
|||
* @param input die Prüflinge
|
||||
* @return false wenn es Assertion-Fehler gibt, sonst true
|
||||
*/
|
||||
public boolean checkInput(List<Input> input) {
|
||||
List<CheckAction.Bag> results = new ArrayList<>();
|
||||
input.forEach(i -> {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(i, createReport());
|
||||
runCheckInternal(bag);
|
||||
results.add(bag);
|
||||
});
|
||||
|
||||
return printAndEvaluate(results);
|
||||
|
||||
void checkInput(Input input) {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(input, createReport());
|
||||
runCheckInternal(bag);
|
||||
if (bag.getAssertionResult() != null) {
|
||||
checkAssertions += bag.getAssertionResult().getObject();
|
||||
failedAssertions += bag.getAssertionResult().getErrors().size();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean printAndEvaluate(List<CheckAction.Bag> results) {
|
||||
final List<Result<Integer, String>> asserts = results.stream().filter(r -> r.getAssertionResult() != null)
|
||||
.map(CheckAction.Bag::getAssertionResult).collect(Collectors.toList());
|
||||
int checkAssertions = asserts.stream().mapToInt(e -> e.getObject()).sum();
|
||||
int failedAssertions = asserts.stream().mapToInt(e -> e.getErrors().size()).sum();
|
||||
|
||||
public boolean printAndEvaluate() {
|
||||
if (failedAssertions > 0) {
|
||||
log.error("Assertion check failed.\n\nAssertions run: {}, Assertions failed: {}\n", checkAssertions, failedAssertions);
|
||||
} else if (checkAssertions > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue