From e7076e1cc771fcbe30865eee70a36aaf9f622881 Mon Sep 17 00:00:00 2001 From: Miles Ziemer Date: Mon, 17 Jul 2023 13:29:32 -0400 Subject: [PATCH] Fix building models in subdirs Fixes #1859 Modifies the changes in https://github.com/smithy-lang/smithy/pull/1851, specifically `SmithyBuild::addSources`, to not check subdirectories for Smithy files. The previous behavior was to just add whatever path was given to the method, *not* everything in subdirectories. However, the change didn't recursively search subdirectores, so you could get build errors due to missing shapes when running the sources plugin. This change reverts the behavior of `SmithyBuild::addSource` to only add whichever path it was given, but still checks to see if the path is a valid Smithy model. --- .../amazon/smithy/build/SmithyBuild.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java index 136b03f779c..6c6429eca48 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuild.java @@ -15,8 +15,6 @@ package software.amazon.smithy.build; -import java.io.IOException; -import java.io.UncheckedIOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; @@ -199,23 +197,10 @@ public SmithyBuild config(SmithyBuildConfig config) { // // Ignores and logs when an unsupported model file is encountered. private void addSource(Path path) { - try { - if (Files.isDirectory(path)) { - // Pre-emptively crawl the given models to filter them up front into a flat, file-only, list. - Files.list(path).filter(Files::isRegularFile).forEach(this::addSourceFile); - } else { - addSourceFile(path); - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - private void addSourceFile(Path file) { - if (!VALID_MODELS.matches(file.getFileName())) { - LOGGER.warning("Omitting unsupported Smithy model file from model sources: " + file); + if (Files.isRegularFile(path) && !VALID_MODELS.matches(path.getFileName())) { + LOGGER.warning("Omitting unsupported Smithy model file from model sources: " + path); } else { - sources.add(file.toAbsolutePath()); + sources.add(path.toAbsolutePath()); } }