title: Get list of files containing string(s) or pattern(s)
body: <p>Is there a Gradle pattern for retrieving the list of files in a folder or set of folders that contain a given string, set of strings, or pattern?</p>
  <p>My project produces RPMs and is using the Nebula RPM type (great package!).  There are a couple of different kinds of sets of files that need post-processing.  I am trying to generate the list of files that contain the strings that are the indicators for post-processing.  For example, files that contain &quot;@doc&quot; need to be processed by the doc generator script.  Files that contain &quot;@HOSTNAME@&quot; and &quot;@HOSTFQDN@&quot; need to be processed by sed to replace the strings with the actual host name or host fqdn.</p>
  <p>The search root in the package will be src\main\resources.  With the result the build script sets up the post-install script commands - something like:</p>
  <pre><code>postInstall('/opt/product/bin/postprocess.sh ' + join(filesContainingDocs, &quot; &quot;))
  postInstall('/bin/sed -i -e &quot;s/@HOSTNAME@/$(hostname -s)/&quot; -e s/@HOSTFQDN@/$(hostname)/&quot; ' + join(filesContainingHostname, &quot; &quot;)
  </code></pre>
  <p>I can figure out the postinstall syntax.  I'm having difficulty finding the filter for any of the regular Gradle 'things' (i.e., FileTree) that operate on contents of files rather than names of files.  How would I populate filesContainingDocs and filesContainingHostname - something along the lines of:</p>
  <pre><code>filesContainingDocs = FileTree('src/main/resources', { contents.matches('@doc') }
  filesContainingHostname = FileTree('src/main/resources', { contents.matches('@(HOSTNAME|HOSTFQDN)@') }
  </code></pre>
  <p>While the post-process script could simply do the grep, the several RPMs in our product overlay each other and each RPM should only post-process the files it provides, so a general grep over the final installed folder is not workable - it would catch files provided by other RPMs.  It seems to me that I ought to be able to, at build time, produce the correct static list of files from the bigger set of source files that comprise the given RPM's project.</p>
  <p>It doesn't have to be FileTree - running a command like <code>findstr /s /m /c:&quot;@doc&quot; src\main\resources\*.conf</code> (alas, the build platform is Windows) produces the answer in stdout but I'm not sure how to get that result into an object Gradle can use to expand the result.  (I also suspect there is a 'more Gradle way' to do this.)</p>
  <p>The set of files, and the contents of those files, is generally fairly small.</p>