You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Matthew Jaggard <an...@jaggard.org.uk> on 2010/07/19 17:00:28 UTC

[Newbie] Nice way of concatenating files

Hi,
   Sorry for the newbie question. I have written a task to concatenate
files but want to do it better (in a more platform independent way) as
it currently relies on "cat" being an available executable. Can anyone
tell me how to do this using the <concat> task or anything?

	<target name="-pre-compile">
		<apply executable="cat">
			<arg value="${web.docbase.dir}/header.html "/>
			<srcfile/>
			<arg value="${web.docbase.dir}/footer.html "/>
			<fileset dir="${web.docbase.dir}/" includes="*.html.part" excludes="" />
			<mapper type="glob" from="*.html.part" to="*.html"/>
			<redirector>
				<outputmapper id="out" type="glob" from="*.html.part"
to="${build.web.dir}/*.html"/>
			</redirector>
		</apply>
	</target>


Many thanks,
Mat.

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


Re: [Newbie] Nice way of concatenating files

Posted by Matthew Jaggard <ma...@jaggard.org.uk>.
Perfect! Thank you very much. The code I ended up using is...

	<target name="-pre-compile">
		<copy todir="${build.web.dir}">
			<fileset dir="${web.docbase.dir}" includes="*.html.part" excludes="" />
			<filterchain>
				<concatfilter prepend="${web.docbase.dir}/header.html"
append="${web.docbase.dir}/footer.html" />
			</filterchain>
			<mapper type="glob" from="*.html.part" to="*.html" />
		</copy>
	</target>

Thanks again to all who answered,
Mat.

On 19 July 2010 17:29, Jonathan Rosenberg <jr...@tabbysplace.org> wrote:
> How about this (untested):
>
>        <copy todir='... if needed ...'>
>                <fileset dir='/web' includes='*.html' excludes='... if
> needed...' />
>                <filterchain>
>                        <concatfilter prepend=' header.html'
> append='footer.html' />
>                </filterchain>
>                <mapper type='glob' from='*.part to='*.html' />
>        </copy>
>
> If this isn't correct, it should be very close to gthe answer.
>
> --
> Jonathan Rosenberg
> Founder & Executive Director, Tabby's Place
> http://www.tabbysplace.org/
>
>
>
>
> -----Original Message-----
> From: Matthew Jaggard [mailto:matthew@jaggard.org.uk]
> Sent: Monday, July 19, 2010 11:40 AM
> To: Ant Users List
> Subject: Re: [Newbie] Nice way of concatenating files
>
> I saw this but couldn't work out how to apply it to a selection of
> files as my script does. It needs to look for all scripts labeled
> *.html.part and concatenate header.html, the file and then footer.html
> to create *.html. For example for the following directory...
>
> /web:
> index.html.part
> page1.html.part
>
> I need to create
> index.html from header.html + index.html.part + footer.html
> and
> page1.html from header.html + page1.html.part + footer.html
>
> Thanks,
> Mat.
>
> On 19 July 2010 16:06, Jonathan Rosenberg <jr...@tabbysplace.org> wrote:
>> Ant's <concat/> task is what you want:
>>
>>        http://ant.apache.org/manual/index.html
>>
>> --
>> Jonathan Rosenberg
>> Founder & Executive Director, Tabby's Place
>> http://www.tabbysplace.org/
>>
>>
>> -----Original Message-----
>> From: matthew@jaggard.org.uk [mailto:matthew@jaggard.org.uk] On Behalf Of
>> Matthew Jaggard
>> Sent: Monday, July 19, 2010 11:00 AM
>> To: user
>> Subject: [Newbie] Nice way of concatenating files
>>
>> Hi,
>>   Sorry for the newbie question. I have written a task to concatenate
>> files but want to do it better (in a more platform independent way) as
>> it currently relies on "cat" being an available executable. Can anyone
>> tell me how to do this using the <concat> task or anything?
>>
>>        <target name="-pre-compile">
>>                <apply executable="cat">
>>                        <arg value="${web.docbase.dir}/header.html "/>
>>                        <srcfile/>
>>                        <arg value="${web.docbase.dir}/footer.html "/>
>>                        <fileset dir="${web.docbase.dir}/"
>> includes="*.html.part" excludes="" />
>>                        <mapper type="glob" from="*.html.part"
> to="*.html"/>
>>                        <redirector>
>>                                <outputmapper id="out" type="glob"
>> from="*.html.part"
>> to="${build.web.dir}/*.html"/>
>>                        </redirector>
>>                </apply>
>>        </target>
>>
>>
>> Many thanks,
>> Mat.
>>
>> ---------------------------------------------------------------------
>> 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


RE: [Newbie] Nice way of concatenating files

Posted by Jonathan Rosenberg <jr...@tabbysplace.org>.
How about this (untested):

	<copy todir='... if needed ...'>
		<fileset dir='/web' includes='*.html' excludes='... if
