Bugs item #1305673, was opened at 2005-09-27 18:11
Message generated for change (Comment added) made by henryl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1305673&group_id=31650

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Henry (henryl)
Assigned to: Nobody/Anonymous (nobody)
Summary: Adding a regex filter

Initial Comment:
Attached is a build file to enable a regular expression
filter to be used as part of a filter chain. It gives
far more powerful filtering of data than (for example)
replacetokens.

Enable it by including it in your nant config file...

    <include buildfile="regex.build" />


Here is an example bit of a task to copy (and filter) a
version.h header file to include build information:

    <copy file="${source_filename}"
tofile="${version_header_filename}">
        <filterchain>
           <regex pattern="(MAJOR_FILE_VER)(.*)"
replacement="$1
${version::get-major(build::get-version())}" />
           <regex pattern="(MINOR_FILE_VER)(.*)"
replacement="$1
${version::get-minor(build::get-version()) / 10}" />
           <regex pattern="(PRIVATE_FILE_VER)(.*)"
replacement="$1
${version::get-minor(build::get-version()) % 10}" />
           <regex pattern="(BUILD_FILE_VER)(.*)"
replacement="$1
${version::get-build(build::get-version())}" />
                
           <regex pattern="(PRODUCT_COMMENTS)(.*)"
replacement='$1 "Release of ${ReleaseName} built on
${environment::get-machine-name()} by
${environment::get-user-name()}\r\nBuild started on
${datetime::now()}"' />

           <!-- Strip out comments. Note that we want
to strip out the entire line, so we include the new
line characters. -->               
           <regex pattern="[\r\n]+//.*" replacement="" />

           <!-- Add a note before the initial header
guard that this is the generated copy. Note the new
line characters. -->
           <regex pattern="(.*ifndef.*)"
replacement="// This is an automatically generated copy
of the file at ${source_filename}&#xD;&#xA;$1" />
        </filterchain>
    </copy>

Note that this is using a custom build::get-version()
function, but you get the idea.

The code can be trivially extraced from the build file
and put directly in the nant source (I put it in a
script so I wouldn't have to update everybody's copy of
nant).

Hope someone will find it useful (possibly for
inclusion as a default filter in nant).

----------------------------------------------------------------------

>Comment By: Henry (henryl)
Date: 2006-07-03 19:03

Message:
Logged In: YES 
user_id=1083163

Modification to allow setting of regex options. For example,
to extract the assembly name from a csproj, you could do the
following;

<!-- Extract the assembly name from the project -->
<loadfile file="some.csproj" property="project.name">
  <filterchain>
    <regex pattern=".*?AssemblyName = &quot;(.*?)&quot;.*"
replacement="$1" options="Singleline" />
  </filterchain>
</loadfile>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1305673&group_id=31650

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
nant-developers mailing list
nant-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to