-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithySelectTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.gradle.tasks; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.inject.Inject; | ||
import org.gradle.StartParameter; | ||
import org.gradle.api.GradleException; | ||
import org.gradle.api.model.ObjectFactory; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
|
||
/** | ||
* Executes the Smithy CLI {@code format} tool on a set of source files. | ||
* | ||
* <p>The smithy format tool is an opinionated formatter that can be used to maintain | ||
* a consistent, readable style for your smithy files. This task can be used to quickly | ||
* reformat smithy files as part of your gradle build process. | ||
* | ||
* <p>WARNING: This task will mutate input source files and change their formatting in-place. | ||
* | ||
* <p>Note: Smithy format was introduced to the CLI in version 1.33.0 so earlier | ||
* versions will be unable to use this tool. | ||
*/ | ||
public abstract class SmithySelectTask extends AbstractSmithyCliTask { | ||
private static final String DESCRIPTION = "Selects smithy models."; | ||
|
||
@Inject | ||
public SmithySelectTask(ObjectFactory objectFactory, StartParameter startParameter) { | ||
super(objectFactory, startParameter); | ||
setDescription(DESCRIPTION); | ||
} | ||
|
||
@Input | ||
@Option(option = "selector", description = "The Smithy selector to execute") | ||
abstract Property<String> getSelector(); | ||
|
||
|
||
@Input | ||
@Optional | ||
@Option(option = "show", description = "The Smithy selector to execute") | ||
abstract Property<String> getShow(); | ||
|
||
@Input | ||
@Optional | ||
@Option(option = "show-traits", description = "The Smithy selector to execute") | ||
abstract Property<String> getShowTraits(); | ||
|
||
@TaskAction | ||
public void execute() { | ||
if (!getSelector().isPresent()) { | ||
throw new GradleException("Select task requires that the command line option `--select` be set."); | ||
} | ||
List<String> extraArgs = new ArrayList<>(); | ||
extraArgs.add("--selector"); | ||
extraArgs.add(getSelector().get()); | ||
|
||
if (getShow().isPresent()) { | ||
extraArgs.add("--show"); | ||
extraArgs.add(getShow().get()); | ||
} | ||
|
||
if (getShowTraits().isPresent()) { | ||
extraArgs.add("--show-traits"); | ||
extraArgs.add(getShowTraits().get()); | ||
} | ||
|
||
executeCliProcess("select", | ||
extraArgs, | ||
getModels().get(), | ||
true | ||
); | ||
} | ||
} |