ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <>
Subject Re: [ant] Determining relative paths resp. substring?
Date Fri, 16 Jan 2009 21:41:25 GMT

I had a need for something exactly like this...long story but it had to do 
with javacc :)

Anyway, my open source project Keros (url is in my sig line) has a lot of 
this type of functionality...

I am enclosing my macrodef to compute a branch:

         name        = "compute-branch"
         description = "Compute the branch based upon a root dir, @{root}, 
and full path, @{full-path}.  The branch represents the full path minus 
the root dir.  Please note:  if @{root} does not exist in @{full-path}, 
@{property} will be set with an empty value."
         uri         = "">

         <attribute  name = "root"         description = "The root of the 
path defined in @{full-path}."/>
         <attribute  name = "full-path"    description = "The absolute path 
for which @{root} is the root of the path and the branch computed is this 
path minus the root."/>
         <attribute  name = "property"     description = "The property to 
set with the branch."/>
         <attribute  name = "description"  default = ""  description = 
"Information about this macro call."/>


                 Grab data past @{root} in @{full-path}.

             <ant-contrib:propertyregex  property = 
"keros.compute-branch.COMPUTE_BRANCH"  override = "true"  input = 
"@{full-path}"  regexp = "@{root}(.*)"  select = "\1"  description = 
"Parse out the branch from the value contained in @{root}"/>


                 Remove the leading file separator (if it is there).  If it 
is not there,
                 simply use the value as is.

             <ant-contrib:propertyregex  property = "@{property}"  override 
= "true"  input = "${keros.compute-branch.COMPUTE_BRANCH}"  regexp = 
"^[${file.separator}](.*)"  replace = "\1" defaultValue = 
"${keros.compute-branch.COMPUTE_BRANCH}"  description = "Remove the 
leading file separator if its there"/>

I am using Ant Contrib's propertyregex task to do this...  Adjust URI's, 
etc for your needs :)

Let me know if you have any questions...



On Fri, 16 Jan 2009, Georg-Johann Lay wrote:

> Hi,
> can anyone assist me in solving this following quite trivial problem?
> Given a path A and the current directory B=. derermine B relative to A.
> This is needed for prefixes in zipfileset.
> In the special case that I am after B is a subdirectory (of some level)
> of A. So gettig the relative path B-A means that A and B look like this:
> A=<sting1>
> B=<sting1><string2>
> I wasted hours to figure out how this could be achieved... The regex
> stuff is too complicated because dirs may contain special chars like
> blanke, ., \, /, -, $ and even *.
> How can I easily remove the prexix A from B? I bet it is a one-liner.
> Are there low level string utilities like getting substrings, prefixes, etc?
> Thanks in advance,
> Georg-Johann
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate
Chief Architect JavaPIM

Architect Keros

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message