<!--
Purpose: Immediately after creating a new GWT web application eclipse project, this file
can config this project to use SmartGWT Pro 3.1. Files are backed-up before modifying.
Usage: cd <project base dir>
ant -f GWT2SmartGWTPro.xml smartgwtproize
Setup: need Ant-contrib, http://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-1.0b2
download jar to ANT_HOME/lib
set property SGWTPRO_HOME below.
Note: For those of you who use tools/adminConsole.jsp, after you define a database,
copy classes/server.properties to src/server.properties to avoid your changes being
overwritten by src/server.properties.
Tested for SmartGWT Pro 3.1 running on windows 7 and ubuntu 12
Coded by: Thad.Welch@gmail.com
-->
<project name="GWT2SmartGWTPro">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<property name="SGWTPRO_HOME" value="c:/Users/THAD~1.WEL/tmp/SMARTG~1.1P" />
<!-- add this comment to a xml file to flag it as being processed. Will not be processed again. -->
<property name="xml.file.mod" value="<!--smartgwtproize-->" />
<!-- add this comment to a properties file to flag it as being processes. Will not be processed again. -->
<property name="props.file.mod" value="# smartgwtproize" />
<target name="smartgwtproize" depends="modify_module_gwt_xml, modify_module_html, add_jars, modify_classpath, modify_server_properties, modify_web_xml, misc_copies">
</target>
<target name="misc_copies" depends="init_smartgwtproize">
<copy toDir="src">
<fileset file="${SGWTPRO_HOME}/samples/built-in-ds/src/log4j.isc.config.xml" />
</copy>
<copy toDir="war/WEB-INF">
<fileset file="${SGWTPRO_HOME}/samples/built-in-ds/war/WEB-INF/iscTaglib.xml" />
</copy>
</target>
<target name="modify_web_xml" depends="init_smartgwtproize, check_web_xml" unless="skip.web.xml">
<backup_file org.file.name="war/WEB-INF/web.xml" backup.file.prop.name="web.xml.backup" />
<copy file="${SGWTPRO_HOME}/samples/built-in-ds/war/WEB-INF/web.xml" todir="war/WEB-INF" overwrite="true" />
<!-- use my module's context -->
<replaceregexp file="war/WEB-INF/web.xml" flags="mg">
<regexp pattern="builtinds" />
<substitution expression="${module.name}" />
</replaceregexp>
<!-- remove HSQLDB entries -->
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="<context-param>.*context-param>" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="<listener>\s*<listener-class>.*HSQLServletContextListener</listener-class>\s*</listener>" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="\s*<\!--start hsql db.*hsqldb-->" />
<substitution expression="" />
</replaceregexp>
<!-- remove </web-app>, going to concat original web.xml file to builtin's web.xml -->
<replaceregexp file="war/WEB-INF/web.xml">
<regexp pattern="\s*</web-app>" />
<substitution expression="" />
</replaceregexp>
<!-- from GWT generated web.xml file, remove start <?xml..><web-app..."> -->
<replaceregexp file="${web.xml.backup}" flags="s">
<regexp pattern="<\?.*">" />
<substitution expression="" />
</replaceregexp>
<!-- append GWT's web.xml to builtin's web.xml -->
<concat destfile="war/WEB-INF/web.xml" append="true">
<fileset file="${web.xml.backup}" />
</concat>
<mark_xml_file regex="version="2.4">" file="war/WEB-INF/web.xml" />
</target>
<target name="modify_server_properties" depends="init_smartgwtproize, check_server_properties" unless="skip.server.properties">
<backup_file org.file.name="src/server.properties" backup.file.prop.name="server.properties.backup" />
<copy file="${SGWTPRO_HOME}/samples/built-in-ds/src/server.properties" toDir="src" />
<!-- set URLs to my context -->
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="builtinds" />
<substitution expression="${module.name}" />
</replaceregexp>
<!-- remove HSQLDB entries -->
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="sql\.HSQLDB\..*" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="(\s*sql.defaultDatabase: HSQLDB\s*)" />
<substitution expression="#\1" />
</replaceregexp>
<mark_props_file regex="\s*# The webRoot directory:\s*" file="src/server.properties" />
</target>
<!-- add SmartGWT jars entries to eclipse's .classpath file -->
<target name="modify_classpath" depends="init_smartgwtproize, check_classpath" unless="skip.classpath">
<backup_file org.file.name=".classpath" backup.file.prop.name=".classpath.backup" />
<jars_to_classpath dir="client_lib" prop.name="client.lib" />
<jars_to_classpath dir="war/WEB-INF/lib" prop.name="server.lib" />
<mark_xml_file regex="<\?xml version="1.0" encoding="UTF-8"\?>" file=".classpath" />
</target>
<!-- Add your own project specific jars here (i.e. your database JDBC implementation jar).
These jars will automatically be added to .classpath file.
-->
<target name="add_jars" depends="init_smartgwtproize">
<mkdir dir="client_lib" />
<copy todir="client_lib">
<fileset dir="${SGWTPRO_HOME}/lib" includes="smartgwt-skins.jar smartgwt.jar smartgwtpro.jar" />
</copy>
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib">
<fileset dir="${SGWTPRO_HOME}/lib" excludes="smartgwt-skins.jar smartgwt.jar smartgwtpro.jar" />
</copy>
</target>
<target name="modify_module_html" depends="init_smartgwtproize, check_module_html" unless="skip.module.html">
<backup_file org.file.name="${module.html}" backup.file.prop.name="module.html.backup" />
<!-- add isomorphicDir in javascript -->
<replaceregexp file="${module.html}" byline="true">
<regexp pattern="^(\s*<head>\s*)$" />
<substitution expression="${line.separator}
<!-- IMPORTANT : You must set the variable isomorphicDir to [MODULE_NAME]/sc/${line.separator}
so that the SmartGWT resource are correctly resolved -->${line.separator}
<script> var isomorphicDir = "${module.name}/sc/"</script>${line.separator}${line.separator}\1" />
</replaceregexp>
<!-- add DataSourceLoader in javascript -->
<replaceregexp file="${module.html}" byline="true">
<regexp pattern="^(\s*<body>\s*)$" />
<substitution expression="${line.separator}\1${line.separator}${line.separator}
<!--load the datasources -->${line.separator}
<script src="${module.name}/sc/DataSourceLoader?dataSource="></script>" />
</replaceregexp>
<mark_xml_file regex="<\!doctype html>" file="${module.html}" />
</target>
<!-- modify module's gwt.xml file unless it had already been modified. -->
<target name="modify_module_gwt_xml" depends="init_smartgwtproize, check_module_gwt_xml" unless="skip.module.gwt.xml">
<backup_file org.file.name="${gwt.xml.file}" backup.file.prop.name="gwt.xml.file.backup" />
<!-- comment out default google theme -->
<replaceregexp file="${gwt.xml.file}" byline="true">
<regexp pattern="^\s*(<inherits name='com.google.gwt.user.theme.clean.Clean'/>)\s*$" />
<substitution expression="<!--\1-->" />
</replaceregexp>
<!-- add SmartGWT modules -->
<replaceregexp file="${gwt.xml.file}" byline="true">
<regexp pattern="^(\s*<!--\s*Other module inherits\s*-->)\s*$" />
<substitution expression="\1${line.separator}
<inherits name="com.smartgwtpro.SmartGwtPro"/>${line.separator}
<inherits name="com.smartgwtpro.tools.Tools"/>${line.separator}" />
</replaceregexp>
<mark_xml_file regex="<?xml version="1.0" encoding="UTF-8"\?>" file="${gwt.xml.file}" />
</target>
<target name="check_web_xml" depends="init_smartgwtproize">
<grep match.prop="skip.web.xml" regex="${xml.file.mod}" file="war/WEB-INF/web.xml" />
</target>
<target name="check_server_properties" depends="init_smartgwtproize">
<grep match.prop="skip.server.properties" regex="${props.file.mod}" file="src/server.properties" />
</target>
<target name="check_classpath" depends="init_smartgwtproize">
<grep match.prop="skip.classpath" regex="${xml.file.mod}" file=".classpath" />
</target>
<target name="check_module_gwt_xml" depends="init_smartgwtproize">
<grep match.prop="skip.module.gwt.xml" regex="${xml.file.mod}" file="${gwt.xml.file}" />
</target>
<target name="check_module_html" depends="init_smartgwtproize">
<grep match.prop="skip.module.html" regex="${xml.file.mod}" file="${module.html}" />
</target>
<!--
define properties: module.name, module.project.name, gwt.xml.file, module.html
-->
<target name="init_smartgwtproize">
<!-- find gwt.xml file -->
<first id="first">
<fileset dir="." includes="**/*.gwt.xml" />
</first>
<property name="gwt.xml.file" value="${toString:first}" />
<loadfile property="module.line" srcfile="${gwt.xml.file}">
<filterchain>
<linecontainsregexp>
<regexp pattern="module rename-to" />
</linecontainsregexp>
</filterchain>
</loadfile>
<propertyregex property="module.name" input="${module.line}" regexp="'(.+)'" select="\1" />
<propertyregex property="module.project.name" input="${gwt.xml.file}" regexp=".*\${file.separator}(.*)\.gwt\.xml" select="\1" />
<property name="module.html" value="war/${module.project.name}.html" />
</target>
<macrodef name="grep">
<attribute name="match.prop" />
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<loadfile property="@{match.prop}" srcfile="@{file}">
<filterchain>
<linecontainsregexp>
<regexp pattern="@{regex}" />
</linecontainsregexp>
</filterchain>
</loadfile>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="mark_xml_file">
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<replaceregexp file="@{file}" byline="true">
<regexp pattern="(@{regex})" />
<substitution expression="\1${line.separator}${xml.file.mod}" />
</replaceregexp>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="mark_props_file">
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<replaceregexp file="@{file}" byline="true">
<regexp pattern="(@{regex})" />
<substitution expression="\1${line.separator}${props.file.mod}" />
</replaceregexp>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="jars_to_classpath">
<attribute name="dir" />
<attribute name="prop.name" />
<sequential>
<!-- .classpath file's classpathentry.path uses unix '/' -->
<pathconvert targetos="unix" property="@{prop.name}">
<fileset dir="@{dir}" includes="*.jar" />
<map from="${user.dir}/" to="" />
</pathconvert>
<for list="${@{prop.name}}" param="jar.file" delimiter=":">
<sequential>
<replaceregexp file=".classpath" byline="true">
<regexp pattern="^(\s*</classpath>\s*)$" />
<substitution expression=" <classpathentry kind="lib" path="@{jar.file}"/>${line.separator}\1" />
</replaceregexp>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="backup_file">
<attribute name="org.file.name" />
<attribute name="backup.file.prop.name" />
<sequential>
<if>
<available file="@{org.file.name}" />
<then>
<tstamp>
<format property="timestamp" pattern="yyyy_MM_dd_HH_mm_ss" />
</tstamp>
<property name="@{backup.file.prop.name}" value="@{org.file.name}_${timestamp}" />
<copy file="@{org.file.name}" tofile="${@{backup.file.prop.name}}" />
</then>
</if>
</sequential>
</macrodef>
</project>
Purpose: Immediately after creating a new GWT web application eclipse project, this file
can config this project to use SmartGWT Pro 3.1. Files are backed-up before modifying.
Usage: cd <project base dir>
ant -f GWT2SmartGWTPro.xml smartgwtproize
Setup: need Ant-contrib, http://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-1.0b2
download jar to ANT_HOME/lib
set property SGWTPRO_HOME below.
Note: For those of you who use tools/adminConsole.jsp, after you define a database,
copy classes/server.properties to src/server.properties to avoid your changes being
overwritten by src/server.properties.
Tested for SmartGWT Pro 3.1 running on windows 7 and ubuntu 12
Coded by: Thad.Welch@gmail.com
-->
<project name="GWT2SmartGWTPro">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<property name="SGWTPRO_HOME" value="c:/Users/THAD~1.WEL/tmp/SMARTG~1.1P" />
<!-- add this comment to a xml file to flag it as being processed. Will not be processed again. -->
<property name="xml.file.mod" value="<!--smartgwtproize-->" />
<!-- add this comment to a properties file to flag it as being processes. Will not be processed again. -->
<property name="props.file.mod" value="# smartgwtproize" />
<target name="smartgwtproize" depends="modify_module_gwt_xml, modify_module_html, add_jars, modify_classpath, modify_server_properties, modify_web_xml, misc_copies">
</target>
<target name="misc_copies" depends="init_smartgwtproize">
<copy toDir="src">
<fileset file="${SGWTPRO_HOME}/samples/built-in-ds/src/log4j.isc.config.xml" />
</copy>
<copy toDir="war/WEB-INF">
<fileset file="${SGWTPRO_HOME}/samples/built-in-ds/war/WEB-INF/iscTaglib.xml" />
</copy>
</target>
<target name="modify_web_xml" depends="init_smartgwtproize, check_web_xml" unless="skip.web.xml">
<backup_file org.file.name="war/WEB-INF/web.xml" backup.file.prop.name="web.xml.backup" />
<copy file="${SGWTPRO_HOME}/samples/built-in-ds/war/WEB-INF/web.xml" todir="war/WEB-INF" overwrite="true" />
<!-- use my module's context -->
<replaceregexp file="war/WEB-INF/web.xml" flags="mg">
<regexp pattern="builtinds" />
<substitution expression="${module.name}" />
</replaceregexp>
<!-- remove HSQLDB entries -->
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="<context-param>.*context-param>" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="<listener>\s*<listener-class>.*HSQLServletContextListener</listener-class>\s*</listener>" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="war/WEB-INF/web.xml" flags="s">
<regexp pattern="\s*<\!--start hsql db.*hsqldb-->" />
<substitution expression="" />
</replaceregexp>
<!-- remove </web-app>, going to concat original web.xml file to builtin's web.xml -->
<replaceregexp file="war/WEB-INF/web.xml">
<regexp pattern="\s*</web-app>" />
<substitution expression="" />
</replaceregexp>
<!-- from GWT generated web.xml file, remove start <?xml..><web-app..."> -->
<replaceregexp file="${web.xml.backup}" flags="s">
<regexp pattern="<\?.*">" />
<substitution expression="" />
</replaceregexp>
<!-- append GWT's web.xml to builtin's web.xml -->
<concat destfile="war/WEB-INF/web.xml" append="true">
<fileset file="${web.xml.backup}" />
</concat>
<mark_xml_file regex="version="2.4">" file="war/WEB-INF/web.xml" />
</target>
<target name="modify_server_properties" depends="init_smartgwtproize, check_server_properties" unless="skip.server.properties">
<backup_file org.file.name="src/server.properties" backup.file.prop.name="server.properties.backup" />
<copy file="${SGWTPRO_HOME}/samples/built-in-ds/src/server.properties" toDir="src" />
<!-- set URLs to my context -->
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="builtinds" />
<substitution expression="${module.name}" />
</replaceregexp>
<!-- remove HSQLDB entries -->
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="sql\.HSQLDB\..*" />
<substitution expression="" />
</replaceregexp>
<replaceregexp file="src/server.properties" byline="true">
<regexp pattern="(\s*sql.defaultDatabase: HSQLDB\s*)" />
<substitution expression="#\1" />
</replaceregexp>
<mark_props_file regex="\s*# The webRoot directory:\s*" file="src/server.properties" />
</target>
<!-- add SmartGWT jars entries to eclipse's .classpath file -->
<target name="modify_classpath" depends="init_smartgwtproize, check_classpath" unless="skip.classpath">
<backup_file org.file.name=".classpath" backup.file.prop.name=".classpath.backup" />
<jars_to_classpath dir="client_lib" prop.name="client.lib" />
<jars_to_classpath dir="war/WEB-INF/lib" prop.name="server.lib" />
<mark_xml_file regex="<\?xml version="1.0" encoding="UTF-8"\?>" file=".classpath" />
</target>
<!-- Add your own project specific jars here (i.e. your database JDBC implementation jar).
These jars will automatically be added to .classpath file.
-->
<target name="add_jars" depends="init_smartgwtproize">
<mkdir dir="client_lib" />
<copy todir="client_lib">
<fileset dir="${SGWTPRO_HOME}/lib" includes="smartgwt-skins.jar smartgwt.jar smartgwtpro.jar" />
</copy>
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib">
<fileset dir="${SGWTPRO_HOME}/lib" excludes="smartgwt-skins.jar smartgwt.jar smartgwtpro.jar" />
</copy>
</target>
<target name="modify_module_html" depends="init_smartgwtproize, check_module_html" unless="skip.module.html">
<backup_file org.file.name="${module.html}" backup.file.prop.name="module.html.backup" />
<!-- add isomorphicDir in javascript -->
<replaceregexp file="${module.html}" byline="true">
<regexp pattern="^(\s*<head>\s*)$" />
<substitution expression="${line.separator}
<!-- IMPORTANT : You must set the variable isomorphicDir to [MODULE_NAME]/sc/${line.separator}
so that the SmartGWT resource are correctly resolved -->${line.separator}
<script> var isomorphicDir = "${module.name}/sc/"</script>${line.separator}${line.separator}\1" />
</replaceregexp>
<!-- add DataSourceLoader in javascript -->
<replaceregexp file="${module.html}" byline="true">
<regexp pattern="^(\s*<body>\s*)$" />
<substitution expression="${line.separator}\1${line.separator}${line.separator}
<!--load the datasources -->${line.separator}
<script src="${module.name}/sc/DataSourceLoader?dataSource="></script>" />
</replaceregexp>
<mark_xml_file regex="<\!doctype html>" file="${module.html}" />
</target>
<!-- modify module's gwt.xml file unless it had already been modified. -->
<target name="modify_module_gwt_xml" depends="init_smartgwtproize, check_module_gwt_xml" unless="skip.module.gwt.xml">
<backup_file org.file.name="${gwt.xml.file}" backup.file.prop.name="gwt.xml.file.backup" />
<!-- comment out default google theme -->
<replaceregexp file="${gwt.xml.file}" byline="true">
<regexp pattern="^\s*(<inherits name='com.google.gwt.user.theme.clean.Clean'/>)\s*$" />
<substitution expression="<!--\1-->" />
</replaceregexp>
<!-- add SmartGWT modules -->
<replaceregexp file="${gwt.xml.file}" byline="true">
<regexp pattern="^(\s*<!--\s*Other module inherits\s*-->)\s*$" />
<substitution expression="\1${line.separator}
<inherits name="com.smartgwtpro.SmartGwtPro"/>${line.separator}
<inherits name="com.smartgwtpro.tools.Tools"/>${line.separator}" />
</replaceregexp>
<mark_xml_file regex="<?xml version="1.0" encoding="UTF-8"\?>" file="${gwt.xml.file}" />
</target>
<target name="check_web_xml" depends="init_smartgwtproize">
<grep match.prop="skip.web.xml" regex="${xml.file.mod}" file="war/WEB-INF/web.xml" />
</target>
<target name="check_server_properties" depends="init_smartgwtproize">
<grep match.prop="skip.server.properties" regex="${props.file.mod}" file="src/server.properties" />
</target>
<target name="check_classpath" depends="init_smartgwtproize">
<grep match.prop="skip.classpath" regex="${xml.file.mod}" file=".classpath" />
</target>
<target name="check_module_gwt_xml" depends="init_smartgwtproize">
<grep match.prop="skip.module.gwt.xml" regex="${xml.file.mod}" file="${gwt.xml.file}" />
</target>
<target name="check_module_html" depends="init_smartgwtproize">
<grep match.prop="skip.module.html" regex="${xml.file.mod}" file="${module.html}" />
</target>
<!--
define properties: module.name, module.project.name, gwt.xml.file, module.html
-->
<target name="init_smartgwtproize">
<!-- find gwt.xml file -->
<first id="first">
<fileset dir="." includes="**/*.gwt.xml" />
</first>
<property name="gwt.xml.file" value="${toString:first}" />
<loadfile property="module.line" srcfile="${gwt.xml.file}">
<filterchain>
<linecontainsregexp>
<regexp pattern="module rename-to" />
</linecontainsregexp>
</filterchain>
</loadfile>
<propertyregex property="module.name" input="${module.line}" regexp="'(.+)'" select="\1" />
<propertyregex property="module.project.name" input="${gwt.xml.file}" regexp=".*\${file.separator}(.*)\.gwt\.xml" select="\1" />
<property name="module.html" value="war/${module.project.name}.html" />
</target>
<macrodef name="grep">
<attribute name="match.prop" />
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<loadfile property="@{match.prop}" srcfile="@{file}">
<filterchain>
<linecontainsregexp>
<regexp pattern="@{regex}" />
</linecontainsregexp>
</filterchain>
</loadfile>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="mark_xml_file">
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<replaceregexp file="@{file}" byline="true">
<regexp pattern="(@{regex})" />
<substitution expression="\1${line.separator}${xml.file.mod}" />
</replaceregexp>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="mark_props_file">
<attribute name="regex" />
<attribute name="file" />
<sequential>
<if>
<available file="@{file}" />
<then>
<replaceregexp file="@{file}" byline="true">
<regexp pattern="(@{regex})" />
<substitution expression="\1${line.separator}${props.file.mod}" />
</replaceregexp>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="jars_to_classpath">
<attribute name="dir" />
<attribute name="prop.name" />
<sequential>
<!-- .classpath file's classpathentry.path uses unix '/' -->
<pathconvert targetos="unix" property="@{prop.name}">
<fileset dir="@{dir}" includes="*.jar" />
<map from="${user.dir}/" to="" />
</pathconvert>
<for list="${@{prop.name}}" param="jar.file" delimiter=":">
<sequential>
<replaceregexp file=".classpath" byline="true">
<regexp pattern="^(\s*</classpath>\s*)$" />
<substitution expression=" <classpathentry kind="lib" path="@{jar.file}"/>${line.separator}\1" />
</replaceregexp>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="backup_file">
<attribute name="org.file.name" />
<attribute name="backup.file.prop.name" />
<sequential>
<if>
<available file="@{org.file.name}" />
<then>
<tstamp>
<format property="timestamp" pattern="yyyy_MM_dd_HH_mm_ss" />
</tstamp>
<property name="@{backup.file.prop.name}" value="@{org.file.name}_${timestamp}" />
<copy file="@{org.file.name}" tofile="${@{backup.file.prop.name}}" />
</then>
</if>
</sequential>
</macrodef>
</project>