final void executeCliProcess()

in src/main/java/software/amazon/smithy/gradle/tasks/SmithyCliTask.java [170:225]


    final void executeCliProcess(
            String command,
            List<String> customArguments,
            FileCollection cliClasspath,
            FileCollection modelDiscoveryClasspath
    ) {
        // Setup the CLI classpath.
        if (getAddRuntimeClasspath() || getAddCompileClasspath() || getAddBuildScriptClasspath()) {
            FileCollection originalCliClasspath = cliClasspath;
            cliClasspath = cliClasspath != null ? cliClasspath : getProject().files();
            if (getAddBuildScriptClasspath()) {
                cliClasspath = cliClasspath.plus(SmithyUtils.getBuildscriptClasspath(getProject()));
            }
            if (getAddRuntimeClasspath()) {
                cliClasspath = cliClasspath.plus(SmithyUtils.getClasspath(getProject(), RUNTIME_CLASSPATH));
            }
            if (getAddCompileClasspath()) {
                cliClasspath = cliClasspath.plus(SmithyUtils.getClasspath(getProject(), COMPILE_CLASSPATH));
            }
            getLogger().debug(
                    "Configuring classpath: runtime: {}; compile: {}; buildscript: {}; updated from {} to {}",
                    addRuntimeClasspath, addCompileClasspath, addBuildScriptClasspath,
                    originalCliClasspath == null ? "null" : originalCliClasspath.getAsPath(),
                    cliClasspath.getAsPath());
        }

        List<String> args = new ArrayList<>();
        args.add(command);

        if (getAllowUnknownTraits()) {
            args.add("--allow-unknown-traits");
        }

        if (modelDiscoveryClasspath != null) {
            args.add("--discover-classpath");
            args.add(modelDiscoveryClasspath.getAsPath());
        } else if (!disableModelDiscovery) {
            args.add("--discover");
        }

        args.addAll(customArguments);

        if (!getModels().isEmpty()) {
            args.add("--");
            getModels().forEach(file -> {
                if (file.exists()) {
                    getLogger().debug("Adding Smithy model file to CLI: {}", file);
                    args.add(file.getAbsolutePath());
                } else {
                    getLogger().error("Skipping Smithy model file because it does not exist: {}", file);
                }
            });
        }

        SmithyUtils.executeCli(getProject(), args, cliClasspath);
    }