[Yanel-commits] rev 41801 - public/yanel/trunk/src/build/targets/webapp

guillaume at wyona.com guillaume at wyona.com
Thu Mar 5 11:40:25 CET 2009


Author: guillaume
Date: 2009-03-05 11:40:25 +0100 (Thu, 05 Mar 2009)
New Revision: 41801

Modified:
   public/yanel/trunk/src/build/targets/webapp/cluster.xml
Log:
Refactored Ant code handling endorsed JARs using macros.

Issue: 7001


Modified: public/yanel/trunk/src/build/targets/webapp/cluster.xml
===================================================================
--- public/yanel/trunk/src/build/targets/webapp/cluster.xml	2009-03-05 10:14:57 UTC (rev 41800)
+++ public/yanel/trunk/src/build/targets/webapp/cluster.xml	2009-03-05 10:40:25 UTC (rev 41801)
@@ -1,6 +1,8 @@
 <?xml version="1.0"?>
 
-<project name="cluster" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+<project name="cluster"
+ xmlns:yanel="http://www.wyona.org/yanel/1.0"
+>
 
   <target name="deploy-to-tomcat-cluster-node1" if="property-tomcat-cluster-node1-is-set" description="Deploy webapp to Tomcat cluster node 1">
     <echo>Copy webapp (${tomcat1.webapps.dir}):</echo>
@@ -17,22 +19,25 @@
     <touch file="${log4j.path}/log4j-cnode1.log"/>
 
     <antcall target="patch-tomcat-cluster-node-1-ssl-port"/>
+    
+    <yanel:check-endorsed-jar jarId="stax-api"/>
+    
+    <yanel:check-endorsed-jar jarId="stax-impl"/>
+  </target>
 
-    <condition property="endorsed-stax-api-at-node1-does-not-exist-yet">
+  <macrodef name="check-endorsed-jar" uri="http://www.wyona.org/yanel/1.0">
+   <attribute name="jarId"/>
+   <attribute name="serverNode" default="1"/>
+   <attribute name="target-dir" default="${tomcat@{serverNode}.home.dir}/common/endorsed"/>
+   <sequential>
+    <condition property="endorsed-@{jarId}-at-node@{serverNode}-does-not-exist-yet">
       <not>
-        <available file="${tomcat1.home.dir}/common/endorsed/${stax-api.artifactId}-${stax-api.version}.jar"/>
+        <available file="@{target-dir}/${@{jarId}.artifactId}-${@{jarId}.version}.jar"/>
       </not>
     </condition>
-    <antcall target="ask-to-copy-endorsed-stax-api-to-node1"/>
-    
-    <condition property="endorsed-stax-impl-at-node1-does-not-exist-yet">
-      <not>
-        <available file="${tomcat1.home.dir}/common/endorsed/${stax-impl.artifactId}-${stax-impl.version}.jar"/>
-      </not>
-    </condition>
-    <antcall target="ask-to-copy-endorsed-stax-impl-to-node1"/>
-    
-  </target>
+    <antcall target="ask-to-copy-endorsed-@{jarId}-to-node@{serverNode}"/>
+   </sequential>
+  </macrodef>
 
   <target name="copy-webapp-files-to-tomcat-cluster-node1" depends="init">
     <copy todir="${tomcat1.webapps.dir}/${servlet.context.prefix}">
@@ -78,84 +83,73 @@
 
     <antcall target="patch-tomcat-cluster-node-2-ssl-port"/>
 
-    <condition property="endorsed-stax-api-at-node2-does-not-exist-yet">
-      <not>
-        <available file="${tomcat2.home.dir}/common/endorsed/${stax-api.artifactId}-${stax-api.version}.jar"/>
-      </not>
-    </condition>
-    <antcall target="ask-to-copy-endorsed-stax-api-node2"/>
+    <yanel:check-endorsed-jar jarId="stax-api" serverNode="2"/>
 
-    <condition property="endorsed-stax-impl-at-node2-does-not-exist-yet">
-      <not>
-        <available file="${tomcat2.home.dir}/common/endorsed/${stax-impl.artifactId}-${stax-impl.version}.jar"/>
-      </not>
-    </condition>
-    <antcall target="ask-to-copy-endorsed-stax-impl-to-node2"/>
+    <yanel:check-endorsed-jar jarId="stax-impl" serverNode="2"/>
   </target>
 
 
 
