From 5b9a8a459c9bf5c09aa0218cf5e29ad0963250af Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 3 Jun 2011 22:22:35 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51251 Add web application version support to the Ant tasks. Based on a patch provided by Eiji Takahashi. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1131267 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalina/ant/AbstractCatalinaCommandTask.java | 84 ++++++++++++++++++++++ java/org/apache/catalina/ant/ReloadTask.java | 37 +--------- java/org/apache/catalina/ant/SessionsTask.java | 49 ++++++------- java/org/apache/catalina/ant/StartTask.java | 37 +--------- java/org/apache/catalina/ant/StopTask.java | 39 +--------- java/org/apache/catalina/ant/UndeployTask.java | 37 +--------- webapps/docs/changelog.xml | 4 ++ 7 files changed, 117 insertions(+), 170 deletions(-) create mode 100644 java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java diff --git a/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java b/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java new file mode 100644 index 000000000..2cc4e5be4 --- /dev/null +++ b/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.ant; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +import org.apache.tools.ant.BuildException; + +public abstract class AbstractCatalinaCommandTask extends + AbstractCatalinaTask { + + /** + * The context path of the web application we are managing. + */ + protected String path = null; + + public String getPath() { + return (this.path); + } + + public void setPath(String path) { + this.path = path; + } + + /** + * The context version of the web application we are managing. + */ + protected String version = null; + + public String getVersion() { + return (this.version); + } + + public void setVersion(String version) { + this.version = version; + } + + // --------------------------------------------------------- Public Methods + + /** + * Create query string for the specified command. + * + * @param command Command to be executed + * + * @exception BuildException if an error occurs + */ + public StringBuilder createQueryString(String command) throws BuildException { + StringBuilder buffer = new StringBuilder(); + + try { + buffer.append(command); + if (path == null) { + throw new BuildException("Must specify 'path' attribute"); + } else { + buffer.append("?path="); + buffer.append(URLEncoder.encode(this.path, getCharset())); + if (this.version != null) { + buffer.append("&version="); + buffer.append(URLEncoder.encode(this.version, getCharset())); + } + } + } catch (UnsupportedEncodingException e) { + throw new BuildException + ("Invalid 'charset' attribute: " + getCharset()); + } + return buffer; + } + +} \ No newline at end of file diff --git a/java/org/apache/catalina/ant/ReloadTask.java b/java/org/apache/catalina/ant/ReloadTask.java index 275f4b439..316a858f5 100644 --- a/java/org/apache/catalina/ant/ReloadTask.java +++ b/java/org/apache/catalina/ant/ReloadTask.java @@ -19,8 +19,6 @@ package org.apache.catalina.ant; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import org.apache.tools.ant.BuildException; @@ -33,28 +31,7 @@ import org.apache.tools.ant.BuildException; * @version $Id$ * @since 4.1 */ -public class ReloadTask extends AbstractCatalinaTask { - - - // ------------------------------------------------------------- Properties - - - /** - * The context path of the web application we are managing. - */ - protected String path = null; - - public String getPath() { - return (this.path); - } - - public void setPath(String path) { - this.path = path; - } - - - // --------------------------------------------------------- Public Methods - +public class ReloadTask extends AbstractCatalinaCommandTask { /** * Execute the requested operation. @@ -65,17 +42,7 @@ public class ReloadTask extends AbstractCatalinaTask { public void execute() throws BuildException { super.execute(); - if (path == null) { - throw new BuildException - ("Must specify 'path' attribute"); - } - try { - execute("/reload?path=" + URLEncoder.encode(this.path, getCharset())); - } catch (UnsupportedEncodingException e) { - throw new BuildException - ("Invalid 'charset' attribute: " + getCharset()); - } - + execute(createQueryString("/reload").toString()); } diff --git a/java/org/apache/catalina/ant/SessionsTask.java b/java/org/apache/catalina/ant/SessionsTask.java index b0d88d185..0aed7ad77 100644 --- a/java/org/apache/catalina/ant/SessionsTask.java +++ b/java/org/apache/catalina/ant/SessionsTask.java @@ -19,9 +19,6 @@ package org.apache.catalina.ant; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - import org.apache.tools.ant.BuildException; @@ -32,25 +29,29 @@ import org.apache.tools.ant.BuildException; * @author Vivek Chopra * @version $Revision$ */ -public class SessionsTask extends AbstractCatalinaTask { - - // Properties +public class SessionsTask extends AbstractCatalinaCommandTask { - /** - * The context path of the web application we are managing. - */ - protected String path = null; - public String getPath() { - return (this.path); + protected String idle = null; + + public String getIdle() { + return this.idle; } - - public void setPath(String path) { - this.path = path; + + public void setIdle(String idle) { + this.idle = idle; } - - // Public Methods - + + @Override + public StringBuilder createQueryString(String command) { + StringBuilder buffer = super.createQueryString(command); + if (path != null && idle != null) { + buffer.append("&idle="); + buffer.append(this.idle); + } + return buffer; + } + /** * Execute the requested operation. * @@ -60,17 +61,7 @@ public class SessionsTask extends AbstractCatalinaTask { public void execute() throws BuildException { super.execute(); - if (path == null) { - throw new BuildException - ("Must specify 'path' attribute"); - } - - try { - execute("/sessions?path=" + URLEncoder.encode(this.path, getCharset())); - } catch (UnsupportedEncodingException e) { - throw new BuildException - ("Invalid 'charset' attribute: " + getCharset()); - } + execute(createQueryString("/sessions").toString()); } diff --git a/java/org/apache/catalina/ant/StartTask.java b/java/org/apache/catalina/ant/StartTask.java index 51f2d719f..a229a0517 100644 --- a/java/org/apache/catalina/ant/StartTask.java +++ b/java/org/apache/catalina/ant/StartTask.java @@ -19,9 +19,6 @@ package org.apache.catalina.ant; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - import org.apache.tools.ant.BuildException; @@ -33,28 +30,7 @@ import org.apache.tools.ant.BuildException; * @version $Id$ * @since 4.1 */ -public class StartTask extends AbstractCatalinaTask { - - - // ------------------------------------------------------------- Properties - - - /** - * The context path of the web application we are managing. - */ - protected String path = null; - - public String getPath() { - return (this.path); - } - - public void setPath(String path) { - this.path = path; - } - - - // --------------------------------------------------------- Public Methods - +public class StartTask extends AbstractCatalinaCommandTask { /** * Execute the requested operation. @@ -65,16 +41,7 @@ public class StartTask extends AbstractCatalinaTask { public void execute() throws BuildException { super.execute(); - if (path == null) { - throw new BuildException - ("Must specify 'path' attribute"); - } - try { - execute("/start?path=" + URLEncoder.encode(this.path, getCharset())); - } catch (UnsupportedEncodingException e) { - throw new BuildException - ("Invalid 'charset' attribute: " + getCharset()); - } + execute(createQueryString("/start").toString()); } diff --git a/java/org/apache/catalina/ant/StopTask.java b/java/org/apache/catalina/ant/StopTask.java index 4ceed3742..36b843098 100644 --- a/java/org/apache/catalina/ant/StopTask.java +++ b/java/org/apache/catalina/ant/StopTask.java @@ -19,9 +19,6 @@ package org.apache.catalina.ant; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - import org.apache.tools.ant.BuildException; @@ -33,28 +30,7 @@ import org.apache.tools.ant.BuildException; * @version $Id$ * @since 4.1 */ -public class StopTask extends AbstractCatalinaTask { - - - // ------------------------------------------------------------- Properties - - - /** - * The context path of the web application we are managing. - */ - protected String path = null; - - public String getPath() { - return (this.path); - } - - public void setPath(String path) { - this.path = path; - } - - - // --------------------------------------------------------- Public Methods - +public class StopTask extends AbstractCatalinaCommandTask { /** * Execute the requested operation. @@ -65,18 +41,9 @@ public class StopTask extends AbstractCatalinaTask { public void execute() throws BuildException { super.execute(); - if (path == null) { - throw new BuildException - ("Must specify 'path' attribute"); - } - try { - execute("/stop?path=" + URLEncoder.encode(this.path, getCharset())); - } catch (UnsupportedEncodingException e) { - throw new BuildException - ("Invalid 'charset' attribute: " + getCharset()); - } + execute(createQueryString("/stop").toString()); } - + } diff --git a/java/org/apache/catalina/ant/UndeployTask.java b/java/org/apache/catalina/ant/UndeployTask.java index 7564a7fbb..8773c061d 100644 --- a/java/org/apache/catalina/ant/UndeployTask.java +++ b/java/org/apache/catalina/ant/UndeployTask.java @@ -19,9 +19,6 @@ package org.apache.catalina.ant; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - import org.apache.tools.ant.BuildException; @@ -33,27 +30,7 @@ import org.apache.tools.ant.BuildException; * @version $Id$ * @since 4.1 */ -public class UndeployTask extends AbstractCatalinaTask { - - - // ------------------------------------------------------------- Properties - - /** - * The context path of the web application we are managing. - */ - protected String path = null; - - public String getPath() { - return (this.path); - } - - public void setPath(String path) { - this.path = path; - } - - - // --------------------------------------------------------- Public Methods - +public class UndeployTask extends AbstractCatalinaCommandTask { /** * Execute the requested operation. @@ -64,18 +41,8 @@ public class UndeployTask extends AbstractCatalinaTask { public void execute() throws BuildException { super.execute(); - if (path == null) { - throw new BuildException - ("Must specify 'path' attribute"); - } + execute(createQueryString("/undeploy").toString()); - try { - execute("/undeploy?path=" + - URLEncoder.encode(this.path, getCharset())); - } catch (UnsupportedEncodingException e) { - throw new BuildException - ("Invalid 'charset' attribute: " + getCharset()); - } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 31e39e2fc..7b2f9e6ae 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -147,6 +147,10 @@ Patch provided by Eiji Takahashi. (markt) + 51251: Add web application version support to the Ant tasks. + Based on a patch provided by Eiji Takahashi. (markt) + + 51294: Clarify behaviour of unpackWAR attribute of StandardContext components. (markt) -- 2.11.0