diff --git a/build.gradle b/build.gradle index 490c4f04431..4aac721ce9f 100644 --- a/build.gradle +++ b/build.gradle @@ -107,6 +107,7 @@ subprojects { test { testLogging { events = ["passed", "skipped", "failed"] + exceptionFormat = "full" } } } diff --git a/docs/source/1.0/guides/building-models/build-config.rst b/docs/source/1.0/guides/building-models/build-config.rst index 5ca324793ca..5b59ee5abfa 100644 --- a/docs/source/1.0/guides/building-models/build-config.rst +++ b/docs/source/1.0/guides/building-models/build-config.rst @@ -1134,7 +1134,8 @@ The ``sources`` plugin copies the source models and creates a manifest. When building the ``source`` projection, the models that were used to build the model are copied over literally. When a JAR is used as a source model, the Smithy models contained within the JAR are copied as a source model while the -JAR itself is not copied. +JAR itself is not copied. If there are no source models, an empty manifest is +created. When applying a projection, a new model file is created that contains only the shapes, trait definitions, and metadata that were defined in a source diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java index 22c3072708d..d6a50629aba 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/SourcesPlugin.java @@ -88,14 +88,15 @@ public void execute(PluginContext context) { projectSources(context); } + String manifest = ""; if (names.isEmpty()) { - LOGGER.info(String.format("Skipping `%s` manifest because no Smithy sources found", projectionName)); + LOGGER.info(String.format("Writing empty `%s` manifest because no Smithy sources found", projectionName)); } else { LOGGER.fine(() -> String.format("Writing `%s` manifest", projectionName)); // Normalize filenames to Unix style. - String manifest = names.stream().map(name -> name.replace("\\", "/")).collect(Collectors.joining("\n")); - context.getFileManifest().writeFile("manifest", manifest + "\n"); + manifest = names.stream().map(name -> name.replace("\\", "/")).collect(Collectors.joining("\n")); } + context.getFileManifest().writeFile("manifest", manifest + "\n"); } private static List copySources(PluginContext context) { diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java index 69a8b225273..d1ab154e407 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java @@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -133,6 +134,26 @@ public void buildsModels() throws Exception { assertThat(Files.isRegularFile(outputDirectory.resolve("b/model/model.json")), is(true)); } + @Test + public void createsEmptyManifest() throws Exception { + SmithyBuildConfig config = SmithyBuildConfig.builder() + .load(Paths.get(getClass().getResource("empty-config.json").toURI())) + .outputDirectory(outputDirectory.toString()) + .build(); + Model model = Model.assembler() + .assemble() + .unwrap(); + SmithyBuild builder = new SmithyBuild().config(config).model(model); + SmithyBuildResult results = builder.build(); + List files = results.allArtifacts().collect(Collectors.toList()); + + assertThat(files, hasItem(outputDirectory.resolve("source/sources/manifest"))); + assertThat("\n", equalTo(IoUtils.readUtf8File(results.allArtifacts() + .filter(path -> path.toString().endsWith("/manifest")) + .findFirst() + .get()))); + } + @Test public void doesNotCopyErroneousModelsToBuildOutput() throws Exception { SmithyBuildConfig config = SmithyBuildConfig.builder() @@ -377,6 +398,7 @@ public void buildCanOverrideConfigOutputDirectory() throws Exception { List files = results.allArtifacts().collect(Collectors.toList()); assertThat(files, containsInAnyOrder( + outputDirectory.resolve("source/sources/manifest"), outputDirectory.resolve("source/model/model.json"), outputDirectory.resolve("source/build-info/smithy-build-info.json"), outputDirectory.resolve("a/sources/manifest"),