Skip to content

Commit

Permalink
Re-add "Add exception on implicit empty config (#123)"
Browse files Browse the repository at this point in the history
This reverts commit 590302c.
  • Loading branch information
hpmellema committed Mar 14, 2024
1 parent 1f62788 commit 27b495d
Show file tree
Hide file tree
Showing 35 changed files with 114 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This plugin can be applied to a project as follows:
```kotlin
// build.gradle.kts
plugins {
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}
```
However, no tasks will be created unless.
Expand All @@ -72,7 +72,7 @@ The `smithy-jar` plugin must be used with another plugin that creates a `jar` ta
// build.gradle.kts
plugins {
id("java-library") // creates jar task
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy:smithy-aws-traits:[1.0, 2.0[")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace smithy.example

structure Foo {
foo: String
}

@aws.auth#unsignedPayload
operation Bar {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rootProject.name = "forbid-dependency-resolution"

pluginManagement {
repositories {
mavenLocal()
mavenCentral()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}


Expand Down
2 changes: 1 addition & 1 deletion examples/base-plugin/output-directory/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/base-plugin/smithy-build-task/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import software.amazon.smithy.gradle.tasks.SmithyBuildTask
// and the classpath used when building.

plugins {
id("software.amazon.smithy.gradle.smithy-base").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-base").version("0.10.1")
}

tasks.create<SmithyBuildTask>("doit") {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/adds-tags/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

group = "software.amazon.smithy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
8 changes: 6 additions & 2 deletions examples/jar-plugin/custom-trait/consumer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}


Expand All @@ -14,4 +14,8 @@ repositories {

dependencies {
implementation(project(":custom-string-trait"))
}
}

smithy {
smithyBuildConfigs.set(project.files())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This package defines a custom trait for use in other models
plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/disable-jar/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/kotlin-jvm-project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
kotlin("jvm") version "1.9.0"
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions examples/jar-plugin/multi-project/consumer/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0"
}
2 changes: 1 addition & 1 deletion examples/jar-plugin/multiple-jars/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import software.amazon.smithy.gradle.tasks.SmithyJarStagingTask

plugins {
`java-library`
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

val buildTask: SmithyBuildTask = tasks.getByName<SmithyBuildTask>("smithyBuild")
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/multiple-sources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
3 changes: 3 additions & 0 deletions examples/jar-plugin/multiple-sources/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "1.0"
}
2 changes: 1 addition & 1 deletion examples/jar-plugin/no-models/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

group = "software.amazon.smithy"
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/projection/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/projects-with-tags/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/scala-project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
scala
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion examples/jar-plugin/source-projection/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

plugins {
id("java-library")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.0")
id("software.amazon.smithy.gradle.smithy-jar").version("0.10.1")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package software.amazon.smithy.gradle;

import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ForbidImplicitNoBuildConfigTest {
@Test
public void testExceptionThrows() {
Utils.withCopy("base-plugin/failure-cases/forbid-implicit-no-build-config", buildDir -> {
BuildResult result = GradleRunner.create()
.forwardOutput()
.withProjectDir(buildDir)
.withArguments("clean", "build", "--stacktrace")
.buildAndFail();

Assertions.assertTrue(result.getOutput()
.contains("No smithy-build configs found. If this was intentional, set the `smithyBuildConfigs` property to an empty list."));
Utils.assertArtifactsNotCreated(buildDir,
"build/smithyprojections/forbid-implicit-no-build-config/source/build-info/smithy-build-info.json");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private void configureDefaults(Project project) {
getFormat().convention(true);
getAllowUnknownTraits().convention(false);
getOutputDirectory().convention(getDefaultOutputDirectory(project));

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
Expand Down Expand Up @@ -57,14 +59,14 @@ public SmithyBuildTask(ObjectFactory objectFactory) {
public abstract SetProperty<String> getProjectionSourceTags();


/** Smithy build configs to use for building models.
/**
* Smithy build configs to use for building models.
*
* @return list of smithy-build config json files
*/
@InputFiles
public abstract Property<FileCollection> getSmithyBuildConfigs();


/**
* Sets whether to fail a {@link SmithyBuildTask} if an unknown trait is encountered.
*
Expand Down Expand Up @@ -104,10 +106,27 @@ List<String> getModelAbsolutePaths() {
.collect(Collectors.toList());
}

/**
* Read-only property.
*
* @return Returns true if at least one of the specified build configs exists.
*/
@Internal
Provider<Boolean> getSmithyBuildConfigsMissing() {
return getSmithyBuildConfigs().map(
files -> !files.isEmpty() && files.filter(File::exists).isEmpty()
);
}

@TaskAction
public void execute() {
writeHeading("Running smithy build");

if (getSmithyBuildConfigsMissing().get()) {
throw new GradleException("No smithy-build configs found. "
+ "If this was intentional, set the `smithyBuildConfigs` property to an empty list.");
}

BuildParameterBuilder builder = new BuildParameterBuilder();

// Model discovery classpath
Expand Down

0 comments on commit 27b495d

Please sign in to comment.