You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2017/04/20 19:26:45 UTC
svn commit: r1792134 - in /tomcat/trunk/java/org/apache/catalina/ant:
AbstractCatalinaCommandTask.java AbstractCatalinaTask.java
BaseRedirectorHelperTask.java DeployTask.java FindLeaksTask.java
Author: markt
Date: Thu Apr 20 19:26:44 2017
New Revision: 1792134
URL: http://svn.apache.org/viewvc?rev=1792134&view=rev
Log:
Align with 8.5.x
Modified:
tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java
tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaTask.java
tomcat/trunk/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java
tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java
tomcat/trunk/java/org/apache/catalina/ant/FindLeaksTask.java
Modified: tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java?rev=1792134&r1=1792133&r2=1792134&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaCommandTask.java Thu Apr 20 19:26:44 2017
@@ -29,7 +29,7 @@ public abstract class AbstractCatalinaCo
protected String path = null;
public String getPath() {
- return (this.path);
+ return this.path;
}
public void setPath(String path) {
@@ -42,13 +42,14 @@ public abstract class AbstractCatalinaCo
protected String version = null;
public String getVersion() {
- return (this.version);
+ return this.version;
}
public void setVersion(String version) {
this.version = version;
}
+
// --------------------------------------------------------- Public Methods
/**
@@ -76,10 +77,8 @@ public abstract class AbstractCatalinaCo
}
}
} catch (UnsupportedEncodingException e) {
- throw new BuildException
- ("Invalid 'charset' attribute: " + getCharset());
+ throw new BuildException("Invalid 'charset' attribute: " + getCharset());
}
return buffer;
}
-
}
\ No newline at end of file
Modified: tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaTask.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaTask.java?rev=1792134&r1=1792133&r2=1792134&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/AbstractCatalinaTask.java Thu Apr 20 19:26:44 2017
@@ -30,9 +30,9 @@ import org.apache.tools.ant.BuildExcepti
import org.apache.tools.ant.Project;
/**
- * Abstract base class for Ant tasks that interact with the
- * <em>Manager</em> web application for dynamically deploying and
- * undeploying applications. These tasks require Ant 1.4 or later.
+ * Abstract base class for Ant tasks that interact with the <em>Manager</em> web
+ * application for dynamically deploying and undeploying applications. These
+ * tasks require Ant 1.4 or later.
*
* @author Craig R. McClanahan
* @since 4.1
@@ -69,7 +69,7 @@ public abstract class AbstractCatalinaTa
protected String password = null;
public String getPassword() {
- return (this.password);
+ return this.password;
}
public void setPassword(String password) {
@@ -83,7 +83,7 @@ public abstract class AbstractCatalinaTa
protected String url = "http://localhost:8080/manager/text";
public String getUrl() {
- return (this.url);
+ return this.url;
}
public void setUrl(String url) {
@@ -97,7 +97,7 @@ public abstract class AbstractCatalinaTa
protected String username = null;
public String getUsername() {
- return (this.username);
+ return this.username;
}
public void setUsername(String username) {
@@ -109,9 +109,9 @@ public abstract class AbstractCatalinaTa
* message that must be "OK -".
* <p>
* When this attribute is set to {@code false} (the default), the first line
- * of server response is expected to start with "OK -". If it does not
- * then the task is considered as failed and the first line is treated
- * as an error message.
+ * of server response is expected to start with "OK -". If it does not then
+ * the task is considered as failed and the first line is treated as an
+ * error message.
* <p>
* When this attribute is set to {@code true}, the first line of the
* response is treated like any other, regardless of its text.
@@ -129,28 +129,21 @@ public abstract class AbstractCatalinaTa
// --------------------------------------------------------- Public Methods
-
/**
- * Execute the specified command. This logic only performs the common
- * attribute validation required by all subclasses; it does not perform
- * any functional logic directly.
+ * Execute the specified command. This logic only performs the common
+ * attribute validation required by all subclasses; it does not perform any
+ * functional logic directly.
*
* @exception BuildException if a validation error occurs
*/
@Override
public void execute() throws BuildException {
-
if ((username == null) || (password == null) || (url == null)) {
- throw new BuildException
- ("Must specify all of 'username', 'password', and 'url'");
+ throw new BuildException("Must specify all of 'username', 'password', and 'url'");
}
-
}
- // ------------------------------------------------------ Protected Methods
-
-
/**
* Execute the specified command, based on the configured properties.
*
@@ -159,16 +152,14 @@ public abstract class AbstractCatalinaTa
* @exception BuildException if an error occurs
*/
public void execute(String command) throws BuildException {
-
execute(command, null, null, -1);
-
}
/**
- * Execute the specified command, based on the configured properties.
- * The input stream will be closed upon completion of this task, whether
- * it was executed successfully or not.
+ * Execute the specified command, based on the configured properties. The
+ * input stream will be closed upon completion of this task, whether it was
+ * executed successfully or not.
*
* @param command Command to be executed
* @param istream InputStream to include in an HTTP PUT, if any
@@ -177,9 +168,8 @@ public abstract class AbstractCatalinaTa
*
* @exception BuildException if an error occurs
*/
- public void execute(String command, InputStream istream,
- String contentType, long contentLength)
- throws BuildException {
+ public void execute(String command, InputStream istream, String contentType, long contentLength)
+ throws BuildException {
URLConnection conn = null;
InputStreamReader reader = null;
@@ -200,8 +190,7 @@ public abstract class AbstractCatalinaTa
hconn.setRequestProperty("Content-Type", contentType);
}
if (contentLength >= 0) {
- hconn.setRequestProperty("Content-Length",
- "" + contentLength);
+ hconn.setRequestProperty("Content-Length", "" + contentLength);
hconn.setFixedLengthStreamingMode(contentLength);
}
@@ -209,23 +198,20 @@ public abstract class AbstractCatalinaTa
hconn.setDoOutput(false);
hconn.setRequestMethod("GET");
}
- hconn.setRequestProperty("User-Agent",
- "Catalina-Ant-Task/1.0");
+ hconn.setRequestProperty("User-Agent", "Catalina-Ant-Task/1.0");
// Set up an authorization header with our credentials
String input = username + ":" + password;
- String output = Base64.encodeBase64String(
- input.getBytes(StandardCharsets.ISO_8859_1));
- hconn.setRequestProperty("Authorization",
- "Basic " + output);
+ String output = Base64.encodeBase64String(input.getBytes(StandardCharsets.ISO_8859_1));
+ hconn.setRequestProperty("Authorization", "Basic " + output);
// Establish the connection with the server
hconn.connect();
// Send the request data (if any)
if (istream != null) {
- try (BufferedOutputStream ostream =
- new BufferedOutputStream(hconn.getOutputStream(), 1024);) {
+ try (BufferedOutputStream ostream = new BufferedOutputStream(
+ hconn.getOutputStream(), 1024);) {
byte buffer[] = new byte[1024];
while (true) {
int n = istream.read(buffer);
Modified: tomcat/trunk/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java?rev=1792134&r1=1792133&r2=1792134&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/BaseRedirectorHelperTask.java Thu Apr 20 19:26:44 2017
@@ -14,11 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina.ant;
-
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
@@ -30,17 +27,15 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Redirector;
import org.apache.tools.ant.types.RedirectorElement;
-
/**
- * Abstract base class to add output redirection support for Catalina
- * Ant tasks. These tasks require Ant 1.5 or later.
- * <br>
- * <strong>WARNING:</strong> due to depends chain, Ant could call a Task
- * more than once and this can affect the output redirection when configured.
- * If you are collecting the output in a property, it will collect the output
- * of only the first run, since Ant properties are immutable and once created
- * they cannot be changed.
+ * Abstract base class to add output redirection support for Catalina Ant tasks.
+ * These tasks require Ant 1.5 or later.
* <br>
+ * <strong>WARNING:</strong> due to depends chain, Ant could call a Task more
+ * than once and this can affect the output redirection when configured. If you
+ * are collecting the output in a property, it will collect the output of only
+ * the first run, since Ant properties are immutable and once created they
+ * cannot be changed. <br>
* If you are collecting output in a file the file will be overwritten with the
* output of the last run, unless you set append="true", in which case each run
* will append it's output to the file.
@@ -51,57 +46,56 @@ import org.apache.tools.ant.types.Redire
*/
public abstract class BaseRedirectorHelperTask extends Task {
- // ------------------------------------------------------------- Properties
-
/** Redirector helper */
protected final Redirector redirector = new Redirector(this);
- //protected Redirector redirector = null;
+
/** Redirector element for this task */
protected RedirectorElement redirectorElement = null;
+
/** The stream for info output */
protected OutputStream redirectOutStream = null;
+
/** The stream for error output */
protected OutputStream redirectErrStream = null;
+
/** The print stream for info output */
PrintStream redirectOutPrintStream = null;
+
/** The print stream for error output */
PrintStream redirectErrPrintStream = null;
- /**
- * Whether to fail (with a BuildException) if
- * ManagerServlet returns an error. The default behavior is
- * to do so.
- * <b>
- * This flag does not control parameters checking. If the task is called
- * with wrong or invalid parameters, it will throw BuildException
- * independently from the setting of this flag.
- * </b>
+ /**
+ * Whether to fail (with a BuildException) if ManagerServlet returns an
+ * error. The default behavior is to do so. <b> This flag does not control
+ * parameters checking. If the task is called with wrong or invalid
+ * parameters, it will throw BuildException independently from the setting
+ * of this flag. </b>
*/
protected boolean failOnError = true;
/**
- * <code>true</code> true when output redirection is requested for this task .
- * Default is to log on Ant log.
- */
+ * <code>true</code> true when output redirection is requested for this task.
+ * Default is to log on Ant log.
+ */
protected boolean redirectOutput = false;
/**
- * will be set to <code>true</code> when the configuration of the Redirector is
- * complete.
- */
+ * will be set to <code>true</code> when the configuration of the Redirector
+ * is complete.
+ */
protected boolean redirectorConfigured = false;
/**
- * Flag which indicates that, if redirected, output should also be
- * always sent to the log. Default is that output is sent only to
- * redirected streams.
+ * Flag which indicates that, if redirected, output should also be always
+ * sent to the log. Default is that output is sent only to redirected
+ * streams.
*/
protected boolean alwaysLog = false;
+
/**
- * Whether to fail (with a BuildException) if
- * ManagerServlet returns an error. The default behavior is
- * to do so.
+ * Whether to fail (with a BuildException) if ManagerServlet returns an
+ * error. The default behavior is to do so.
*
* @param fail The new value of failonerror
*/
@@ -109,6 +103,7 @@ public abstract class BaseRedirectorHelp
failOnError = fail;
}
+
/**
* Returns the value of the failOnError property.
*
@@ -116,7 +111,7 @@ public abstract class BaseRedirectorHelp
* otherwise <code>false</code>
*/
public boolean isFailOnError() {
- return failOnError;
+ return failOnError;
}
@@ -130,6 +125,7 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
* File the error output of the task is redirected to.
*
@@ -141,22 +137,22 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
- * Controls whether error output is logged. This is only useful
- * when output is being redirected and error output is desired in the
- * Ant log
+ * Controls whether error output is logged. This is only useful when output
+ * is being redirected and error output is desired in the Ant log
*
* @param logError if true the standard error is sent to the Ant log system
- * and not sent to output stream.
+ * and not sent to output stream.
*/
public void setLogError(boolean logError) {
redirector.setLogError(logError);
redirectOutput = true;
}
+
/**
- * Property name whose value should be set to the output of
- * the task.
+ * Property name whose value should be set to the output of the task.
*
* @param outputProperty property name
*
@@ -166,9 +162,9 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
- * Property name whose value should be set to the error of
- * the task..
+ * Property name whose value should be set to the error of the task.
*
* @param errorProperty property name
*
@@ -178,6 +174,7 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
* If true, append output to existing file.
*
@@ -189,24 +186,27 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
- * If true, (error and non-error) output will be redirected
- * as specified while being sent to Ant's logging mechanism as if no
- * redirection had taken place. Defaults to false.
+ * If true, (error and non-error) output will be redirected as specified
+ * while being sent to Ant's logging mechanism as if no redirection had
+ * taken place. Defaults to false.
* <br>
- * Actually handled internally, with Ant 1.6.3 it will be handled by
- * the <code>Redirector</code> itself.
+ * Actually handled internally, with Ant 1.6.3 it will be handled by the
+ * <code>Redirector</code> itself.
+ *
* @param alwaysLog <code>boolean</code>
*/
public void setAlwaysLog(boolean alwaysLog) {
this.alwaysLog = alwaysLog;
- //redirector.setAlwaysLog(alwaysLog);
redirectOutput = true;
}
+
/**
* Whether output and error files should be created even when empty.
* Defaults to true.
+ *
* @param createEmptyFiles <CODE>boolean</CODE>.
*/
public void setCreateEmptyFiles(boolean createEmptyFiles) {
@@ -214,9 +214,11 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
+
/**
* Add a <CODE>RedirectorElement</CODE> to this task.
- * @param redirectorElement <CODE>RedirectorElement</CODE>.
+ *
+ * @param redirectorElement <CODE>RedirectorElement</CODE>.
*/
public void addConfiguredRedirector(RedirectorElement redirectorElement) {
if (this.redirectorElement != null) {
@@ -226,6 +228,7 @@ public abstract class BaseRedirectorHelp
}
}
+
/**
* Set up properties on the Redirector from RedirectorElement if present.
*/
@@ -235,18 +238,19 @@ public abstract class BaseRedirectorHelp
redirectOutput = true;
}
/*
- * Due to depends chain, Ant could call the Task more than once,
- * this is to prevent that we attempt to configure uselessly
- * more than once the Redirector.
+ * Due to depends chain, Ant could call the Task more than once, this is
+ * to prevent that we attempt to configure uselessly more than once the
+ * Redirector.
*/
redirectorConfigured = true;
}
+
/**
* Set up properties on the Redirector and create output streams.
*/
protected void openRedirector() {
- if (! redirectorConfigured) {
+ if (!redirectorConfigured) {
configureRedirector();
}
if (redirectOutput) {
@@ -256,13 +260,14 @@ public abstract class BaseRedirectorHelp
redirectErrStream = redirector.getErrorStream();
redirectErrPrintStream = new PrintStream(redirectErrStream);
}
- }
+ }
+
/**
- * Ask redirector to close all the streams. It is necessary to call this method
- * before leaving the Task to have the Streams flush their contents. If you are
- * collecting output in a property, it will be created only if this method is
- * called, otherwise you'll find it unset.
+ * Ask redirector to close all the streams. It is necessary to call this
+ * method before leaving the Task to have the Streams flush their contents.
+ * If you are collecting output in a property, it will be created only if
+ * this method is called, otherwise you'll find it unset.
*/
protected void closeRedirector() {
try {
@@ -270,13 +275,11 @@ public abstract class BaseRedirectorHelp
redirector.complete();
}
} catch (IOException ioe) {
- log("Error closing redirector: "
- + ioe.getMessage(), Project.MSG_ERR);
+ log("Error closing redirector: " + ioe.getMessage(), Project.MSG_ERR);
}
/*
- * Due to depends chain, Ant could call the Task more than once,
- * this is to prevent that we attempt to reuse the previously
- * closed Streams.
+ * Due to depends chain, Ant could call the Task more than once, this is
+ * to prevent that we attempt to reuse the previously closed Streams.
*/
redirectOutStream = null;
redirectOutPrintStream = null;
@@ -284,6 +287,7 @@ public abstract class BaseRedirectorHelp
redirectErrPrintStream = null;
}
+
/**
* Handles output with the INFO priority.
*
@@ -304,6 +308,7 @@ public abstract class BaseRedirectorHelp
}
}
+
/**
* Handles output with the INFO priority and flushes the stream.
*
@@ -316,6 +321,7 @@ public abstract class BaseRedirectorHelp
redirectOutPrintStream.flush();
}
+
/**
* Handles error output with the ERR priority.
*
@@ -336,6 +342,7 @@ public abstract class BaseRedirectorHelp
}
}
+
/**
* Handles error output with the ERR priority and flushes the stream.
*
@@ -348,9 +355,10 @@ public abstract class BaseRedirectorHelp
redirectErrPrintStream.flush();
}
+
/**
- * Handles output with ERR priority to error stream and all other
- * priorities to output stream.
+ * Handles output with ERR priority to error stream and all other priorities
+ * to output stream.
*
* @param output The output to log. Should not be <code>null</code>.
* @param priority The priority level that should be used
Modified: tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java?rev=1792134&r1=1792133&r2=1792134&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java Thu Apr 20 19:26:44 2017
@@ -14,11 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina.ant;
-
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
@@ -30,20 +27,16 @@ import java.util.regex.Pattern;
import org.apache.tools.ant.BuildException;
-
/**
- * Ant task that implements the <code>/deploy</code> command, supported by
- * the Tomcat manager application.
+ * Ant task that implements the <code>/deploy</code> command, supported by the
+ * Tomcat manager application.
*
* @author Craig R. McClanahan
* @since 4.1
*/
public class DeployTask extends AbstractCatalinaCommandTask {
- private static final Pattern PROTOCOL_PATTERN = Pattern.compile("\\w{3,5}\\:");
-
-
- // ------------------------------------------------------------- Properties
+ private static final Pattern PROTOCOL_PATTERN = Pattern.compile("\\w{3,5}\\:");
/**
* URL of the context configuration file for this application, if any.
@@ -51,7 +44,7 @@ public class DeployTask extends Abstract
protected String config = null;
public String getConfig() {
- return (this.config);
+ return this.config;
}
public void setConfig(String config) {
@@ -60,13 +53,13 @@ public class DeployTask extends Abstract
/**
- * URL of the server local web application archive (WAR) file
- * to be deployed.
+ * URL of the server local web application archive (WAR) file to be
+ * deployed.
*/
protected String localWar = null;
public String getLocalWar() {
- return (this.localWar);
+ return this.localWar;
}
public void setLocalWar(String localWar) {
@@ -80,7 +73,7 @@ public class DeployTask extends Abstract
protected String tag = null;
public String getTag() {
- return (this.tag);
+ return this.tag;
}
public void setTag(String tag) {
@@ -94,7 +87,7 @@ public class DeployTask extends Abstract
protected boolean update = false;
public boolean getUpdate() {
- return (this.update);
+ return this.update;
}
public void setUpdate(boolean update) {
@@ -108,7 +101,7 @@ public class DeployTask extends Abstract
protected String war = null;
public String getWar() {
- return (this.war);
+ return this.war;
}
public void setWar(String war) {
@@ -116,9 +109,6 @@ public class DeployTask extends Abstract
}
- // --------------------------------------------------------- Public Methods
-
-
/**
* Execute the requested operation.
*
@@ -126,17 +116,14 @@ public class DeployTask extends Abstract
*/
@Override
public void execute() throws BuildException {
-
super.execute();
if (path == null) {
- throw new BuildException
- ("Must specify 'path' attribute");
+ throw new BuildException("Must specify 'path' attribute");
}
if ((war == null) && (localWar == null) && (config == null) && (tag == null)) {
- throw new BuildException
- ("Must specify either 'war', 'localWar', 'config', or 'tag' attribute");
+ throw new BuildException(
+ "Must specify either 'war', 'localWar', 'config', or 'tag' attribute");
}
-
// Building an input stream on the WAR to upload, if any
BufferedInputStream stream = null;
String contentType = null;
@@ -147,8 +134,7 @@ public class DeployTask extends Abstract
URL url = new URL(war);
URLConnection conn = url.openConnection();
contentLength = conn.getContentLengthLong();
- stream = new BufferedInputStream
- (conn.getInputStream(), 1024);
+ stream = new BufferedInputStream(conn.getInputStream(), 1024);
} catch (IOException e) {
throw new BuildException(e);
}
@@ -171,7 +157,6 @@ public class DeployTask extends Abstract
}
contentType = "application/octet-stream";
}
-
// Building URL
StringBuilder sb = createQueryString("/deploy");
try {
@@ -190,7 +175,6 @@ public class DeployTask extends Abstract
sb.append("&tag=");
sb.append(URLEncoder.encode(tag, getCharset()));
}
-
execute(sb.toString(), stream, contentType, contentLength);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Invalid 'charset' attribute: " + getCharset());
@@ -203,8 +187,5 @@ public class DeployTask extends Abstract
}
}
}
-
}
-
-
}
Modified: tomcat/trunk/java/org/apache/catalina/ant/FindLeaksTask.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/FindLeaksTask.java?rev=1792134&r1=1792133&r2=1792134&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/FindLeaksTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/FindLeaksTask.java Thu Apr 20 19:26:44 2017
@@ -47,6 +47,7 @@ public class FindLeaksTask extends Abstr
return statusLine;
}
+
/**
* Execute the requested operation.
*
@@ -54,9 +55,7 @@ public class FindLeaksTask extends Abstr
*/
@Override
public void execute() throws BuildException {
-
super.execute();
execute("/findleaks?statusLine=" + Boolean.toString(statusLine));
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org