From 8d779414b7aee6b221916e31c2624ecddb22c859 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Thu, 10 Feb 2005 22:32:21 +0000 Subject: [PATCH] Added loginputstring attribute to redirector. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277628 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 ++ docs/manual/CoreTypes/redirector.html | 15 +++++++++---- src/etc/testcases/types/redirector.xml | 17 ++++++++++++++ .../apache/tools/ant/taskdefs/Redirector.java | 22 +++++++++++++++++-- .../tools/ant/types/RedirectorElement.java | 20 ++++++++++++++++- .../ant/types/RedirectorElementTest.java | 9 ++++++-- 6 files changed, 76 insertions(+), 9 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 94b43d0d5..4dacbc190 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -108,6 +108,8 @@ Other changes: * zip/jar/war/ear supports level attribute for deflate compression level. Bugzilla report 25513. +* Added loginputstring attribute to the redirector type. + Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/docs/manual/CoreTypes/redirector.html b/docs/manual/CoreTypes/redirector.html index 65a1161f4..8fb405300 100644 --- a/docs/manual/CoreTypes/redirector.html +++ b/docs/manual/CoreTypes/redirector.html @@ -107,10 +107,17 @@ source (input) and destination (output/error) files. Since Ant 1.6.2 alwayslog Always send to the log in addition to - any other destination. Default false. - Since Ant 1.6.3. + any other destination. Since Ant 1.6.3. - No + No, default is false + + + loginputstring + Controls the display of inputstring's value in + log messages. Set to false when sending sensitive data + (e.g. passwords) to external processes. Since Ant 1.6.3. + + No, default is true

Parameters specified as nested elements

@@ -153,7 +160,7 @@ Tasks known to support I/O redirection: dependent on the supporting task. Any possible points of confusion should be noted at the task level.


-

Copyright © 2004 The Apache Software Foundation. All rights +

Copyright © 2004-2005 The Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/types/redirector.xml b/src/etc/testcases/types/redirector.xml index dc44912ab..037ef5fa9 100755 --- a/src/etc/testcases/types/redirector.xml +++ b/src/etc/testcases/types/redirector.xml @@ -21,4 +21,21 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Redirector.java b/src/main/org/apache/tools/ant/taskdefs/Redirector.java index 54b234ee7..53c8f8391 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Redirector.java +++ b/src/main/org/apache/tools/ant/taskdefs/Redirector.java @@ -167,6 +167,9 @@ public class Redirector { /** The thread group used for starting StreamPumper threads */ private ThreadGroup threadGroup = new ThreadGroup("redirector"); + /** whether to log the inputstring */ + private boolean logInputString = true; + /** * Create a redirector instance for the given task * @@ -214,6 +217,16 @@ public class Redirector { this.inputString = inputString; } + /** + * Set whether to include the value of the input string in log messages. + * Defaults to true. + * @param logInputString true or false. + * @since Ant 1.7 + */ + public void setLogInputString(boolean logInputString) { + this.logInputString = logInputString; + } + /** * Set a stream to use as input. * @@ -577,8 +590,13 @@ public class Redirector { } ((ConcatFileInputStream) inputStream).setManagingComponent(managingTask); } else if (inputString != null) { - managingTask.log("Using input \"" + inputString + "\"", - Project.MSG_VERBOSE); + StringBuffer buf = new StringBuffer("Using input "); + if (logInputString) { + buf.append('"').append(inputString).append('"'); + } else { + buf.append("string"); + } + managingTask.log(buf.toString(), Project.MSG_VERBOSE); inputStream = new ByteArrayInputStream(inputString.getBytes()); } diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index 1230bf5c8..1968e7eda 100755 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation. + * Copyright 2004-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -98,6 +98,9 @@ public class RedirectorElement extends DataType { /** The input encoding */ private String inputEncoding; + /** whether to log the inputstring */ + private Boolean logInputString; + /** * Add the input file mapper. * @param inputMapper Mapper. @@ -210,6 +213,18 @@ public class RedirectorElement extends DataType { this.inputString = inputString; } + /** + * Set whether to include the value of the input string in log messages. + * Defaults to true. + * @param logInputString true or false. + * @since Ant 1.7 + */ + public void setLogInputString(boolean logInputString) { + if (isReference()) { + throw tooManyAttributes(); + } + this.logInputString = logInputString ? Boolean.TRUE : Boolean.FALSE; + } /** * File the output of the process is redirected to. If error is not @@ -439,6 +454,9 @@ public class RedirectorElement extends DataType { if (inputString != null) { redirector.setInputString(inputString); } + if (logInputString != null) { + redirector.setLogInputString(logInputString.booleanValue()); + } if (inputMapper != null) { String[] inputTargets = null; try { diff --git a/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java b/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java index d57eacc87..b12596e9e 100755 --- a/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java +++ b/src/testcases/org/apache/tools/ant/types/RedirectorElementTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation. + * Copyright 2004-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ */ package org.apache.tools.ant.types; +import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildFileTest; public class RedirectorElementTest extends BuildFileTest { @@ -25,7 +26,7 @@ public class RedirectorElementTest extends BuildFileTest { } public void setUp() { - configureProject("src/etc/testcases/types/redirector.xml"); + configureProject("src/etc/testcases/types/redirector.xml", Project.MSG_VERBOSE); } public void test1() { @@ -48,4 +49,8 @@ public class RedirectorElementTest extends BuildFileTest { executeTarget("test4"); } + public void testLogInputString() { + executeTarget("testLogInputString"); + assertDebuglogContaining("Using input string"); + } }