-  <!--XXX HACK: The following code is a copy-paste orgy, fixing it is now bug 7001! -->
+  <!--XXX HACK: The following code is still mostly copy-paste, but is much better than before fixing bug 7001! -->
 
   <target name="ask-to-copy-endorsed-stax-api-to-node1" if="endorsed-stax-api-at-node1-does-not-exist-yet">
-    <echo>IMPORTANT: Please note that your Tomcat might already contain an endorsed stax-api library at '${tomcat1.home.dir}/common/endorsed/'. Please make sure to resolve any conflicts!</echo>
-    <input message="Endorsed lib is missing (${tomcat1.home.dir}/common/endorsed/${stax-api.artifactId}-${stax-api.version}.jar). Do you want it to be added? (YES/no):" addproperty="answer"/>
-    <condition property="do-not-copy-endorsed-stax-api-to-node1">
-      <equals arg1="no" arg2="${answer}"/>
-    </condition>
-    <antcall target="do-copy-endorsed-stax-api-to-node1"/>
+    <yanel:ask-to-copy-endorsed-jar jarId="stax-api"/>
   </target>
 
-  <target name="ask-to-copy-endorsed-stax-api-node2" if="endorsed-stax-api-at-node2-does-not-exist-yet">
-    <echo>IMPORTANT: Please note that your Tomcat might already contain an endorsed stax-api library at '${tomcat2.home.dir}/common/endorsed/'. Please make sure to resolve any conflicts!</echo>
-    <input message="Endorsed lib is missing (${tomcat2.home.dir}/common/endorsed/${stax-api.artifactId}-${stax-api.version}.jar). Do you want it to be added? (YES/no):" addproperty="answer"/>
-    <condition property="do-not-copy-endorsed-stax-api-to-node2">
-      <equals arg1="no" arg2="${answer}"/>
-    </condition>
-
-    <antcall target="do-copy-endorsed-stax-api-to-node2"/>
+  <target name="ask-to-copy-endorsed-stax-api-to-node2" if="endorsed-stax-api-at-node2-does-not-exist-yet">
+    <yanel:ask-to-copy-endorsed-jar jarId="stax-api" serverNode="2"/>
   </target>
 
   <target name="ask-to-copy-endorsed-stax-impl-to-node1" if="endorsed-stax-impl-at-node1-does-not-exist-yet">
-    <echo>IMPORTANT: Please note that your Tomcat might already contain an endorsed stax-impl library at '${tomcat1.home.dir}/common/endorsed/'. Please make sure to resolve any conflicts!</echo>
-    <input message="Endorsed lib is missing (${tomcat1.home.dir}/common/endorsed/${stax-impl.artifactId}-${stax-impl.version}.jar). Do you want it to be added? (YES/no):" addproperty="answer"/>
-    <condition property="do-not-copy-endorsed-stax-impl-to-node1">
-      <equals arg1="no" arg2="${answer}"/>
-    </condition>
-    <antcall target="do-copy-endorsed-stax-impl-to-node1"/>
+    <yanel:ask-to-copy-endorsed-jar jarId="stax-impl"/>
   </target>
 
   <target name="ask-to-copy-endorsed-stax-impl-to-node2" if="endorsed-stax-impl-at-node2-does-not-exist-yet">
-    <echo>IMPORTANT: Please note that your Tomcat might already contain an endorsed stax-impl library at '${tomcat2.home.dir}/common/endorsed/'. Please make sure to resolve any conflicts!</echo>
-    <input message="Endorsed lib is missing (${tomcat2.home.dir}/common/endorsed/${stax-impl.artifactId}-${stax-impl.version}.jar). Do you want it to be added? (YES/no):" addproperty="answer"/>
-    <condition property="do-not-copy-endorsed-stax-impl-to-node2">
+    <yanel:ask-to-copy-endorsed-jar jarId="stax-impl" serverNode="2"/>
+  </target>
+
+  <macrodef name="ask-to-copy-endorsed-jar" uri="http://www.wyona.org/yanel/1.0">
+   <attribute name="jarId"/>
+   <attribute name="serverNode" default="1"/>
+   <attribute name="targetDir" default="${tomcat@{serverNode}.home.dir}/common/endorsed"/>
+   <sequential>
+    <echo>IMPORTANT: Please note that your Tomcat might already contain an endorsed @{jarId} library at '@{targetDir}/'. Please make sure to resolve any conflicts!</echo>
+    <input message="Endorsed lib is missing (@{targetDir}/${@{jarId}.artifactId}-${@{jarId}.version}.jar). Do you want it to be added? (YES/no):" addproperty="answer"/>
+    <condition property="do-not-copy-endorsed-@{jarId}-to-node@{serverNode}">
       <equals arg1="no" arg2="${answer}"/>
     </condition>
