ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arun <arun.george.1...@gmail.com>
Subject Replacing tokens in file does not work!!
Date Mon, 02 Jun 2008 15:20:17 GMT
Hi,

I am trying to implement a build number system where all static files in my
web application will have a build number appended the filenames.
Basically I am caching everything and when a new build happens all cache
should get cleared.
I have done renaming the files using <mapper> inside <fileset> element.
As a second step I need to add the same to all the filenames inside jsps
like accountmanager.js should be accountmanager_1.0.b25.js.
I have created a properties file which contain the original filenames. I
have used <pathconvert> and my own ant task to do this.
So this propery file gives all files that needs to be renamed and its new
name with build number appended.
AJAX_loading.gif=AJAX_loading_1.0.b30.gif
ajax-loading-wheel.gif=ajax-loading-wheel_1.0.b30.gif
ajax_loading2.gif=ajax_loading2_1.0.b30.gif
blue-gradient.gif=blue-gradient_1.0.b30.gif
calendar-hilite.gif=calendar-hilite_1.0.b30.gif
calendar-icon.gif=calendar-icon_1.0.b30.gif
calendar-next.gif=calendar-next_1.0.b30.gif
calendar-prev.gif=calendar-prev_1.0.b30.gif
calendar-td.gif=calendar-td_1.0.b30.gif
calendar-valid.gif=calendar-valid_1.0.b30.gif
calendar.gif=calendar_1.0.b30.gif
calendar.png=calendar_1.0.b30.png
calendar4.png=calendar4_1.0.b30.png
frw8at_ajaxldr_3.gif=frw8at_ajaxldr_3_1.0.b30.gif
accountmanager.js=accountmanager_1.0.b30.js
calendar.js=calendar_1.0.b30.js
mootools.js=mootools_1.0.b30.js
common.js=common_1.0.b30.js
jquery-1.2.5.min.js=jquery-1.2.5.min_1.0.b30.js
jquery.corner.js=jquery.corner_1.0.b30.js
jquery.easing.1.2.js=jquery.easing.1.2_1.0.b30.js
leavemanager.js=leavemanager_1.0.b30.js
reportingmanager.js=reportingmanager_1.0.b30.js
alternate.css=alternate_1.0.b30.css
calendar.css=calendar_1.0.b30.css
iframe.css=iframe_1.0.b30.css
main.css=main_1.0.b30.css



I dont want to add @ @ to my tokens as that is not practical. I just want to
replace all occurences of these tokens inside all the jsp's with values as
in property file. I tried it for so long and finally came to filter chain ,
but it also did not do the job.
Does not ant have a way of replacing strings?.
Can I not have a token without any beginning and ending token?
I just want to rename the filenames inside the jsps. I dont want to edit my
jsps and add beginning token and ending token.
I tried ReplaceToken chain , but no help.
Any help is appreciated.


This is what I tried.

<copy todir="${web.build.dir}" >
<fileset dir="web"/>
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
<param type="propertiesfile"
value="build_number_appended_files.properties"/>
</filterreader>
</filterchain>
<filterset begintoken="@" endtoken="@"
filtersfile="config/somecompanyempbuild.properties"/>
</copy>


Basically I have a fileset which matches certain file extensions and have a
property file which contain string to be replaced and its substitutions. I
dont want to follow any beginning token and end token fashions for this
inside any jsps.
My aim is to replace all static urls with a url which has a build number.
For this all I want to search is for a filename which is static and see its
substition and replace it.

Is it not possible to just do a simple string replace using fileset and
property files.
Any help would be grealty appreciated.
My caching system hangs on it.




This is my full build.xml
<project name="somecompanyemp" basedir="." default="war">
<property name="build.dir" value="build"/>
<property name="war.build.dir" value="build/war"/>
<property name="web.build.dir" value="build/web"/>
<property name="dist.dir" value="dist"/>
<property name="junit.output.dir" value="junit"/>
<property file="config/somecompanyempbuild.properties"/>

