Class BuildParameterBuilder


  • public final class BuildParameterBuilder
    extends java.lang.Object
    This builder can be used to build up a Smithy CLI command to run `smithy build`.

    This builder will take into account the "lib" and "build" classpaths that points to JAR files when determining which JARs are added as sources and which JARs are added as part of model discovery. This is determined based on the value provided for projectionSource.

    If projectionSource is not set or set to "source", then classes will be loaded using the lib and build classpath. However, models are discovered only using the lib classpath, ensuring that consumers of the generated JAR can find the required models using only the declared dependencies of this package.

    If projectionSource is not set to something other than "source", then we build the model and discover models using only the build classpath. This provides a layer of isolation between the sources that created a projection from the downstream consumers of the projected model. projectionSourceTags can be provided to find JARs in the build classpath that have a META-INF/MANIFEST.MF "Smithy-Tags" value that matches one or more of the provided tags. This is used to select which models from your dependencies should be considered "sources" so that they show up in the JAR you're projecting.

    • Constructor Detail

      • BuildParameterBuilder

        public BuildParameterBuilder()
    • Method Detail

      • projectionSource

        public BuildParameterBuilder projectionSource​(java.lang.String projectionSource)
        Sets the name of the projection being built as a source.

        This means that the given projection is used to populate a build artifact (for example, a JAR being built by Gradle).

        Parameters:
        projectionSource - Projection name.
        Returns:
        Returns the builder.
      • sources

        public BuildParameterBuilder sources​(java.util.Collection<java.lang.String> sources)
        Adds a collection of "source" model files.
        Parameters:
        sources - Sources to add.
        Returns:
        Returns the builder.
      • addSourcesIfExists

        public BuildParameterBuilder addSourcesIfExists​(java.util.Collection<java.lang.String> sources)
        Adds a collection of "source" model files only if they exist.
        Parameters:
        sources - Sources to add.
        Returns:
        Returns the builder.
      • buildClasspath

        public BuildParameterBuilder buildClasspath​(java.lang.String buildClasspath)
        Sets the build classpath.
        Parameters:
        buildClasspath - Classpath to set.
        Returns:
        Returns the builder.
      • libClasspath

        public BuildParameterBuilder libClasspath​(java.lang.String libClasspath)
        Sets the lib classpath.
        Parameters:
        libClasspath - Classpath to set.
        Returns:
        Returns the builder.
      • projectionSourceTags

        public BuildParameterBuilder projectionSourceTags​(java.lang.String projectionSourceTags)
        Sets the tags to find in the build classpath when projecting a JAR.

        Tags can only be provided if projectionSource has been set to something other than "source".

        Parameters:
        projectionSourceTags - Comma separated list of projection tags.
        Returns:
        Returns the builder.
      • projectionSourceTags

        public BuildParameterBuilder projectionSourceTags​(java.util.Collection<java.lang.String> projectionSourceTags)
        Sets the tags to find in the build classpath when projecting a JAR.

        Tags can only be provided if projectionSource has been set to something other than "source".

        Parameters:
        projectionSourceTags - Projection tags.
        Returns:
        Returns the builder.
      • tagMatcher

        public BuildParameterBuilder tagMatcher​(BuildParameterBuilder.ClassPathTagMatcher tagMatcher)
        Sets the implementation used to find JARs with the given tags.

        A default implementation that loads JARs is automatically used if an explicit implementation is not specified. You probably only need to provide a custom implementation for testing.

        Parameters:
        tagMatcher - Tag matching implementation.
        Returns:
        Returns the builder.
      • addConfig

        public BuildParameterBuilder addConfig​(java.lang.String pathToConfig)
        Adds a configuration file to the builder.
        Parameters:
        pathToConfig - Path to the configuration file.
        Returns:
        Returns the builder.
      • addConfigIfExists

        public BuildParameterBuilder addConfigIfExists​(java.lang.String pathToConfig)
        Adds a configuration file to the builder only if it exists.

        This method is ignored if the file is null, empty, or does not exist.

        Parameters:
        pathToConfig - Path to the configuration file.
        Returns:
        Returns the builder.
      • output

        public BuildParameterBuilder output​(java.lang.String output)
        Sets the optional output directory.
        Parameters:
        output - Optional output directory to set.
        Returns:
        Returns the builder.
      • projection

        public BuildParameterBuilder projection​(java.lang.String projection)
        Ensures that only the given projection is built. All other projections are skipped.

        This is not the same as calling projectionSource.

        Parameters:
        projection - Projection to build, excluding others.
        Returns:
        Returns the builder.
      • plugin

        public BuildParameterBuilder plugin​(java.lang.String plugin)
        Ensures that only the given plugin is built in each projection. All other plugins are skipped.
        Parameters:
        plugin - Plugin to build, excluding others.
        Returns:
        Returns the builder.
      • discover

        public BuildParameterBuilder discover​(boolean discover)
        Enables model discovery.
        Parameters:
        discover - Set to true to enable model discovery.
        Returns:
        Returns the builder.
      • allowUnknownTraits

        public BuildParameterBuilder allowUnknownTraits​(boolean allowUnknownTraits)
        Ignores unknown traits when building models.
        Parameters:
        allowUnknownTraits - Set to true to allow unknown traits.
        Returns:
        Returns the builder.
      • addExtraArgs

        public BuildParameterBuilder addExtraArgs​(java.lang.String... args)
        Adds extra arguments to the CLI arguments before positional arguments.
        Parameters:
        args - Arguments to add.
        Returns:
        Returns the builder.
      • build

        public BuildParameterBuilder.Result build()
        Computes the result object that is used when running smithy build.
        Returns:
        Returns the computed result.