Skip to content

Commit

Permalink
Support several flavours
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Jul 30, 2024
1 parent acd2742 commit 7ef5e5b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand All @@ -29,7 +30,7 @@ public void shouldCreateXmlReportsInGivenDirectory() throws Exception {

int numberOfThreads = 4;

List<Future<ValidationResult>> futureResult = startValidation(fileToValidate, numberOfThreads);
List<Future<List<ValidationResult>>> futureResult = startValidation(fileToValidate, numberOfThreads);
List<ValidationResult> validationResults = getValidationResult(futureResult);

boolean isExpectedResults = compareResultsFromDifferentThreads(validationResults);
Expand All @@ -52,21 +53,21 @@ private boolean compareResultsFromDifferentThreads(List<ValidationResult> valida
return isExpectedResults;
}

private List<ValidationResult> getValidationResult(List<Future<ValidationResult>> results) throws InterruptedException, java.util.concurrent.ExecutionException {
private List<ValidationResult> getValidationResult(List<Future<List<ValidationResult>>> results) throws InterruptedException, java.util.concurrent.ExecutionException {
List<ValidationResult> validationResults = new ArrayList<>();
for (Future<ValidationResult> result : results) {
ValidationResult validationResult = result.get();
validationResults.add(validationResult);
for (Future<List<ValidationResult>> result : results) {
List<ValidationResult> validationResult = result.get();
validationResults.addAll(validationResult);
}
return validationResults;
}

private List<Future<ValidationResult>> startValidation(File fileToValidate, int numberOfThreads) {
List<Future<ValidationResult>> futureResult = new ArrayList<>();
private List<Future<List<ValidationResult>>> startValidation(File fileToValidate, int numberOfThreads) {
List<Future<List<ValidationResult>>> futureResult = new ArrayList<>();
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
CallableValidatorForTest validator = new CallableValidatorForTest(fileToValidate);
Future<ValidationResult> submit = executor.submit(validator);
Future<List<ValidationResult>> submit = executor.submit(validator);
futureResult.add(submit);
}
return futureResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.concurrent.Callable;

public class CallableValidatorForTest implements Callable<ValidationResult> {
public class CallableValidatorForTest implements Callable<List<ValidationResult>> {
private final File fileToValidate;

public CallableValidatorForTest(File fileToValidate) {
this.fileToValidate = fileToValidate;
}

@Override
public ValidationResult call() throws Exception {
ValidationResult result;
public List<ValidationResult> call() throws Exception {
List<ValidationResult> result;
try (FileInputStream fis = new FileInputStream(this.fileToValidate);
PDFAParser parser = Foundries.defaultInstance().createParser(fis);
PDFAValidator validator = Foundries.defaultInstance().createValidator(parser.getFlavour(), false)) {
result = validator.validate(parser);
result = validator.validateAll(parser);
}
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions gui/src/main/java/org/verapdf/cli/VeraPdfCliProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.verapdf.cli.CliConstants.ExitCodes;
import org.verapdf.cli.commands.VeraCliArgParser;
import org.verapdf.core.VeraPDFException;
import org.verapdf.pdfa.results.ValidationResult;
import org.verapdf.policy.PolicyChecker;
import org.verapdf.processor.*;
import org.verapdf.processor.app.ConfigManager;
Expand Down Expand Up @@ -183,8 +184,11 @@ private ExitCodes processStream(final ItemDetails item, final InputStream toProc

if (result.isPdf() && !result.isEncryptedPdf()) {
ProcessorFactory.writeSingleResultReport(result, handler, processorConfig);
if (!result.getValidationResult().isCompliant()) {
retVal = ExitCodes.INVALID;
for (ValidationResult validationResult : result.getValidationResults()) {
if (!validationResult.isCompliant()) {
retVal = ExitCodes.INVALID;
break;
}
}
} else {
String message = String.format(
Expand Down

2 comments on commit 7ef5e5b

@DanielRuf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaximPlusov
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Arlington branch was updated manually: e21a92c

Please sign in to comment.