Package software.amazon.smithy.build
Class MockManifest
- java.lang.Object
-
- software.amazon.smithy.build.MockManifest
-
- All Implemented Interfaces:
FileManifest
public final class MockManifest extends java.lang.Object implements FileManifest
AFileManifestthat doesn't actually store files on disk.This manifest is useful for testing SmithyBuildPlugin implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMockManifest.StoreModeThe way in which files are stored.
-
Constructor Summary
Constructors Constructor Description MockManifest()Creates a mock manifest that stores files in memory and uses a base directory of "/".MockManifest(java.nio.file.Path baseDir)Creates a mock manifest that stores files in memory.MockManifest(java.nio.file.Path baseDir, MockManifest.StoreMode storeMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.file.PathaddFile(java.nio.file.Path path)Adds a path to the manifest.byte[]expectFileBytes(java.lang.String file)Expects that the given file was stored and returns the bytes.byte[]expectFileBytes(java.nio.file.Path file)Expects that the given file was stored and returns the bytes.java.lang.StringexpectFileString(java.lang.String file)Expects that the given file was stored and returns a UTF-8 string.java.lang.StringexpectFileString(java.nio.file.Path file)Expects that the given file was stored and returns a UTF-8 string.java.nio.file.PathgetBaseDir()Gets the base directory of the manifest.java.util.Optional<byte[]>getFileBytes(java.lang.String file)Gets the bytes of a stored file.java.util.Optional<byte[]>getFileBytes(java.nio.file.Path file)Gets the bytes of a stored file.java.util.Set<java.nio.file.Path>getFiles()Gets all of the files in the result.java.util.Optional<java.lang.String>getFileString(java.lang.String file)Gets the contents of a stored file as a String.java.util.Optional<java.lang.String>getFileString(java.nio.file.Path file)Gets the contents of a stored file as a String.java.nio.file.PathwriteFile(java.nio.file.Path path, java.io.InputStream fileContentsInputStream)Adds a file to the result using the contents of anInputStream.java.nio.file.PathwriteFile(java.nio.file.Path path, java.io.Reader fileContentsReader)Adds a file to the result using the contents of aReader.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.amazon.smithy.build.FileManifest
addAllFiles, getFilesIn, getFilesIn, hasFile, hasFile, resolvePath, writeFile, writeFile, writeFile, writeFile, writeFile, writeFile, writeJson, writeJson
-
-
-
-
Constructor Detail
-
MockManifest
public MockManifest(java.nio.file.Path baseDir, MockManifest.StoreMode storeMode)- Parameters:
baseDir- Base directory of the manifest.storeMode- How files are stored in the mock.
-
MockManifest
public MockManifest(java.nio.file.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 Detail
-
getBaseDir
public java.nio.file.Path getBaseDir()
Description copied from interface:FileManifestGets the base directory of the manifest.- Specified by:
getBaseDirin interfaceFileManifest- Returns:
- Returns the base directory.
-
getFiles
public java.util.Set<java.nio.file.Path> getFiles()
Description copied from interface:FileManifestGets all of the files in the result.The order of files returned should be stable across calls.
- Specified by:
getFilesin interfaceFileManifest- Returns:
- Returns the files in the manifest.
-
addFile
public java.nio.file.Path addFile(java.nio.file.Path path)
Description copied from interface:FileManifestAdds a path to the manifest.The given path must be relative or within the base directory.
- Specified by:
addFilein interfaceFileManifest- Parameters:
path- Path to add.- Returns:
- Returns the path resolved against any base URL.
-
writeFile
public java.nio.file.Path writeFile(java.nio.file.Path path, java.io.Reader fileContentsReader)Description copied from interface:FileManifestAdds a file to the result using the contents of aReader.This method will write the contents of a Reader to a file.
- Specified by:
writeFilein interfaceFileManifest- 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 java.nio.file.Path writeFile(java.nio.file.Path path, java.io.InputStream fileContentsInputStream)Description copied from interface:FileManifestAdds a file to the result using the contents of anInputStream.This method will write the contents of an input stream to a file.
- Specified by:
writeFilein interfaceFileManifest- 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 java.util.Optional<java.lang.String> getFileString(java.nio.file.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 java.util.Optional<java.lang.String> getFileString(java.lang.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 java.lang.String expectFileString(java.nio.file.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:
java.nio.file.InvalidPathException- if the file cannot be found.
-
expectFileString
public java.lang.String expectFileString(java.lang.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:
java.nio.file.InvalidPathException- if the file cannot be found.
-
getFileBytes
public java.util.Optional<byte[]> getFileBytes(java.nio.file.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 java.util.Optional<byte[]> getFileBytes(java.lang.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(java.nio.file.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:
java.nio.file.InvalidPathException- if the file cannot be found.
-
expectFileBytes
public byte[] expectFileBytes(java.lang.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:
java.nio.file.InvalidPathException- if the file cannot be found.
-
-