Fixed 15709: On update or uninstall remove orphan jarfiles from deployed webapp
authorStefan Hühner <stefan.huehner@openbravo.com>
Thu, 20 Jan 2011 12:06:03 +0100
changeset 9978 c7ebe8961ccb
parent 9977 ea713e75b0e8
child 9979 2e738c79c070
Fixed 15709: On update or uninstall remove orphan jarfiles from deployed webapp
When running with deploy.mode class not only update deployed webapp with new
files but also remove orphan jar files from it.
Note: If running from Rebuild UI (MMC) this is done between tomcat stop & start
instead of directly in the rebuild to not delete the files from under the still
running application.
build.xml
src-core/src/org/openbravo/base/BuildTask.java
src/build.xml
--- a/build.xml	Thu Jan 20 11:31:26 2011 +0100
+++ b/build.xml	Thu Jan 20 12:06:03 2011 +0100
@@ -408,6 +408,13 @@
     <copy todir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib" file="${build.core.lib}/openbravo-core.jar" encoding="UTF-8" />
   </target>
 
+  <!-- Only needed in special cases. See issue 15709 for details.
+       This task (if deploy.mode=class) does sync jar-files from WebContent -> deployed webapp (& delete orphan jars)
+  -->
+  <target name="copy.files.jarsync" depends="init" if="mode.class">
+    <ant dir="${base.src}" target="copy.files.jarsync.do" inheritAll="true" inheritRefs="true" />
+  </target>
+
   <target name="build.deploy.war" if="mode.war">
     <antcall target="war" />
   </target>
@@ -828,7 +835,11 @@
       <arg line="stop" />
     </java>
     <sleep description="Wait to give tomcat time to stop" seconds="20" />
-    <java classname="org.apache.catalina.startup.Bootstrap" failonerror="true" fork="true">
+
+    <!-- if deploy.mode=class this will sync (& delete orphan) jarfiles from WebContent -> tomcat-->
+    <antcall target="copy.files.jarsync"/>
+
+    <java classname="org.apache.catalina.startup.Bootstrap" fork="true" spawn="true">
       <classpath path=":${env.CATALINA_HOME}/bin/bootstrap.jar:${env.CATALINA_HOME}/bin/commons-logging-api.jar" />
       <!-- note because CATALINA_OPTS can be multi argument the line attribute has to be used! -->
       <jvmarg line="${env.CATALINA_OPTS}" />
--- a/src-core/src/org/openbravo/base/BuildTask.java	Thu Jan 20 11:31:26 2011 +0100
+++ b/src-core/src/org/openbravo/base/BuildTask.java	Thu Jan 20 12:06:03 2011 +0100
@@ -69,6 +69,9 @@
     // We will show special, friendly warnings when they are available
     ant.setProperty("friendlyWarnings", "true");
 
+    // Set a property so build tasks know they have been called via the Rebuild UI from the MMC
+    ant.setProperty("runningInRebuildUI", "true");
+
     final Vector<String> tasks = new Vector<String>();
     final String unnappliedModules = getUnnapliedModules();
     tasks.add("update.database");
--- a/src/build.xml	Thu Jan 20 11:31:26 2011 +0100
+++ b/src/build.xml	Thu Jan 20 12:06:03 2011 +0100
@@ -847,7 +847,12 @@
     </java>
   </target>
 
-  <target name="copy.files" if="mode.class">
+  <!-- Note (see issue 15709 for details):
+       orphan jarfiles are not deleted from the webapp as deployed in tomcat when
+       this rebuild is running inside the rebuild UI (started from MMC). See also the related
+       copy.files.jarsync(.do) task which does this deletion between tomcat stop & start
+   -->
+  <target name="copy.files" depends="copy.files.jarsync.notinrebuildui" if="mode.class">
     <mkdir dir="${jakarta.base}/webapps/${context.name}" />
     <sync todir="${jakarta.base}/webapps/${context.name}">
       <preserveintarget>
@@ -865,6 +870,19 @@
     </copy>
   </target>
 
+  <target name="copy.files.jarsync.notinrebuildui" unless="runningInRebuildUI">
+    <antcall target="copy.files.jarsync.do"/>
+  </target>
+
+  <!-- sync jar files from WebContent -> deployed webapp & delete orphan jars from webapp
+       as delete orphan is excluded from normal copy.files task -->
+  <target name="copy.files.jarsync.do" if="mode.class">
+    <mkdir dir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib"/>
+    <sync todir="${jakarta.base}/webapps/${context.name}/WEB-INF/lib">
+      <fileset dir="${base.context}/WEB-INF/lib" />
+    </sync>
+  </target>
+
   <target name="compile.development" depends="generate.entities, compile, copy.files">
   </target>