title: How to get the relative path of files in a SourceDirectorySet
body: <p>I want to process some sources from a directory structure using a <a href="https://docs.gradle.org/current/javadoc/org/gradle/api/file/SourceDirectorySet.html" rel="nofollow" title="Gradle API: SourceDirectorySet"><code>SourceDirectorySet</code></a> and I'd like to save the output under the build dir, mimicking the original dir structure. E.g.:</p>
  
  <pre class="lang-none prettyprint-override"><code>src / main / plantuml
                  + dir1
                     + dir11
                         + file.pu
  </code></pre>
  
  <p>Should result in:</p>
  
  <pre class="lang-none prettyprint-override"><code>build / doc / plantuml
                  + dir1
                     + dir11
                         + file.png
  </code></pre>
  
  <p>How could I achieve it?</p>
  
  <p>N.B.: <code>SourceDirectorySet</code> is <a href="https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html" rel="nofollow" title="Gradle API: PatternFilterable"><code>PatternFilterable</code></a></p>
  
  <h3>Background</h3>
  
  <p>I want to extend janvolck's plugin <a href="https://github.com/janvolck/gradle-plantuml-plugin" rel="nofollow" title="gradle-plantuml-plugin">"gradle-plantuml-plugin"</a> (there is already a <a href="https://github.com/janvolck/gradle-plantuml-plugin/issues/7" rel="nofollow" title="gradle-plantuml-plugin#7 Generate diagrams under build directory instead">corresponding feature request</a>), so that it generates its output files under a configured directory but maintaining the original directory hierarchy. The current implementation of the gradle plugin traverses all files of a <code>SourceDirectorySet</code> and generates the output files in the same directory where the source files live.</p>
  
  <p>This is the closest I could come out with:</p>
  
  <pre class="lang-gradle prettyprint-override"><code>// Process directory trees
  mySourceDirectorySet.srcDirTrees.each { DirectoryTree d -&gt;
      project.logger.debug("Processing srcDirTree " + d.dir
          + "; patterns.excludes: " + d.patterns.excludes
          + "; patterns.includes" + d.patterns.includes)
  
      // Reconstruct a FileTree from the directory tree, as I cannot find
      // any means to get the files directly from 'd' (1)
      // ... and traverse its files
      project.fileTree(dir: d.dir,
          excludes: d.patterns.excludes,
          includes: d.patterns.includes).each { File f -&gt;
              project.logger.info("-- Input file: " + f)
  
              def relPath = d.dir.toURI().relativize(f.parentFile.toURI())
              def outputPath = "/myOutputDir/" + relPath
  
              option.setOutputDir(project.file(outputPath))
              processFile(f, option);
      }
  }
  </code></pre>
  
  <p>Unfortunatelly, the trick in <code>(1)</code> doesn't seem to work and I cannot recreate an appropriate FileTree.</p>
  
  <p>My untrained gradle intuition says it should be easy to achieve this task. I'm surely missing something?</p>