public void execute()

in smithy-cli/src/main/java/software/amazon/smithy/cli/commands/BuildCommand.java [79:150]


    public void execute(Arguments arguments, ClassLoader classLoader) {
        List<String> config = arguments.repeatedParameter("--config", null);
        String output = arguments.parameter("--output", null);
        List<String> models = arguments.positionalArguments();

        Cli.stdout(String.format("Building Smithy model sources: %s", models));
        SmithyBuildConfig.Builder configBuilder = SmithyBuildConfig.builder();

        // Try to find a smithy-build.json file.
        if (config == null && Files.exists(Paths.get("smithy-build.json"))) {
            config = Collections.singletonList("smithy-build.json");
        }

        if (config != null) {
            Cli.stdout(String.format("Loading Smithy configs: [%s]", String.join(" ", config)));
            config.forEach(file -> configBuilder.load(Paths.get(file)));
        } else {
            configBuilder.version(SmithyBuild.VERSION);
        }

        if (output != null) {
            configBuilder.outputDirectory(output);
            try {
                Files.createDirectories(Paths.get(output));
                LOGGER.info(String.format("Output directory set to: %s", output));
            } catch (IOException e) {
                throw new CliError("Unable to create Smithy output directory: " + e.getMessage());
            }
        }

        SmithyBuildConfig smithyBuildConfig = configBuilder.build();

        // Build the model and fail if there are errors. Prints errors to stdout.
        Model model = CommandUtils.buildModel(arguments, classLoader, SetUtils.of(Validator.Feature.STDOUT));

        SmithyBuild smithyBuild = SmithyBuild.create(classLoader)
                .config(smithyBuildConfig)
                .model(model);

        if (arguments.has("--plugin")) {
            smithyBuild.pluginFilter(name -> name.equals(arguments.parameter("--plugin")));
        }

        if (arguments.has("--projection")) {
            smithyBuild.projectionFilter(name -> name.equals(arguments.parameter("--projection")));
        }

        // Register sources with the builder.
        models.forEach(path -> smithyBuild.registerSources(Paths.get(path)));

        ResultConsumer resultConsumer = new ResultConsumer();
        smithyBuild.build(resultConsumer, resultConsumer);

        // Always print out the status of the successful projections.
        Colors color = resultConsumer.failedProjections.isEmpty()
                ? Colors.BRIGHT_BOLD_GREEN
                : Colors.BRIGHT_BOLD_YELLOW;
        color.out(String.format(
                "Smithy built %s projection(s), %s plugin(s), and %s artifacts",
                resultConsumer.projectionCount,
                resultConsumer.pluginCount,
                resultConsumer.artifactCount));

        // Throw an exception if any errors occurred.
        if (!resultConsumer.failedProjections.isEmpty()) {
            resultConsumer.failedProjections.sort(String::compareTo);
            throw new CliError(String.format(
                    "The following %d Smithy build projection(s) failed: %s",
                    resultConsumer.failedProjections.size(),
                    resultConsumer.failedProjections));
        }
    }