-
Notifications
You must be signed in to change notification settings - Fork 20
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 merge task to handle existing trait definitions #139
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
examples/trait-module-plugin/create-simple-trait/README.md
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,11 @@ | ||
# Example Project - Custom Trait Module | ||
|
||
TODO | ||
|
||
## Using the example as a starting point | ||
|
||
TODO | ||
|
||
## See Also | ||
|
||
TODO: Add plugin documentation when available |
17 changes: 17 additions & 0 deletions
17
examples/trait-module-plugin/create-simple-trait/build.gradle.kts
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,17 @@ | ||
description = "Custom Smithy structure trait with multiple inputs" | ||
|
||
plugins { | ||
id("software.amazon.smithy.gradle.smithy-trait-module") version "1.0.0" | ||
} | ||
|
||
group = "software.amazon.smithy" | ||
version = "9.9.9" | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") | ||
} |
39 changes: 39 additions & 0 deletions
39
examples/trait-module-plugin/create-simple-trait/model/custom-trait.smithy
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,39 @@ | ||
$version: "2.0" | ||
|
||
namespace io.smithy.gradle.example | ||
|
||
@trait( | ||
selector: "resource" | ||
breakingChanges: [ | ||
{ | ||
change: "presence" | ||
} | ||
] | ||
) | ||
structure resourceMetadata { | ||
/// Provides a custom name for your resource. | ||
@required | ||
description: String | ||
|
||
/// A type for the resource | ||
@required | ||
type: ResourceType | ||
|
||
/// A list of associated structures | ||
associated: Associated | ||
} | ||
|
||
@private | ||
@idRef(failWhenMissing: true, selector: "structure") | ||
string Associated | ||
|
||
@private | ||
enum ResourceType { | ||
NORMAL | ||
SPECIAL | ||
OTHER | ||
NONE | ||
} | ||
|
||
@trait(selector: "member") | ||
string jsonName | ||
10 changes: 10 additions & 0 deletions
10
examples/trait-module-plugin/create-simple-trait/settings.gradle.kts
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,10 @@ | ||
rootProject.name = "create-simple-trait" | ||
|
||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
// Uncomment these to use the published version of the plugin from your preferred source. | ||
// gradlePluginPortal() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/trait-module-plugin/create-simple-trait/smithy-build.json
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,11 @@ | ||
{ | ||
"version": "1.0", | ||
"sources": ["model"], | ||
"plugins": { | ||
"trait-codegen": { | ||
"package": "io.smithy.gradle.examples.traits", | ||
"namespace": "io.smithy.gradle.example", | ||
"header": ["Header line one", "Header line two"] | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/trait-module-plugin/use-with-existing-trait/README.md
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,11 @@ | ||
# Example Project - Trait Module with both generated and manual traits | ||
|
||
TODO | ||
|
||
## Using the example as a starting point | ||
|
||
TODO | ||
|
||
## See Also | ||
|
||
TODO: Add plugin documentation when available |
17 changes: 17 additions & 0 deletions
17
examples/trait-module-plugin/use-with-existing-trait/build.gradle.kts
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,17 @@ | ||
description = "Use existing" | ||
|
||
plugins { | ||
id("software.amazon.smithy.gradle.smithy-trait-module") version "1.0.0" | ||
} | ||
|
||
group = "software.amazon.smithy" | ||
version = "9.9.9" | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("software.amazon.smithy:smithy-model:[1.0, 2.0[") | ||
} |
40 changes: 40 additions & 0 deletions
40
examples/trait-module-plugin/use-with-existing-trait/model/custom-trait.smithy
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,40 @@ | ||
$version: "2.0" | ||
|
||
namespace io.smithy.gradle.example | ||
|
||
@trait( | ||
selector: "resource" | ||
breakingChanges: [ | ||
{ | ||
change: "presence" | ||
} | ||
] | ||
) | ||
structure resourceMetadata { | ||
/// Provides a custom name for your resource. | ||
@required | ||
description: String | ||
|
||
/// A type for the resource | ||
@required | ||
type: ResourceType | ||
|
||
/// A list of associated structures | ||
associated: Associated | ||
} | ||
|
||
@private | ||
@idRef(failWhenMissing: true, selector: "structure") | ||
string Associated | ||
|
||
@private | ||
enum ResourceType { | ||
NORMAL | ||
SPECIAL | ||
OTHER | ||
NONE | ||
} | ||
|
||
@tags(["no-generate"]) | ||
@trait(selector: "member") | ||
string jsonName |
10 changes: 10 additions & 0 deletions
10
examples/trait-module-plugin/use-with-existing-trait/settings.gradle.kts
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,10 @@ | ||
rootProject.name = "use-with-existing-trait" | ||
|
||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
// Uncomment these to use the published version of the plugin from your preferred source. | ||
// gradlePluginPortal() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/trait-module-plugin/use-with-existing-trait/smithy-build.json
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,12 @@ | ||
{ | ||
"version": "1.0", | ||
"sources": ["model"], | ||
"plugins": { | ||
"trait-codegen": { | ||
"package": "io.smithy.gradle.examples.traits", | ||
"namespace": "io.smithy.gradle.example", | ||
"excludeTags": ["no-generate"], | ||
"header": ["Header line one", "Header line two"] | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...use-with-existing-trait/src/main/java/io/smithy/gradle/examples/traits/JsonNameTrait.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,24 @@ | ||
package io.smithy.gradle.examples.traits; | ||
|
||
import software.amazon.smithy.model.FromSourceLocation; | ||
import software.amazon.smithy.model.SourceLocation; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.model.traits.StringTrait; | ||
public final class JsonNameTrait extends StringTrait { | ||
|
||
public static final ShapeId ID = ShapeId.from("io.smithy.gradle.example#jsonName"); | ||
|
||
private JsonNameTrait(String name) { | ||
super(ID, name, SourceLocation.NONE); | ||
} | ||
|
||
private JsonNameTrait(String name, FromSourceLocation sourceLocation) { | ||
super(ID, name, sourceLocation); | ||
} | ||
|
||
public static final class Provider extends StringTrait.Provider<JsonNameTrait> { | ||
public Provider() { | ||
super(ID, JsonNameTrait::new); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ait/src/main/resources/META-INF/services/software.amazon.smithy.model.traits.TraitService
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 @@ | ||
io.smithy.gradle.examples.traits.JsonNameTrait$Provider |
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
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
40 changes: 40 additions & 0 deletions
40
smithy-trait-module/src/it/java/software/amazon/smithy/gradle/CreatesCustomTraitTest.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,40 @@ | ||
package software.amazon.smithy.gradle; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.File; | ||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CreatesCustomTraitTest { | ||
|
||
@Test | ||
public void createsTraitsAndAddsToJar() { | ||
Utils.withCopy("trait-module-plugin/create-simple-trait", buildDir -> { | ||
BuildResult result = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(buildDir) | ||
.withArguments("clean", "build", "--stacktrace") | ||
.build(); | ||
|
||
Utils.assertSmithyBuildTaskRan(result); | ||
Utils.assertValidationRan(result); | ||
Utils.assertJarContains(buildDir, "build/libs/create-simple-trait-9.9.9.jar", | ||
"META-INF/MANIFEST.MF", | ||
"META-INF/smithy/manifest", | ||
"META-INF/smithy/custom-trait.smithy", | ||
"META-INF/services/software.amazon.smithy.model.traits.TraitService", | ||
"io/smithy/gradle/examples/traits/ResourceMetadataTrait.class", | ||
"io/smithy/gradle/examples/traits/ResourceType.class", | ||
"io/smithy/gradle/examples/traits/JsonNameTrait.class" | ||
); | ||
|
||
String spiContents = Utils.getJarEntryContents(new File(buildDir, "build/libs/create-simple-trait-9.9.9.jar"), | ||
"META-INF/services/software.amazon.smithy.model.traits.TraitService"); | ||
|
||
assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.ResourceMetadataTrait$Provider")); | ||
assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.JsonNameTrait$Provider")); | ||
}); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
smithy-trait-module/src/it/java/software/amazon/smithy/gradle/RespectsManualTraitTest.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,46 @@ | ||
package software.amazon.smithy.gradle; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.File; | ||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RespectsManualTraitTest { | ||
|
||
@Test | ||
public void respectsExistingTraitAndMergesSpiFiles() { | ||
Utils.withCopy("trait-module-plugin/use-with-existing-trait", buildDir -> { | ||
BuildResult result = GradleRunner.create() | ||
.forwardOutput() | ||
.withProjectDir(buildDir) | ||
.withArguments("clean", "build", "--stacktrace") | ||
.build(); | ||
|
||
Utils.assertSmithyBuildTaskRan(result); | ||
Utils.assertValidationRan(result); | ||
|
||
// Check that the merge task was executed successfully | ||
Assertions.assertTrue(result.task(":mergeSpiFiles").getOutcome() == TaskOutcome.SUCCESS); | ||
|
||
Utils.assertJarContains(buildDir, "build/libs/use-with-existing-trait-9.9.9.jar", | ||
"META-INF/MANIFEST.MF", | ||
"META-INF/smithy/manifest", | ||
"META-INF/smithy/custom-trait.smithy", | ||
"META-INF/services/software.amazon.smithy.model.traits.TraitService", | ||
"io/smithy/gradle/examples/traits/ResourceMetadataTrait.class", | ||
"io/smithy/gradle/examples/traits/ResourceType.class", | ||
"io/smithy/gradle/examples/traits/JsonNameTrait.class" | ||
); | ||
|
||
String spiContents = Utils.getJarEntryContents(new File(buildDir, "build/libs/use-with-existing-trait-9.9.9.jar"), | ||
"META-INF/services/software.amazon.smithy.model.traits.TraitService"); | ||
|
||
assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.ResourceMetadataTrait$Provider")); | ||
assertTrue(spiContents.contains("io.smithy.gradle.examples.traits.JsonNameTrait$Provider")); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: IMO, it would be better to name this something else, since
jsonName
is already a commonly used trait.