Class MockManifest

java.lang.Object
software.amazon.smithy.build.MockManifest
All Implemented Interfaces:
FileManifest

public final class MockManifest extends Object implements FileManifest
A FileManifest that doesn't actually store files on disk.

This manifest is useful for testing SmithyBuildPlugin implementations.

  • Constructor Details

    • MockManifest

      public MockManifest(Path baseDir, MockManifest.StoreMode storeMode)
      Parameters:
      baseDir - Base directory of the manifest.
      storeMode - How files are stored in the mock.
    • MockManifest

      public MockManifest(Path baseDir)
      Creates a mock manifest that stores files in memory.
      Parameters:
      baseDir - Base directory of the manifest.
    • MockManifest

      public MockManifest()
      Creates a mock manifest that stores files in memory and uses a base directory of "/".
  • Method Details

    • getBaseDir

      public Path getBaseDir()
      Description copied from interface: FileManifest
      Gets the base directory of the manifest.
      Specified by:
      getBaseDir in interface FileManifest
      Returns:
      Returns the base directory.
    • getFiles

      public Set<Path> getFiles()
      Description copied from interface: FileManifest
      Gets all of the files in the result.

      The order of files returned should be stable across calls.

      Specified by:
      getFiles in interface FileManifest
      Returns:
      Returns the files in the manifest.
    • addFile

      public Path addFile(Path path)
      Description copied from interface: FileManifest
      Adds a path to the manifest.

      The given path must be relative or within the base directory.

      Specified by:
      addFile in interface FileManifest
      Parameters:
      path - Path to add.
      Returns:
      Returns the path resolved against any base URL.
    • writeFile

      public Path writeFile(Path path, Reader fileContentsReader)
      Description copied from interface: FileManifest
      Adds a file to the result using the contents of a Reader.

      This method will write the contents of a Reader to a file.

      Specified by:
      writeFile in interface FileManifest
      Parameters:
      path - Relative path to the file to create.
      fileContentsReader - Reader to consume and write to the file.
      Returns:
      Returns the resolved path.
    • writeFile

      public Path writeFile(Path path, InputStream fileContentsInputStream)
      Description copied from interface: FileManifest
      Adds a file to the result using the contents of an InputStream.

      This method will write the contents of an input stream to a file.

      Specified by:
      writeFile in interface FileManifest
      Parameters:
      path - Relative path to the file to create.
      fileContentsInputStream - InputStream to consume and write to the file.
      Returns:
      Returns the resolved path.
    • getFileString

      public Optional<String> getFileString(Path file)
      Gets the contents of a stored file as a String.
      Parameters:
      file - Relative or absolute path to the file to retrieve.
      Returns:
      Returns the optionally found file string.
      Throws:
      SmithyBuildException - if the file cannot be read as UTF-8.
    • getFileString

      public Optional<String> getFileString(String file)
      Gets the contents of a stored file as a String.
      Parameters:
      file - Relative or absolute path to the file to retrieve.
      Returns:
      Returns the optionally found file string.
      Throws:
      SmithyBuildException - if the file cannot be read as UTF-8.
    • expectFileString

      public String expectFileString(Path file)
      Expects that the given file was stored and returns a UTF-8 string.
      Parameters:
      file - File to retrieve.
      Returns:
      Returns the bytes of the file if found.
      Throws:
      InvalidPathException - if the file cannot be found.
    • expectFileString

      public String expectFileString(String file)
      Expects that the given file was stored and returns a UTF-8 string.
      Parameters:
      file - File to retrieve.
      Returns:
      Returns the bytes of the file if found.
      Throws:
      InvalidPathException - if the file cannot be found.
    • getFileBytes

      public Optional<byte[]> getFileBytes(Path file)
      Gets the bytes of a stored file.
      Parameters:
      file - Relative or absolute path to the file to retrieve.
      Returns:
      Returns the optionally found file by.es,
    • getFileBytes

      public Optional<byte[]> getFileBytes(String file)
      Gets the bytes of a stored file.
      Parameters:
      file - Relative or absolute path to the file to retrieve.
      Returns:
      Returns the optionally found file by.es,
    • expectFileBytes

      public byte[] expectFileBytes(Path file)
      Expects that the given file was stored and returns the bytes.
      Parameters:
      file - File to retrieve.
      Returns:
      Returns the bytes of the file if found.
      Throws:
      InvalidPathException - if the file cannot be found.
    • expectFileBytes

      public byte[] expectFileBytes(String file)
      Expects that the given file was stored and returns the bytes.
      Parameters:
      file - File to retrieve.
      Returns:
      Returns the bytes of the file if found.
      Throws:
      InvalidPathException - if the file cannot be found.