Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds failOnWarning flag to support failing validation on Warning … #18

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ the [`ShadowedRuleValidator`](#shadowed-rules) should be executed. To specify va
</validatorClasses>
</configuration>

Additionally `failOnWarning` (default false) parameter can be set to fail mvn execution if there are validation errors with Warning severity.

<configuration>
<failOnWarning>true</failOnWarning>
</configuration>

#### Standalone Usage

To use `dmn-check` without or outside of a Maven project you can invoke it in the following way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public class CheckerMain extends AbstractMojo implements PluginBase {
@SuppressWarnings("nullness")
private MavenProject project;

@Parameter( defaultValue = "false", readonly = true )
@SuppressWarnings("nullness")
private Boolean failOnWarning;

@Override
public void execute() throws MojoExecutionException {
loadProjectclasspath();
Expand Down Expand Up @@ -121,4 +125,9 @@ void setValidatorClasses(String[] validatorClasses) {
void setProject(MavenProject project) {
this.project = project;
}

@Override
public boolean failOnWarning() {
return failOnWarning;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -55,8 +56,16 @@ default boolean testFile(final File file) {

if (!validationResults.isEmpty()) {
PrettyPrintValidationResults.logPrettified(file, validationResults, getPluginLogger());

List<Severity> errors = new ArrayList<>();
errors.add(Severity.ERROR);

if (failOnWarning()) {
errors.add(Severity.WARNING);
}

encounteredError = validationResults.stream()
.anyMatch(result -> Severity.ERROR.equals(result.getSeverity()));
.anyMatch(result -> errors.contains(result.getSeverity()));
}
}
catch (Exception e) {
Expand Down Expand Up @@ -103,4 +112,8 @@ default List<Path> getFileNames(final List<Path> dirs) {
default List<Validator> getValidators() {
return ValidatorLoader.getValidators(getValidatorPackages(), getValidatorClasses());
}

default boolean failOnWarning() {
return false;
}
}