Skip to content

Commit

Permalink
Using supplier parameter to create
Browse files Browse the repository at this point in the history
  • Loading branch information
gosar committed Mar 20, 2023
1 parent e2bd757 commit 73f6d3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,7 @@ public SmithyBuild(SmithyBuildConfig config) {
* @return Returns the created {@code SmithyBuild} object.
*/
public static SmithyBuild create(ClassLoader classLoader) {
return create(classLoader, false);
}

/**
* Creates a {@code SmithyBuild} implementation that is configured to
* discover various Smithy service providers using the given
* {@code ClassLoader}.
*
* @param classLoader ClassLoader used to discover service providers.
* @param allowUnknownTraits Set to true to allow unknown traits.
* @return Returns the created {@code SmithyBuild} object.
*/
public static SmithyBuild create(ClassLoader classLoader, boolean allowUnknownTraits) {
ModelAssembler assembler = Model.assembler(classLoader);
if (allowUnknownTraits) {
assembler.putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true);
}
return create(classLoader, assembler::copy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import software.amazon.smithy.build.FileManifest;
import software.amazon.smithy.build.ProjectionResult;
import software.amazon.smithy.build.SmithyBuild;
Expand All @@ -40,6 +41,7 @@
import software.amazon.smithy.cli.Style;
import software.amazon.smithy.cli.dependencies.DependencyResolver;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.loader.ModelAssembler;
import software.amazon.smithy.model.validation.Severity;

final class BuildCommand extends ClasspathCommand {
Expand Down Expand Up @@ -102,7 +104,14 @@ int runWithClassLoader(SmithyBuildConfig config, Arguments arguments, Env env, L
// Configure whether the build is quiet or not based on the --quiet option.
Model model = CommandUtils.buildModel(arguments, models, env, env.stderr(), standardOptions.quiet(), config);

SmithyBuild smithyBuild = SmithyBuild.create(classLoader, buildOptions.allowUnknownTraits())
Supplier<ModelAssembler> modelAssemblerSupplier = () -> {
ModelAssembler assembler = Model.assembler(classLoader);
if (buildOptions.allowUnknownTraits()) {
assembler.putProperty(ModelAssembler.ALLOW_UNKNOWN_TRAITS, true);
}
return assembler;
};
SmithyBuild smithyBuild = SmithyBuild.create(classLoader, modelAssemblerSupplier)
.config(config)
.model(model);

Expand Down

0 comments on commit 73f6d3a

Please sign in to comment.