<buildnumber/>
<property name="build.token" value="_1.0.b${build.number}"/>
<property name="build.token.without_underscore"
value="1.0.b${build.number}"/>
<propertyfile
file="config/somecompanyempbuild.properties"
comment="Build Properties">
<entry key="version" value="${build.token.without_underscore}"/>
</propertyfile>
<path id="project.classpath">
<fileset dir="lib" includes="*.jar" />
<fileset dir="lib/tool" includes="*.jar" />
<fileset dir="lib/proj" includes="*.jar" />
<pathelement location="config" />
<pathelement location="config/spring" />
</path>
<target name="init">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${web.build.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${war.build.dir}"/>
<mkdir dir="${web.build.dir}"/>
</target>
<target name="compile" depends="init">
<javac classpathref="project.classpath" destdir="${build.dir}" srcdir="src"
debug="true"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${build.dir}/emails"/>
<copy todir="${build.dir}/emails">
<fileset dir="config/emails">
<include name="**/*.*"/>
</fileset>
</copy>
<mkdir dir="${build.dir}/xml"/>
<copy todir="${build.dir}/xml">
<fileset dir="config/xml">
<include name="**/*.*"/>
</fileset>
</copy>
<jar destfile="${dist.dir}/somecompanyemp.jar">
<fileset file="config/applicationContext.xml"/>
<fileset file="config/somecompanyempbuild.properties"/>
<fileset file="config/somecompanyempenv.properties"/>
<fileset file="config/log4j.properties"/>
<fileset dir="${build.dir}"/>
<metainf file="config/META-INF/persistence.xml"/>
</jar>
</target>
<target name="login-conf-jar" depends="compile">
<jar destfile="${dist.dir}/somecompanymep-login-config.jar">
<fileset dir="${build.dir}">
<include name="com/somecompany/emp/login/*"/>
</fileset>
</jar>
</target>
<target name="war" depends="jar">
<!--START Create a properties file which contain the old filename and ant
build filenames-->
<taskdef name="buildnumberappender"
classname="com.somecompany.internal.util.BuildNumberGenerator"
classpath="build" />
<fileset dir="web" id="build_number_changed.files">
<include name="**/*.jpg"/>
<include name="**/*.gif"/>
<include name="**/*.bmp"/>
<include name="**/*.png"/>
<include name="**/*.js"/>
<include name="**/*.css"/>
</fileset>
<pathconvert pathsep="," property="build_number_appended_files"
refid="build_number_changed.files">
<mapper type="flatten"/>
</pathconvert>
<buildnumberappender filenamelist="${build_number_appended_files}"
buildnumber="${build.token}" />
<!--END Create a properties file which contain the old filename and ant
build filenames-->
<copy todir="${web.build.dir}" >
<fileset dir="web"/>
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
<param type="propertiesfile"
value="build_number_appended_files.properties"/>
</filterreader>
</filterchain>
<filterset begintoken="@" endtoken="@"
filtersfile="config/somecompanyempbuild.properties"/>
</copy>
<!-- See web.xml . Web.xml filters are converted to build numbers. -->
<move todir="${web.build.dir}" filtering="true">
<fileset dir="${web.build.dir}">
<include name="**/*.jpg"/>
<include name="**/*.gif"/>
<include name="**/*.bmp"/>
<include name="**/*.png"/>
<include name="**/*.js"/>
<include name="**/*.css"/>
</fileset>
<mapper type="regexp" from="^(.*?)\.(jpg|gif|bmp|png|js|css)$$"
to="\1${build.token}.\2"/>
</move>
<copy todir="${war.build.dir}" >
<fileset dir="${web.build.dir}">
<include name="**/*.*"/>
</fileset>
</copy>
<mkdir dir="${war.build.dir}/WEB-INF/classes"/>
<mkdir dir="${war.build.dir}/WEB-INF/lib"/>
<copy todir="${war.build.dir}/WEB-INF/classes">
<fileset dir="src">
<include name="*.*"/>
</fileset>
</copy>
<copy todir="${war.build.dir}" file="config/somecompanyempenv.properties"/>
<copy todir="${war.build.dir}"
file="config/somecompanyempbuild.properties"/>
<copy todir="${war.build.dir}/WEB-INF"
file="config/applicationContext.xml"/>
<copy todir="${war.build.dir}/WEB-INF/classes" file="config/struts.xml"/>
<copy todir="${war.build.dir}/WEB-INF/lib">
<fileset dir="lib/proj">
<include name="*.*"/>
</fileset>
<fileset dir="lib/tool">
<include name="*.*"/>
</fileset>
<fileset dir="${dist.dir}">
<include name="*.*"/>
</fileset>
</copy>
<jar destfile="${dist.dir}/somecompanyemp.war">
<fileset dir="${war.build.dir}">
<include name="**/*"/>
</fileset>
</jar>
<mkdir dir="D:/apache-tomcat-5.5.20/webapps/somecompanyemp"/>
<copy todir="D:/apache-tomcat-5.5.20/webapps/somecompanyemp" >
<fileset dir="${war.build.dir}" />
</copy>
</target>
<target name="runtests">
<antcall target="EmployeeManagerTest"/>
</target>
<target name="EmployeeManagerTest">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<classpath>
<pathelement location="${build.dir}" />
</classpath>
<classpath refid="project.classpath"/>
<formatter type="xml"/>
<test name="com.somecompany.emp.tests.EmployeeManagerTest"
todir="${junit.output.dir}"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>




































-- 
Thanks
Arun George

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message