@Beta public class FileSystemFixture extends Object implements DirectoryFixture
TempDir
.Constructor and Description |
---|
FileSystemFixture(Path currentPath) |
Modifier and Type | Method and Description |
---|---|
Path |
copyFromClasspath(String resourcePath)
Copies a file from classpath using the contextClass to load the resource.
|
Path |
copyFromClasspath(String resourcePath,
Class<?> contextClass)
Copies a file from classpath using the contextClass to load the resource.
|
Path |
copyFromClasspath(String resourcePath,
String targetName)
Copies a file from classpath using the contextClass to load the resource.
|
Path |
copyFromClasspath(String resourcePath,
String targetName,
Class<?> contextClass)
Copies a file from classpath using the contextClass to load the resource.
|
void |
create(Closure<?> dirSpec)
Basically the same as
DirectoryFixture.dir(String, Closure) , but with the current root as base. |
Path |
dir(String dir)
Creates a directory, creates the ancestors as necessary.
|
Path |
dir(String dir,
Closure<?> dirSpec)
Creates a directory, creates the ancestors as necessary.
|
Path |
file(String file)
Creates a file object relative to the enclosing fixture or directory,
but not the physical File, it will eagerly create parent directories if necessary.
|
Path |
getCurrentPath() |
Path |
resolve(Path path)
A shorthand for
getCurrentPath().resolve(path) |
Path |
resolve(String path)
A shorthand for
getCurrentPath().resolve(path) |
public FileSystemFixture(Path currentPath)
public Path getCurrentPath()
public Path resolve(String path)
getCurrentPath().resolve(path)
path
- the path to resolve relative to currentPathpublic Path resolve(Path path)
getCurrentPath().resolve(path)
path
- the path to resolve relative to currentPathpublic void create(@DelegatesTo(value=DirectoryFixture.class,strategy=1) Closure<?> dirSpec) throws IOException
DirectoryFixture.dir(String, Closure)
, but with the current root as base.IOException
public Path dir(String dir) throws IOException
DirectoryFixture
dir
in interface DirectoryFixture
dir
- path to the directory, can either be a single level or multilevelIOException
- if the directories could not be created.public Path dir(String dir, Closure<?> dirSpec) throws IOException
DirectoryFixture
dirSpec
closure, that can create files and directories in the scope of this one.
Example:
dir('src') {
dir('main') {
dir('groovy') {
file('HelloWorld.java') << 'println "Hello World"'
}
}
dir('test/resources') {
file('META-INF/MANIFEST.MF') << 'bogus entry'
}
}
dir
in interface DirectoryFixture
dir
- path to the directory, can either be a single level or multileveldirSpec
- a closure within the scope of this directory.IOException
- if the directories could not be created.public Path file(String file) throws IOException
DirectoryFixture
file
in interface DirectoryFixture
file
- the (path and) filenamePath
object pointing to the fileIOException
- if the parent directories could not be created.public Path copyFromClasspath(String resourcePath) throws IOException
DirectoryFixture
This will use the Closure.getOwner()
of the enclosing closure to determine the contextClass.
The target name will be the same as the last path element of the resourcePath
.
copyFromClasspath
in interface DirectoryFixture
resourcePath
- the path to the resource to loadPath
pointing to the copied fileIOException
- if the parent directories could not be created or the resource could not be foundpublic Path copyFromClasspath(String resourcePath, String targetName) throws IOException
DirectoryFixture
This will use the Closure.getOwner()
of the enclosing closure to determine the contextClass.
copyFromClasspath
in interface DirectoryFixture
resourcePath
- the path to the resource to loadtargetName
- the name of the target to usePath
pointing to the copied fileIOException
- if the parent directories could not be created or the resource could not be foundpublic Path copyFromClasspath(String resourcePath, Class<?> contextClass) throws IOException
DirectoryFixture
The target name will be the same as the last path element of the resourcePath
.
copyFromClasspath
in interface DirectoryFixture
resourcePath
- the path to the resource to loadcontextClass
- the class to use to load the resourcePath
pointing to the copied fileIOException
- if the parent directories could not be created or the resource could not be foundpublic Path copyFromClasspath(String resourcePath, String targetName, Class<?> contextClass) throws IOException
DirectoryFixture
copyFromClasspath
in interface DirectoryFixture
resourcePath
- the path to the resource to loadtargetName
- the name of the target to usecontextClass
- the class to use to load the resourcePath
pointing to the copied fileIOException
- if the parent directories could not be created or the resource could not be found