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

Add severity option for validators #131

Merged
merged 2 commits into from
Mar 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ Provider<FileCollection> getCliExecutionClasspath() {
@Optional
public abstract Property<ShowStacktrace> getShowStackTrace();

/**
* Set the minimum reported validation severity.
*
* <p>This value should be one of: NOTE, WARNING [default], DANGER, ERROR.
*
* @return minimum validator severity
*/
@Input
@Optional
public abstract Property<String> getSeverity();

@Internal
WorkerExecutor getExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.gradle.api.tasks.TaskAction;
import software.amazon.smithy.cli.BuildParameterBuilder;
import software.amazon.smithy.gradle.SmithyUtils;
import software.amazon.smithy.model.validation.Severity;

/**
* Executes the Smithy CLI {@code build} command.
Expand All @@ -39,6 +40,7 @@ public SmithyBuildTask(ObjectFactory objectFactory) {
super(objectFactory);

getSourceProjection().convention("source");
getSeverity().convention(Severity.WARNING.toString());
getOutputDir().convention(SmithyUtils.getProjectionOutputDirProperty(getProject()));
}

Expand Down Expand Up @@ -149,6 +151,11 @@ public void execute() {
// Add extra configuration options for build command
List<String> extraArgs = new ArrayList<>();
configureLoggingOptions(extraArgs);

// Add validator severity option if it exists
extraArgs.add("--severity");
extraArgs.add(getSeverity().get());

builder.addExtraArgs(extraArgs.toArray(new String[0]));

BuildParameterBuilder.Result result = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package software.amazon.smithy.gradle.tasks;

import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
Expand All @@ -15,7 +17,7 @@
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.model.validation.Severity;


/**
Expand All @@ -35,6 +37,7 @@ public SmithyValidateTask(ObjectFactory objectFactory) {
super(objectFactory);
getAllowUnknownTraits().convention(false);
getDisableModelDiscovery().convention(false);
getSeverity().convention(Severity.ERROR.toString());
setDescription(DESCRIPTION);
}

Expand Down Expand Up @@ -67,6 +70,17 @@ public SmithyValidateTask(ObjectFactory objectFactory) {
@Optional
public abstract Property<Boolean> getDisableModelDiscovery();

/**
* Set the minimum reported validation severity.
*
* <p>This value should be one of: NOTE, WARNING, DANGER, ERROR [default].
*
* @return minimum validator severity
*/
@Input
@Optional
public abstract Property<String> getSeverity();

/**
* Gets the classpath to use when executing the Smithy CLI.
*
Expand All @@ -86,8 +100,13 @@ Provider<FileCollection> getCliExecutionClasspath() {
public void execute() {
writeHeading("Running smithy validate");

// Add validator severity settings
List<String> extraArgs = new ArrayList<>();
extraArgs.add("--severity");
extraArgs.add(getSeverity().get());

// Set models to an empty collection so source models are not included in validation path.
executeCliProcess("validate", ListUtils.of(),
executeCliProcess("validate", extraArgs,
getJarToValidate().get(),
getDisableModelDiscovery().get()
);
Expand Down
Loading