needed...' />
		<filterchain>
			<concatfilter prepend=' header.html'
append='footer.html' />
		</filterchain>
		<mapper type='glob' from='*.part to='*.html' />
	</copy>

If this isn't correct, it should be very close to gthe answer.

--
Jonathan Rosenberg
Founder & Executive Director, Tabby's Place
http://www.tabbysplace.org/




-----Original Message-----
From: Matthew Jaggard [mailto:matthew@jaggard.org.uk] 
Sent: Monday, July 19, 2010 11:40 AM
To: Ant Users List
Subject: Re: [Newbie] Nice way of concatenating files

I saw this but couldn't work out how to apply it to a selection of
files as my script does. It needs to look for all scripts labeled
*.html.part and concatenate header.html, the file and then footer.html
to create *.html. For example for the following directory...

/web:
index.html.part
page1.html.part

I need to create
index.html from header.html + index.html.part + footer.html
and
page1.html from header.html + page1.html.part + footer.html

Thanks,
Mat.

On 19 July 2010 16:06, Jonathan Rosenberg <jr...@tabbysplace.org> wrote:
> Ant's <concat/> task is what you want:
>
>        http://ant.apache.org/manual/index.html
>
> --
> Jonathan Rosenberg
> Founder & Executive Director, Tabby's Place
> http://www.tabbysplace.org/
>
>
> -----Original Message-----
> From: matthew@jaggard.org.uk [mailto:matthew@jaggard.org.uk] On Behalf Of
> Matthew Jaggard
> Sent: Monday, July 19, 2010 11:00 AM
> To: user
> Subject: [Newbie] Nice way of concatenating files
>
> Hi,
>   Sorry for the newbie question. I have written a task to concatenate
> files but want to do it better (in a more platform independent way) as
> it currently relies on "cat" being an available executable. Can anyone
> tell me how to do this using the <concat> task or anything?
>
>        <target name="-pre-compile">
>                <apply executable="cat">
>                        <arg value="${web.docbase.dir}/header.html "/>
>                        <srcfile/>
>                        <arg value="${web.docbase.dir}/footer.html "/>
>                        <fileset dir="${web.docbase.dir}/"
> includes="*.html.part" excludes="" />
>                        <mapper type="glob" from="*.html.part"
to="*.html"/>
>                        <redirector>
>                                <outputmapper id="out" type="glob"
> from="*.html.part"
> to="${build.web.dir}/*.html"/>
>                        </redirector>
>                </apply>
>        </target>
>
>
> Many thanks,
> Mat.
>
> ---------------------------------------------------------------------
> 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: [Newbie] Nice way of concatenating files

Posted by Shawn Castrianni <Sh...@halliburton.com>.
This worked in my test.  It uses the antcontrib tasks called "for" and "var" declared using the xmlns within the root <project> element.


<project name="concat-test" xmlns:ac="antlib:net.sf.antcontrib">
   <target name="concat-test">
	<!--Loop over each html.part file found in webparts directory-->
      <ac:for param="webPartFile">
         <fileset dir="${basedir}/webparts">
            <include name="*.html.part"/>
         </fileset>
         <sequential>
		<!--Use antcontrib to clear out property for each loop iteration since ant properties are immutable-->
            <ac:var name="webPartFileRoot" unset="true"/>
		<!--Calculate root file name of web part minus any directories and extensions-->
            <basename property="webPartFileRoot" file="@{webPartFile}" suffix=".html.part"/>
		<!--Perform concatenation specifying the header and footer from a webtemplates directory and output to web directory-->
            <concat destfile="${basedir}/web/${webPartFileRoot}.html">
               <header file="${basedir}/webtemplates/header.html"/>
               <fileset file="@{webPartFile}"/>
               <footer file="${basedir}/webtemplates/footer.html"/>
            </concat>
         </sequential>
      </ac:for>
   </target>
</project>

---
Shawn Castrianni

-----Original Message-----
From: Matthew Jaggard [mailto:matthew@jaggard.org.uk] 
Sent: Monday, July 19, 2010 10:40 AM
To: Ant Users List
Subject: Re: [Newbie] Nice way of concatenating files

I saw this but couldn't work out how to apply it to a selection of
files as my script does. It needs to look for all scripts labeled
*.html.part and concatenate header.html, the file and then footer.html
to create *.html. For example for the following directory...

/web:
index.html.part
page1.html.part

I need to create
index.html from header.html + index.html.part + footer.html
and
page1.html from header.html + page1.html.part + footer.html

Thanks,
Mat.

