ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Madunic <haj...@imag.net>
Subject Re: getting filename from dir listing
Date Fri, 21 Sep 2007 19:24:44 GMT
Thanks Gilbert.

I ran a test of your script and received the following error.


C:\RBI\VAP>test

C:\RBI\VAP>ant -f C:\RBI\VAP\antTasks\reports.xml
Buildfile: C:\RBI\VAP\antTasks\reports.xml

step01:
   [script] Sep 21, 2007 12:18:54 PM org.apache.bsf.BSFManager exec
   [script] SEVERE: Exception :
   [script] java.security.PrivilegedActionException:
org.apache.bsf.BSFException: Exception
   [script]     at java.security.AccessController.doPrivileged(Native Method)
   [script]     at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
   [script]     at
org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.java:128)
   [script]     at
org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:60)
   [script]     at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   [script]     at org.apache.tools.ant.Task.perform(Task.java:364)
   [script]     at org.apache.tools.ant.Target.execute(Target.java:341)
   [script]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
   [script]     at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   [script]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
   [script]     at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   [script]     at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   [script]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
   [script]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
   [script]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
   [script]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
   [script] Caused by: org.apache.bsf.BSFException: Exception
   [script]     at org.jruby.javasupport.bsf.JRubyEngine.exec(JRubyEngine.java:116)
   [script]     at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
   [script]     ... 16 more

BUILD FAILED
C:\RBI\VAP\antTasks\reports.xml:15: org.jruby.exceptions.RaiseException:
<script>:2: syntax error, expecting    kCLASS  kMODULE kDEF    kBEGIN  kIF    
kUNLESS kCASE   kWHILE  kUNTIL  kFOR    kBREAK  kNEXT   kREDO   kRETRY  kRETURN
kYIELD  kSUPER  kSELF   kNIL    kTRUE   kFALSE  kDEFINED        k__LINE__      
k__FILE__       tIDENTIFIER     tFID    tGVAR   tIVAR   tCONSTANT       tCVAR  
tNTH_REF        tBACK_REF       tINTEGER        tFLOAT  tUPLUS  tUMINUS
tUMINUS_NUM     tCOLON3 tLPAREN tLPAREN_ARG     tLBRACK tRBRACK tLBRACE tSTAR  
tTILDE  tBANG   tSYMBEG tSTRING_BEG     tXSTRING_BEG    tREGEXP_BEG    
tWORDS_BEG      tQWORDS_BEG but found null instead


Total time: 1 second
C:\RBI\VAP>

When i make the following change to the script to just output the filename at a
certain location of the arrray i do get a filename

<script language="ruby">
<![CDATA[
str=File.basename(Dir["J:/test/*.xml"].sort[3])
$project.setProperty "myproperty", str
]]>
</script>


<echo>
$${myproperty} == ${myproperty}
</echo>

i get the following

step01:
     [echo]
     [echo] ${myproperty} == 19750625_0003.xml

Is there something wrong with my setup or do i need to change the gsub portion.

Marijan (Mario) Madunic







---------------------------
Quoting Gilbert Rebhan <ant@schillbaer.de>:

> 
> Hi,
> 
> Mario Madunic wrote:
> > I would like to get the filename of the first file in a directory and then
> get a
> > particular part of the filename.
> > 
> > There has to be a much easier and cleaner way of doing this.
> 
> You want the first part of the filename, right ?
> 
> with a dir like that =
> J:\test>dir /B
> 20070921_0001.xml
> 20070921_0002.xml
> 20070921_0003.xml
> 
> you can go with <script>, and put the
> string in a property for further
> ant processing, i.e. =
> 
> <script language="ruby">
> <![CDATA[
> str=File.basename(Dir["J:/test/*.xml"].sort[0]).gsub(/(\w{8}).+/, $1)
> $project.setProperty "myproperty", str
> ]]>
> </script>
> ...
> <echo>
> $${myproperty} == ${myproperty}
> </echo>
> 
> will give you =
> ${myproperty} == 20070921
> 
> Regards, Gilbert
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message