-    <antcall target="do-copy-endorsed-stax-impl-to-node2"/>
-  </target>
+    <antcall target="do-copy-endorsed-@{jarId}-to-node@{serverNode}"/>
+   </sequential>
+  </macrodef>
   
   <target name="do-copy-endorsed-stax-api-to-node1" unless="do-not-copy-endorsed-stax-api-to-node1">
-    <copy file="${yanel.source.home}/build/webapps/${servlet.context.prefix}/WEB-INF/lib/${stax-api.artifactId}-${stax-api.version}.jar" todir="${tomcat1.home.dir}/common/endorsed" overwrite="false"/>
-    <echo>INFO: ${stax-api.artifactId}-${stax-api.version}.jar has been copied!</echo>
+    <yanel:do-copy-endorsed-jar jarId="stax-api"/>
   </target>
   
   <target name="do-copy-endorsed-stax-api-to-node2" unless="do-not-copy-endorsed-stax-api-to-node2">
-    <copy file="${yanel.source.home}/build/webapps/${servlet.context.prefix}/WEB-INF/lib/${stax-api.artifactId}-${stax-api.version}.jar" todir="${tomcat2.home.dir}/common/endorsed" overwrite="false"/>
-    <echo>INFO: ${stax-api.artifactId}-${stax-api.version}.jar has been copied!</echo>
+    <yanel:do-copy-endorsed-jar jarId="stax-api" serverNode="2"/>
   </target>
   
   <target name="do-copy-endorsed-stax-impl-to-node1" unless="do-not-copy-endorsed-stax-impl-to-node1">
-    <copy file="${yanel.source.home}/build/webapps/${servlet.context.prefix}/WEB-INF/lib/${stax-impl.artifactId}-${stax-impl.version}.jar" todir="${tomcat1.home.dir}/common/endorsed" overwrite="false"/>
-    <echo>INFO: ${stax-impl.artifactId}-${stax-impl.version}.jar has been copied!</echo>
+    <yanel:do-copy-endorsed-jar jarId="stax-impl"/>
   </target>
   
   <target name="do-copy-endorsed-stax-impl-to-node2" unless="do-not-copy-endorsed-stax-impl-to-node2">
-    <copy file="${yanel.source.home}/build/webapps/${servlet.context.prefix}/WEB-INF/lib/${stax-impl.artifactId}-${stax-impl.version}.jar" todir="${tomcat2.home.dir}/common/endorsed" overwrite="false"/>
-    <echo>INFO: ${stax-impl.artifactId}-${stax-impl.version}.jar has been copied!</echo>
+    <yanel:do-copy-endorsed-jar jarId="stax-impl" serverNode="2"/>
   </target>
 
+  <macrodef name="do-copy-endorsed-jar" uri="http://www.wyona.org/yanel/1.0">
+   <attribute name="jarId"/>
+   <attribute name="serverNode" default="1"/>
+   <attribute name="targetDir" default="${tomcat@{serverNode}.home.dir}/common/endorsed"/>
+   <sequential>
+    <copy file="${yanel.source.home}/build/webapps/${servlet.context.prefix}/WEB-INF/lib/${@{jarId}.artifactId}-${@{jarId}.version}.jar" todir="@{targetDir}" overwrite="false"/>
+    <echo>INFO: ${@{jarId}.artifactId}-${@{jarId}.version}.jar has been copied!</echo>
+   </sequential>
+  </macrodef>
 
 
+
     <target name="ask-to-clean-tomcat-cluster-node1" if="property-tomcat-cluster-node1-is-set" description="Clean Tomcat cluster node 1">
     <input message="Do you really want to delete your deployed (maybe productive) Yanel version at '${tomcat1.webapps.dir}/${servlet.context.prefix}'? (yes/NO):" addproperty="answer"/>
     <condition property="yes-delete-tomcat-cluster-node1">



More information about the Yanel-commits mailing list