On 19 July 2010 16:06, Jonathan Rosenberg <jr...@tabbysplace.org> wrote:
> Ant's <concat/> task is what you want:
>
>        http://ant.apache.org/manual/index.html
>
> --
> Jonathan Rosenberg
> Founder & Executive Director, Tabby's Place
> http://www.tabbysplace.org/
>
>
> -----Original Message-----
> From: matthew@jaggard.org.uk [mailto:matthew@jaggard.org.uk] On Behalf Of
> Matthew Jaggard
> Sent: Monday, July 19, 2010 11:00 AM
> To: user
> Subject: [Newbie] Nice way of concatenating files
>
> Hi,
>   Sorry for the newbie question. I have written a task to concatenate
> files but want to do it better (in a more platform independent way) as
> it currently relies on "cat" being an available executable. Can anyone
> tell me how to do this using the <concat> task or anything?
>
>        <target name="-pre-compile">
>                <apply executable="cat">
>                        <arg value="${web.docbase.dir}/header.html "/>
>                        <srcfile/>
>                        <arg value="${web.docbase.dir}/footer.html "/>
>                        <fileset dir="${web.docbase.dir}/"
> includes="*.html.part" excludes="" />
>                        <mapper type="glob" from="*.html.part" to="*.html"/>
>                        <redirector>
>                                <outputmapper id="out" type="glob"
> from="*.html.part"
> to="${build.web.dir}/*.html"/>
>                        </redirector>
>                </apply>
>        </target>
>
>
> Many thanks,
> Mat.
>
> ---------------------------------------------------------------------
> 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

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

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


Re: [Newbie] Nice way of concatenating files

Posted by Matthew Jaggard <ma...@jaggard.org.uk>.
I saw this but couldn't work out how to apply it to a selection of
files as my script does. It needs to look for all scripts labeled
*.html.part and concatenate header.html, the file and then footer.html
to create *.html. For example for the following directory...

/web:
index.html.part
page1.html.part

I need to create
index.html from header.html + index.html.part + footer.html
and
page1.html from header.html + page1.html.part + footer.html

Thanks,
Mat.

On 19 July 2010 16:06, Jonathan Rosenberg <jr...@tabbysplace.org> wrote:
> Ant's <concat/> task is what you want:
>
>        http://ant.apache.org/manual/index.html
>
> --
> Jonathan Rosenberg
> Founder & Executive Director, Tabby's Place
> http://www.tabbysplace.org/
>
>
> -----Original Message-----
> From: matthew@jaggard.org.uk [mailto:matthew@jaggard.org.uk] On Behalf Of
> Matthew Jaggard
> Sent: Monday, July 19, 2010 11:00 AM
> To: user
> Subject: [Newbie] Nice way of concatenating files
>
> Hi,
>   Sorry for the newbie question. I have written a task to concatenate
> files but want to do it better (in a more platform independent way) as
> it currently relies on "cat" being an available executable. Can anyone
> tell me how to do this using the <concat> task or anything?
>
>        <target name="-pre-compile">
>                <apply executable="cat">
>                        <arg value="${web.docbase.dir}/header.html "/>
>                        <srcfile/>
>                        <arg value="${web.docbase.dir}/footer.html "/>
>                        <fileset dir="${web.docbase.dir}/"
> includes="*.html.part" excludes="" />
>                        <mapper type="glob" from="*.html.part" to="*.html"/>
>                        <redirector>
>                                <outputmapper id="out" type="glob"
> from="*.html.part"
> to="${build.web.dir}/*.html"/>
>                        </redirector>
>                </apply>
>        </target>
>
>
> Many thanks,
> Mat.
>
> ---------------------------------------------------------------------
> 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: [Newbie] Nice way of concatenating files

Posted by Jonathan Rosenberg <jr...@tabbysplace.org>.
Ant's <concat/> task is what you want:

	http://ant.apache.org/manual/index.html

--
Jonathan Rosenberg
Founder & Executive Director, Tabby's Place
http://www.tabbysplace.org/


-----Original Message-----
From: matthew@jaggard.org.uk [mailto:matthew@jaggard.org.uk] On Behalf Of
Matthew Jaggard
Sent: Monday, July 19, 2010 11:00 AM
To: user
Subject: [Newbie] Nice way of concatenating files

Hi,
   Sorry for the newbie question. I have written a task to concatenate
files but want to do it better (in a more platform independent way) as
it currently relies on "cat" being an available executable. Can anyone
tell me how to do this using the <concat> task or anything?

	<target name="-pre-compile">
		<apply executable="cat">
			<arg value="${web.docbase.dir}/header.html "/>
			<srcfile/>
			<arg value="${web.docbase.dir}/footer.html "/>
			<fileset dir="${web.docbase.dir}/"
includes="*.html.part" excludes="" />
			<mapper type="glob" from="*.html.part" to="*.html"/>
			<redirector>
				<outputmapper id="out" type="glob"
from="*.html.part"
to="${build.web.dir}/*.html"/>
			</redirector>
		</apply>
	</target>


Many thanks,
Mat.

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