Package spock.util.io

Interface DirectoryFixture

  • All Known Implementing Classes:
    FileSystemFixture

    public interface DirectoryFixture
    • Method Detail

      • dir

        Path dir​(String dir)
          throws IOException
        Creates a directory, creates the ancestors as necessary.
        Parameters:
        dir - path to the directory, can either be a single level or multilevel
        Returns:
        the path to the directory
        Throws:
        IOException - if the directories could not be created.
      • dir

        Path dir​(String dir,
                 @DelegatesTo(value=DirectoryFixture.class,strategy=1)
                 Closure<?> dirSpec)
          throws IOException
        Creates a directory, creates the ancestors as necessary. Accepts a 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'
             }
           }
         
        Parameters:
        dir - path to the directory, can either be a single level or multilevel
        dirSpec - a closure within the scope of this directory.
        Returns:
        the path to the directory
        Throws:
        IOException - if the directories could not be created.
      • file

        Path file​(String file)
           throws IOException
        Creates a file object relative to the enclosing fixture or directory, but not the physical File, it will eagerly create parent directories if necessary.
        Parameters:
        file - the (path and) filename
        Returns:
        the Path object pointing to the file
        Throws:
        IOException - if the parent directories could not be created.
      • copyFromClasspath

        Path copyFromClasspath​(String resourcePath)
                        throws IOException
        Copies a file from classpath using the contextClass to load the resource.

        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.

        Parameters:
        resourcePath - the path to the resource to load
        Returns:
        the Path pointing to the copied file
        Throws:
        IOException - if the parent directories could not be created or the resource could not be found
      • copyFromClasspath

        Path copyFromClasspath​(String resourcePath,
                               String targetName)
                        throws IOException
        Copies a file from classpath using the contextClass to load the resource.

        This will use the Closure.getOwner() of the enclosing closure to determine the contextClass.

        Parameters:
        resourcePath - the path to the resource to load
        targetName - the name of the target to use
        Returns:
        the Path pointing to the copied file
        Throws:
        IOException - if the parent directories could not be created or the resource could not be found
      • copyFromClasspath

        Path copyFromClasspath​(String resourcePath,
                               Class<?> contextClass)
                        throws IOException
        Copies a file from classpath using the contextClass to load the resource.

        The target name will be the same as the last path element of the resourcePath.

        Parameters:
        resourcePath - the path to the resource to load
        contextClass - the class to use to load the resource
        Returns:
        the Path pointing to the copied file
        Throws:
        IOException - if the parent directories could not be created or the resource could not be found
      • copyFromClasspath

        Path copyFromClasspath​(String resourcePath,
                               String targetName,
                               Class<?> contextClass)
                        throws IOException
        Copies a file from classpath using the contextClass to load the resource.
        Parameters:
        resourcePath - the path to the resource to load
        targetName - the name of the target to use
        contextClass - the class to use to load the resource
        Returns:
        the Path pointing to the copied file
        Throws:
        IOException - if the parent directories could not be created or the resource could not be found