You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Greg <gr...@tpg.com.au> on 2005/12/23 23:43:56 UTC

How can I automate use of LOADFILE? (i.e. to load all files in a particular directory into their properties)

Hi,

Is there a way to automatically load all files (using LOADFILE) in a
particular directory?  

That is loaded in a way such that the ANT property name will be the name of
the file.  I want to automate what I'm doing in my ANT script below which
does the LOADFILE part manually.


	<!-- HOW CAN I AUTOMATE CREATION OF THESE PROPERTIES??? -->
	<loadfile property="snippet1"
srcFile="${src}/${common}/snippet1.lsl"/>
	<loadfile property="snippet2"
srcFile="${src}/${common}/snippet2.lsl"/>

Thanks.

-----Original Message-----
From: gregsfm@tpg.com.au [mailto:gregsfm@tpg.com.au] 
Sent: Thursday, 22 December 2005 4:15 PM
To: user@ant.apache.org
Subject: RE: Is there an ANT task to replace a <TAG:filename> in the source
with the contents of the specified file???

Hi,

I've got a fair portion of this working (see below), however does anyone
know how to automate the LOADFILE part below?  

That is, automate finding all files in the "common" directory and
loading the concents of each file into a property for which the property
name is the filename?

....................................................................
<project name="MyProject" default="compile" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="common" value="common"/>
  
  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init" description="compile the source " >

	<!-- HOW CAN I AUTOMATE CREATION OF THESE PROPERTIES??? -->
	<loadfile property="snippet1"
srcFile="${src}/${common}/snippet1.lsl"/>
	<loadfile property="snippet2"
srcFile="${src}/${common}/snippet2.lsl"/>

  <copy toDir="${build}">
		<fileset dir="${src}">
			<include name="**/*.*"/>
			<exclude name="${common}/*.*"/>
		</fileset>
		<filterchain>
			<expandproperties/>
		</filterchain>
	  </copy>
  </target>

  <target name="clean"
        description="clean up" >
		<!-- Delete the ${build} and ${dist} directory trees -->
		<delete dir="${build}"/>
  </target>
</project>

....................................................................

The simplest thing would be a <copy> with a nested <filterchain>s and
<filterset>s.
Your TAG would be an Ant property in the snippet.

Jan

http://ant.apache.org/manual/CoreTypes/filterchain.html#expandproperties


>-----Ursprüngliche Nachricht-----
>Von: gregsfm@tpg.com.au [mailto:gregsfm@tpg.com.au]
>Gesendet: Montag, 19. Dezember 2005 08:08
>An: user@ant.apache.org
>Betreff: Is there an ANT task to replace a <TAG:filename> in the source 
>with the contents of the specified file???
>
>Hi,
>
>Is there an ANT task to replace a <TAG:filename> in the source with the 
>contents of the specified file???
>
>That is I working with some scripting languages where I'd like to 
>identify common code and keep these in separate files (e.g.
>like JSP TAG replacement concept but simpler).  What I'm looking for is 
>a way to specific a TAG in the source file, which within the TAG it 
>identified the file which has the common code.  Then when running the 
>ANT task and "building"
>from the SOURCE to the BUILD area the TAGS would be replaced by the 
>contents of the files.
>
>Any suggestions re how to do this with ANT?
>
>An optional (ideal) extra would be the ability to handle recursion 
>(i.e.
>a file with a snippet of text itself could contain a TAG).
>
>Thanks
>
>---------------------------------------------------------------------
>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


---------------------------------------------------------------------
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


Re: How can I automate use of LOADFILE? (i.e. to load all files in a particular directory into their properties)

Posted by Ninju Bohra <ni...@yahoo.com>.
Have you tried using the <for> task (from the ant-contrib) to loop over all the files in the directory and then call <loadfile> inside the macrodef.
 
<for param="file">
   <path>
      <fileset dir="${test.dir}/mains" includes="*.cpp"/>
   </path>
   <sequential>
      <var name="simple.name" unset="true"/>
      <basename file="@{file}" property="simple.name"/>
      <loadfile property="contents.of.${simple.name}" srcfile="@{file}"/>
   </sequential>
</for>
 
Have fun,
 
Ninju


----- Original Message ----
From: Greg <gr...@tpg.com.au>
To: Ant Users List <us...@ant.apache.org>
Sent: Friday, December 23, 2005 4:43:56 PM
Subject: How can I automate use of LOADFILE? (i.e. to load all files in a particular directory into their properties)


Hi,

Is there a way to automatically load all files (using LOADFILE) in a
particular directory?  

That is loaded in a way such that the ANT property name will be the name of
the file.  I want to automate what I'm doing in my ANT script below which
does the LOADFILE part manually.


    <!-- HOW CAN I AUTOMATE CREATION OF THESE PROPERTIES??? -->
    <loadfile property="snippet1"
srcFile="${src}/${common}/snippet1.lsl"/>
    <loadfile property="snippet2"
srcFile="${src}/${common}/snippet2.lsl"/>

Thanks.

-----Original Message-----
From: gregsfm@tpg.com.au [mailto:gregsfm@tpg.com.au] 
Sent: Thursday, 22 December 2005 4:15 PM
To: user@ant.apache.org
Subject: RE: Is there an ANT task to replace a <TAG:filename> in the source
with the contents of the specified file???

Hi,

I've got a fair portion of this working (see below), however does anyone
know how to automate the LOADFILE part below?  

That is, automate finding all files in the "common" directory and
loading the concents of each file into a property for which the property
name is the filename?

....................................................................
<project name="MyProject" default="compile" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="common" value="common"/>
  
  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init" description="compile the source " >

    <!-- HOW CAN I AUTOMATE CREATION OF THESE PROPERTIES??? -->
    <loadfile property="snippet1"
srcFile="${src}/${common}/snippet1.lsl"/>
    <loadfile property="snippet2"
srcFile="${src}/${common}/snippet2.lsl"/>

  <copy toDir="${build}">
        <fileset dir="${src}">
            <include name="**/*.*"/>
            <exclude name="${common}/*.*"/>
        </fileset>
        <filterchain>
            <expandproperties/>
        </filterchain>
      </copy>
  </target>

  <target name="clean"
        description="clean up" >
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
  </target>
</project>

....................................................................

The simplest thing would be a <copy> with a nested <filterchain>s and
<filterset>s.
Your TAG would be an Ant property in the snippet.

Jan

http://ant.apache.org/manual/CoreTypes/filterchain.html#expandproperties


>-----Ursprüngliche Nachricht-----
>Von: gregsfm@tpg.com.au [mailto:gregsfm@tpg.com.au]
>Gesendet: Montag, 19. Dezember 2005 08:08
>An: user@ant.apache.org
>Betreff: Is there an ANT task to replace a <TAG:filename> in the source 
>with the contents of the specified file???
>
>Hi,
>
>Is there an ANT task to replace a <TAG:filename> in the source with the 
>contents of the specified file???
>
>That is I working with some scripting languages where I'd like to 
>identify common code and keep these in separate files (e.g.
>like JSP TAG replacement concept but simpler).  What I'm looking for is 
>a way to specific a TAG in the source file, which within the TAG it 
>identified the file which has the common code.  Then when running the 
>ANT task and "building"
>from the SOURCE to the BUILD area the TAGS would be replaced by the 
>contents of the files.
>
>Any suggestions re how to do this with ANT?
>
>An optional (ideal) extra would be the ability to handle recursion 
>(i.e.
>a file with a snippet of text itself could contain a TAG).
>
>Thanks
>
>---------------------------------------------------------------------
>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


---------------------------------------------------------------------
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

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