Class PluginContext

  • All Implemented Interfaces:
    software.amazon.smithy.utils.ToSmithyBuilder<PluginContext>

    public final class PluginContext
    extends java.lang.Object
    implements software.amazon.smithy.utils.ToSmithyBuilder<PluginContext>
    Context object used in plugin execution.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PluginContext.Builder builder()
      Creates a new PluginContext Builder.
      java.util.List<software.amazon.smithy.model.validation.ValidationEvent> getEvents()
      Gets the validation events encountered after projecting the model.
      FileManifest getFileManifest()
      Gets the FileManifest used to create files in the projection.
      software.amazon.smithy.model.Model getModel()
      Gets the model that was projected.
      software.amazon.smithy.model.Model getModelWithoutTraitShapes()
      Creates a new Model where shapes that define traits or shapes that are only used as part of a trait definition have been removed.
      java.util.Optional<software.amazon.smithy.model.Model> getOriginalModel()
      Get the original model before applying the projection.
      java.util.Optional<java.lang.ClassLoader> getPluginClassLoader()
      Gets the ClassLoader that should be used in build plugins to load services.
      java.util.Optional<ProjectionConfig> getProjection()  
      java.lang.String getProjectionName()
      Gets the name of the projection being applied.
      software.amazon.smithy.model.node.ObjectNode getSettings()
      Gets the plugin configuration settings.
      java.util.Set<java.nio.file.Path> getSources()
      Gets the source models, or models that are considered the subject of the build.
      boolean isSourceMetadata​(java.lang.String metadataKey)
      Checks if the given metadata key-value pair is either not present in the old model (thus a new, source metadata), or is present and the filename of the entry in the original model matches one of the defined sources.
      boolean isSourceShape​(software.amazon.smithy.model.shapes.ToShapeId shape)
      Checks if the given shape/ID is either not present in the original model (thus a new, source shape), or is present and the filename of the shape in the original model matches one of the defined sources.
      PluginContext.Builder toBuilder()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • builder

        public static PluginContext.Builder builder()
        Creates a new PluginContext Builder.
        Returns:
        Returns the created builder.
      • getProjection

        public java.util.Optional<ProjectionConfig> getProjection()
        Returns:
        Get the projection the plugin is optionally attached to.
      • getProjectionName

        public java.lang.String getProjectionName()
        Gets the name of the projection being applied.

        If no projection could be found, "source" is assumed.

        Returns:
        Returns the explicit or assumed projection name.
      • getModel

        public software.amazon.smithy.model.Model getModel()
        Gets the model that was projected.
        Returns:
        Get the projected model.
      • getOriginalModel

        public java.util.Optional<software.amazon.smithy.model.Model> getOriginalModel()
        Get the original model before applying the projection.
        Returns:
        The optionally provided original model.
      • getEvents

        public java.util.List<software.amazon.smithy.model.validation.ValidationEvent> getEvents()
        Gets the validation events encountered after projecting the model.
        Returns:
        Get the validation events that were encountered.
      • getSettings

        public software.amazon.smithy.model.node.ObjectNode getSettings()
        Gets the plugin configuration settings.
        Returns:
        Plugins settings object.
      • getFileManifest

        public FileManifest getFileManifest()
        Gets the FileManifest used to create files in the projection.

        All files written by a plugin should either be written using this manifest or added to the manifest via FileManifest.addFile(java.nio.file.Path).

        Returns:
        Returns the file manifest.
      • getPluginClassLoader

        public java.util.Optional<java.lang.ClassLoader> getPluginClassLoader()
        Gets the ClassLoader that should be used in build plugins to load services.
        Returns:
        Returns the optionally set ClassLoader.
      • getModelWithoutTraitShapes

        public software.amazon.smithy.model.Model getModelWithoutTraitShapes()
        Creates a new Model where shapes that define traits or shapes that are only used as part of a trait definition have been removed.

        This is typically functionality used by code generators when generating data structures from a model. It's useful because it only provides shapes that are used to describe data structures rather than shapes used to describe metadata about the data structures.

        Note: this method just calls ModelTransformer.getModelWithoutTraitShapes(software.amazon.smithy.model.Model). It's added to PluginContext to make it more easily available to code generators.

        Returns:
        Returns a Model containing matching shapes.
      • getSources

        public java.util.Set<java.nio.file.Path> getSources()
        Gets the source models, or models that are considered the subject of the build.

        This does not return an exhaustive set of model paths! There are typically two kinds of models that are added to a build: source models and discovered models. Discovered models are someone else's models. Source models are the models owned by the package being built.

        Returns:
        Returns the source models.
      • isSourceShape

        public boolean isSourceShape​(software.amazon.smithy.model.shapes.ToShapeId shape)
        Checks if the given shape/ID is either not present in the original model (thus a new, source shape), or is present and the filename of the shape in the original model matches one of the defined sources.
        Parameters:
        shape - Shape or Shape ID to check.
        Returns:
        Returns true if this shape is considered a source shape.
      • isSourceMetadata

        public boolean isSourceMetadata​(java.lang.String metadataKey)
        Checks if the given metadata key-value pair is either not present in the old model (thus a new, source metadata), or is present and the filename of the entry in the original model matches one of the defined sources.
        Parameters:
        metadataKey - Metadata key to check.
        Returns:
        Returns true if this metadata is considered a source entry.