From 1909e147eef504b349518a1e78d89beb28df4a31 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Fri, 11 May 2018 11:38:21 +0200 Subject: [PATCH 1/4] Checkstyle: indentation/whitespace (cf master) --- .../apache/tools/ant/taskdefs/MacroDef.java | 2 +- .../taskdefs/optional/junit/Enumerations.java | 177 +++++++++--------- .../org/apache/tools/ant/BuildFileRule.java | 2 +- 3 files changed, 89 insertions(+), 92 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java index 95757b6df..937cdd1e1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java +++ b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java @@ -670,7 +670,7 @@ public class MacroDef extends AntlibDefinition { */ public boolean equals(Object obj) { if (obj == this) { - return true; + return true; } if (obj == null || !obj.getClass().equals(getClass())) { return false; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Enumerations.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Enumerations.java index 327547efc..c6a014dcd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/Enumerations.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/Enumerations.java @@ -28,77 +28,76 @@ import java.util.NoSuchElementException; */ public final class Enumerations { - private Enumerations() { - } + private Enumerations() { + } - /** - * creates an enumeration from an array of objects. - * @param array the array of object to enumerate. - * @return the enumeration over the array of objects. - */ - public static Enumeration fromArray(Object[] array) { - return new ArrayEnumeration(array); - } + /** + * creates an enumeration from an array of objects. + * @param array the array of object to enumerate. + * @return the enumeration over the array of objects. + */ + public static Enumeration fromArray(Object[] array) { + return new ArrayEnumeration(array); + } - /** - * creates an enumeration from an array of enumeration. The created enumeration - * will sequentially enumerate over all elements of each enumeration and skip - * null enumeration elements in the array. - * @param enums the array of enumerations. - * @return the enumeration over the array of enumerations. - */ - public static Enumeration fromCompound(Enumeration[] enums) { - return new CompoundEnumeration(enums); - } + /** + * creates an enumeration from an array of enumeration. The created enumeration + * will sequentially enumerate over all elements of each enumeration and skip + * null enumeration elements in the array. + * @param enums the array of enumerations. + * @return the enumeration over the array of enumerations. + */ + public static Enumeration fromCompound(Enumeration[] enums) { + return new CompoundEnumeration(enums); + } } - /** * Convenient enumeration over an array of objects. */ class ArrayEnumeration implements Enumeration { - /** object array */ - private Object[] array; + /** object array */ + private Object[] array; - /** current index */ - private int pos; + /** current index */ + private int pos; - /** - * Initialize a new enumeration that wraps an array. - * @param array the array of object to enumerate. - */ - public ArrayEnumeration(Object[] array) { - this.array = array; - this.pos = 0; - } - /** - * Tests if this enumeration contains more elements. - * - * @return true if and only if this enumeration object - * contains at least one more element to provide; - * false otherwise. - */ - public boolean hasMoreElements() { - return (pos < array.length); - } + /** + * Initialize a new enumeration that wraps an array. + * @param array the array of object to enumerate. + */ + public ArrayEnumeration(Object[] array) { + this.array = array; + this.pos = 0; + } + /** + * Tests if this enumeration contains more elements. + * + * @return true if and only if this enumeration object + * contains at least one more element to provide; + * false otherwise. + */ + public boolean hasMoreElements() { + return (pos < array.length); + } - /** - * Returns the next element of this enumeration if this enumeration - * object has at least one more element to provide. - * - * @return the next element of this enumeration. - * @throws NoSuchElementException if no more elements exist. - */ - public Object nextElement() throws NoSuchElementException { - if (hasMoreElements()) { - Object o = array[pos]; - pos++; - return o; - } - throw new NoSuchElementException(); + /** + * Returns the next element of this enumeration if this enumeration + * object has at least one more element to provide. + * + * @return the next element of this enumeration. + * @throws NoSuchElementException if no more elements exist. + */ + public Object nextElement() throws NoSuchElementException { + if (hasMoreElements()) { + Object o = array[pos]; + pos++; + return o; } + throw new NoSuchElementException(); + } } /** * Convenient enumeration over an array of enumeration. For example: @@ -130,48 +129,46 @@ class ArrayEnumeration implements Enumeration { * } * */ - class CompoundEnumeration implements Enumeration { +class CompoundEnumeration implements Enumeration { - /** enumeration array */ - private Enumeration[] enumArray; + /** enumeration array */ + private Enumeration[] enumArray; - /** index in the enums array */ - private int index = 0; + /** index in the enums array */ + private int index = 0; public CompoundEnumeration(Enumeration[] enumarray) { - this.enumArray = enumarray; + this.enumArray = enumarray; } - /** - * Tests if this enumeration contains more elements. - * - * @return true if and only if this enumeration object - * contains at least one more element to provide; - * false otherwise. - */ + /** + * Tests if this enumeration contains more elements. + * + * @return true if and only if this enumeration object + * contains at least one more element to provide; + * false otherwise. + */ public boolean hasMoreElements() { - while (index < enumArray.length) { - if (enumArray[index] != null && enumArray[index].hasMoreElements()) { - return true; - } - index++; - } - return false; + while (index < enumArray.length) { + if (enumArray[index] != null && enumArray[index].hasMoreElements()) { + return true; + } + index++; + } + return false; } - /** - * Returns the next element of this enumeration if this enumeration - * object has at least one more element to provide. - * - * @return the next element of this enumeration. - * @throws NoSuchElementException if no more elements exist. - */ + /** + * Returns the next element of this enumeration if this enumeration + * object has at least one more element to provide. + * + * @return the next element of this enumeration. + * @throws NoSuchElementException if no more elements exist. + */ public Object nextElement() throws NoSuchElementException { - if (hasMoreElements()) { - return enumArray[index].nextElement(); - } - throw new NoSuchElementException(); + if (hasMoreElements()) { + return enumArray[index].nextElement(); + } + throw new NoSuchElementException(); } } - - diff --git a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java index c5a71c75a..a4441098a 100644 --- a/src/tests/junit/org/apache/tools/ant/BuildFileRule.java +++ b/src/tests/junit/org/apache/tools/ant/BuildFileRule.java @@ -170,7 +170,7 @@ public class BuildFileRule extends ExternalResource { * * @param targetName the target in the currently configured build file to run. */ - public void executeTarget(String targetName) { + public void executeTarget(String targetName) { outputBuffer = new StringBuffer(); PrintStream out = new PrintStream(new AntOutputStream(outputBuffer)); errorBuffer = new StringBuffer(); From fd514f77c1be33f307e78baeda66080a23f5d7b8 Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Fri, 11 May 2018 12:36:36 +0200 Subject: [PATCH 2/4] Shorten fully-qualified names (cherry-pick b4243b9) --- .../org/apache/tools/ant/ComponentHelper.java | 3 +- .../org/apache/tools/ant/Diagnostics.java | 1 + .../apache/tools/ant/IntrospectionHelper.java | 33 ++++++++++--------- src/main/org/apache/tools/ant/Project.java | 3 +- .../apache/tools/ant/input/InputHandler.java | 6 ++-- .../apache/tools/ant/taskdefs/MakeUrl.java | 2 +- .../org/apache/tools/ant/taskdefs/Rename.java | 4 +-- .../org/apache/tools/ant/taskdefs/Rmic.java | 4 +-- .../org/apache/tools/ant/taskdefs/Sleep.java | 5 ++- .../tools/ant/taskdefs/XSLTProcess.java | 3 +- .../tools/ant/taskdefs/XmlProperty.java | 3 +- .../ant/taskdefs/condition/IsReachable.java | 2 +- .../tools/ant/taskdefs/condition/Xor.java | 2 +- .../optional/ejb/BorlandDeploymentTool.java | 2 +- .../j2ee/AbstractHotDeploymentTool.java | 2 +- .../j2ee/GenericHotDeploymentTool.java | 4 +-- .../optional/j2ee/HotDeploymentTool.java | 4 +-- .../taskdefs/optional/j2ee/ServerDeploy.java | 2 +- .../ant/taskdefs/optional/pvcs/Pvcs.java | 5 +-- .../optional/unix/AbstractAccessTask.java | 4 +-- .../tools/ant/types/RedirectorElement.java | 4 +-- .../ant/types/optional/ScriptCondition.java | 2 +- .../ant/types/optional/ScriptSelector.java | 2 +- .../ant/types/selectors/TokenizedPath.java | 3 +- .../modifiedselector/ModifiedSelector.java | 1 + .../apache/tools/ant/taskdefs/ZipTest.java | 2 +- .../tools/ant/taskdefs/optional/RpmTest.java | 3 +- 27 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java index 31ab880d9..6672fdacb 100644 --- a/src/main/org/apache/tools/ant/ComponentHelper.java +++ b/src/main/org/apache/tools/ant/ComponentHelper.java @@ -38,6 +38,7 @@ import java.util.Stack; import org.apache.tools.ant.launch.Launcher; import org.apache.tools.ant.taskdefs.Definer; +import org.apache.tools.ant.taskdefs.Property; import org.apache.tools.ant.taskdefs.Typedef; import org.apache.tools.ant.util.FileUtils; @@ -523,7 +524,7 @@ public class ComponentHelper { if (task == null && taskType.equals(ANT_PROPERTY_TASK)) { // quick fix for Ant.java use of property before // initializing the project - addTaskDefinition(ANT_PROPERTY_TASK, org.apache.tools.ant.taskdefs.Property.class); + addTaskDefinition(ANT_PROPERTY_TASK, Property.class); task = createNewTask(taskType); } return task; diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index e5b7913a2..6007e2af3 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -457,6 +457,7 @@ public final class Diagnostics { /** * Call org.apache.env.Which if available + * * @param out the stream to print the content to. */ private static void doReportWhich(PrintStream out) { diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index ff64e9d6d..c13f802a4 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -17,6 +17,7 @@ */ package org.apache.tools.ant; +import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -187,30 +188,30 @@ public final class IntrospectionHelper { final Class[] args = m.getParameterTypes(); // check of add[Configured](Class) pattern - if (args.length == 1 && java.lang.Void.TYPE.equals(returnType) + if (args.length == 1 && Void.TYPE.equals(returnType) && ("add".equals(name) || "addConfigured".equals(name))) { insertAddTypeMethod(m); continue; } // not really user settable properties on tasks/project components - if (org.apache.tools.ant.ProjectComponent.class.isAssignableFrom(bean) + if (ProjectComponent.class.isAssignableFrom(bean) && args.length == 1 && isHiddenSetMethod(name, args[0])) { continue; } // hide addTask for TaskContainers if (isContainer() && args.length == 1 && "addTask".equals(name) - && org.apache.tools.ant.Task.class.equals(args[0])) { + && Task.class.equals(args[0])) { continue; } - if ("addText".equals(name) && java.lang.Void.TYPE.equals(returnType) - && args.length == 1 && java.lang.String.class.equals(args[0])) { + if ("addText".equals(name) && Void.TYPE.equals(returnType) + && args.length == 1 && String.class.equals(args[0])) { addTextMethod = methods[i]; - } else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType) + } else if (name.startsWith("set") && Void.TYPE.equals(returnType) && args.length == 1 && !args[0].isArray()) { final String propName = getPropertyName(name, "set"); AttributeSetter as = attributeSetters.get(propName); if (as != null) { - if (java.lang.String.class.equals(args[0])) { + if (String.class.equals(args[0])) { /* Ignore method m, as there is an overloaded form of this method that takes in a @@ -219,7 +220,7 @@ public final class IntrospectionHelper { */ continue; } - if (java.io.File.class.equals(args[0])) { + if (File.class.equals(args[0])) { // Ant Resources/FileProviders override java.io.File if (Resource.class.equals(as.type) || FileProvider.class.equals(as.type)) { continue; @@ -251,8 +252,8 @@ public final class IntrospectionHelper { nestedCreators.put(propName, new CreateNestedCreator(m)); } } else if (name.startsWith("addConfigured") - && java.lang.Void.TYPE.equals(returnType) && args.length == 1 - && !java.lang.String.class.equals(args[0]) + && Void.TYPE.equals(returnType) && args.length == 1 + && !String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) { try { Constructor constructor = null; @@ -269,8 +270,8 @@ public final class IntrospectionHelper { // ignore } } else if (name.startsWith("add") - && java.lang.Void.TYPE.equals(returnType) && args.length == 1 - && !java.lang.String.class.equals(args[0]) + && Void.TYPE.equals(returnType) && args.length == 1 + && !String.class.equals(args[0]) && !args[0].isArray() && !args[0].isPrimitive()) { try { Constructor constructor = null; @@ -308,10 +309,10 @@ public final class IntrospectionHelper { * @return true if the given set method is to be hidden. */ private boolean isHiddenSetMethod(final String name, final Class type) { - if ("setLocation".equals(name) && org.apache.tools.ant.Location.class.equals(type)) { + if ("setLocation".equals(name) && Location.class.equals(type)) { return true; } - if ("setTaskType".equals(name) && java.lang.String.class.equals(type)) { + if ("setTaskType".equals(name) && String.class.equals(type)) { return true; } return false; @@ -1060,7 +1061,7 @@ public final class IntrospectionHelper { }; } // simplest case - setAttribute expects String - if (java.lang.String.class.equals(reflectedArg)) { + if (String.class.equals(reflectedArg)) { return new AttributeSetter(m, arg) { @Override public void set(final Project p, final Object parent, final String value) @@ -1685,7 +1686,7 @@ public final class IntrospectionHelper { if (exposedClass == null) { continue; } - final Method method = findMatchingMethod(exposedClass, methods); + final Method method = findMatchingMethod(exposedClass, methods); if (method == null) { continue; } diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 461b89ac5..5feeb38e9 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -38,6 +38,7 @@ import java.util.WeakHashMap; import org.apache.tools.ant.helper.DefaultExecutor; import org.apache.tools.ant.input.DefaultInputHandler; import org.apache.tools.ant.input.InputHandler; +import org.apache.tools.ant.launch.Locator; import org.apache.tools.ant.types.Description; import org.apache.tools.ant.types.FilterSet; import org.apache.tools.ant.types.FilterSetCollection; @@ -326,7 +327,7 @@ public class Project implements ResourceFactory { * to the result */ private void setAntLib() { - final File antlib = org.apache.tools.ant.launch.Locator.getClassSource( + final File antlib = Locator.getClassSource( Project.class); if (antlib != null) { setPropertyInternal(MagicNames.ANT_LIB, antlib.getAbsolutePath()); diff --git a/src/main/org/apache/tools/ant/input/InputHandler.java b/src/main/org/apache/tools/ant/input/InputHandler.java index aea60fcc0..a71546ffe 100644 --- a/src/main/org/apache/tools/ant/input/InputHandler.java +++ b/src/main/org/apache/tools/ant/input/InputHandler.java @@ -18,6 +18,8 @@ package org.apache.tools.ant.input; +import org.apache.tools.ant.BuildException; + /** * Plugin to Ant to handle requests for user input. * @@ -34,8 +36,8 @@ public interface InputHandler { *

Postcondition: request.getInput will return a non-null * value, request.isInputValid will return true.

* @param request the request to be processed - * @throws org.apache.tools.ant.BuildException if the input cannot be read from the console + * @throws BuildException if the input cannot be read from the console */ void handleInput(InputRequest request) - throws org.apache.tools.ant.BuildException; + throws BuildException; } diff --git a/src/main/org/apache/tools/ant/taskdefs/MakeUrl.java b/src/main/org/apache/tools/ant/taskdefs/MakeUrl.java index 9fc94bc6a..5c1e44c95 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MakeUrl.java +++ b/src/main/org/apache/tools/ant/taskdefs/MakeUrl.java @@ -231,7 +231,7 @@ public class MakeUrl extends Task { /** * Create the url * - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if something goes wrong with the build */ @Override diff --git a/src/main/org/apache/tools/ant/taskdefs/Rename.java b/src/main/org/apache/tools/ant/taskdefs/Rename.java index f4199bb2c..cce74e279 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rename.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rename.java @@ -69,8 +69,8 @@ public class Rename extends Task { /** * Renames the file src to dest - * @exception org.apache.tools.ant.BuildException The exception is - * thrown, if the rename operation fails. + * + * @throws BuildException if the rename operation fails */ public void execute() throws BuildException { log("DEPRECATED - The rename task is deprecated. Use move instead."); diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 0a54b3efe..e093e498a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -590,7 +590,7 @@ public class Rmic extends MatchingTask { /** * execute by creating an instance of an implementation * class and getting to do the work - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if there's a problem with baseDir or RMIC */ @Override @@ -701,7 +701,7 @@ public class Rmic extends MatchingTask { /** * Move the generated source file(s) to the base directory * - * @throws org.apache.tools.ant.BuildException When error + * @throws BuildException When error * copying/removing files. */ private void moveGeneratedFile(File baseDir, File sourceBaseFile, String classname, diff --git a/src/main/org/apache/tools/ant/taskdefs/Sleep.java b/src/main/org/apache/tools/ant/taskdefs/Sleep.java index 6468c3901..7f124cca1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Sleep.java +++ b/src/main/org/apache/tools/ant/taskdefs/Sleep.java @@ -166,10 +166,9 @@ public class Sleep extends Task { /** - * Executes this build task. Throws org.apache.tools.ant.BuildException - * if there is an error during task execution. + * Executes this build task. * - * @exception BuildException Description of Exception + * @throws BuildException if there is an error during task execution */ @Override public void execute() diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 83943141f..a28e15346 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -41,6 +41,7 @@ import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.PropertyHelper; +import org.apache.tools.ant.taskdefs.optional.TraXLiaison; import org.apache.tools.ant.types.CommandlineJava; import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Mapper; @@ -713,7 +714,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { */ private void resolveProcessor(final String proc) throws Exception { if (proc.equals(PROCESSOR_TRAX)) { - liaison = new org.apache.tools.ant.taskdefs.optional.TraXLiaison(); + liaison = new TraXLiaison(); } else { //anything else is a classname final Class clazz = loadClass(proc); diff --git a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java index 6f64a888e..9feb3579d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java +++ b/src/main/org/apache/tools/ant/taskdefs/XmlProperty.java @@ -27,6 +27,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.ResourceCollection; @@ -174,7 +175,7 @@ import org.xml.sax.SAXException; * * @ant.task name="xmlproperty" category="xml" */ -public class XmlProperty extends org.apache.tools.ant.Task { +public class XmlProperty extends Task { private Resource src; private String prefix = ""; diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java index e673b828b..818393b06 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java @@ -136,7 +136,7 @@ public class IsReachable extends ProjectComponent implements Condition { * * @return true if the condition is true. * - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if an error occurs */ public boolean eval() throws BuildException { diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Xor.java b/src/main/org/apache/tools/ant/taskdefs/condition/Xor.java index a2e675cb5..2cc8e4c49 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Xor.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Xor.java @@ -31,7 +31,7 @@ public class Xor extends ConditionBase implements Condition { /** * Evaluate the contained conditions. * @return the result of xoring the conditions together. - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if an error occurs. */ public boolean eval() throws BuildException { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java index 99694f6fd..0c9e63266 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java @@ -325,7 +325,7 @@ public class BorlandDeploymentTool extends GenericDeploymentTool * @param sourceJar java.io.File representing the produced jar file */ private void verifyBorlandJarV4(File sourceJar) { - org.apache.tools.ant.taskdefs.Java javaTask = null; + Java javaTask = null; log("verify BAS " + sourceJar, Project.MSG_INFO); try { String args = verifyArgs; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java index 11447e028..7c47f713c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java @@ -85,7 +85,7 @@ public abstract class AbstractHotDeploymentTool implements HotDeploymentTool { * validation of boilerplate attributes. *

Only the "action" attribute is required in the * base class. Subclasses should check attributes accordingly. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. + * @throws BuildException if the attributes are invalid or incomplete. */ public void validateAttributes() throws BuildException { if (task.getAction() == null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java index 5a5abbab6..e4a5b6b7b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java @@ -88,7 +88,7 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { * Perform the actual deployment. * For this generic implementation, a JVM is spawned using the * supplied classpath, classname, JVM args, and command line arguments. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. + * @exception BuildException if the attributes are invalid or incomplete. */ public void deploy() throws BuildException { java.setClassname(className); @@ -101,7 +101,7 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { /** * Validates the passed in attributes. * Ensures the className and arguments attribute have been set. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. + * @throws BuildException if the attributes are invalid or incomplete. */ public void validateAttributes() throws BuildException { super.validateAttributes(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/HotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/HotDeploymentTool.java index 16c55d8e7..dae9667c8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/HotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/HotDeploymentTool.java @@ -43,13 +43,13 @@ public interface HotDeploymentTool { /** * Validates the passed in attributes. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. + * @exception BuildException if the attributes are invalid or incomplete. */ void validateAttributes() throws BuildException; /** * Perform the actual deployment. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. + * @throws BuildException if the attributes are invalid or incomplete. */ void deploy() throws BuildException; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java index 8965b8e88..02d6f61cb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java @@ -97,7 +97,7 @@ public class ServerDeploy extends Task { *

This method calls the deploy() method on each of the vendor-specific tools * in the vendorTools collection. This performs the actual * process of deployment on each tool. - * @exception org.apache.tools.ant.BuildException if the attributes + * @throws BuildException if the attributes * are invalid or incomplete, or a failure occurs in the deployment process. */ public void execute() throws BuildException { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java index 6956019af..964466184 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java @@ -33,6 +33,7 @@ import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.taskdefs.LogOutputStream; @@ -71,7 +72,7 @@ import org.apache.tools.ant.util.FileUtils; * discussion. * */ -public class Pvcs extends org.apache.tools.ant.Task { +public class Pvcs extends Task { // CheckStyle - magic numbers // checking for "X:\ 0=dquote,1=letter,2=:,3=\ private static final int POS_1 = 1; @@ -143,7 +144,7 @@ public class Pvcs extends org.apache.tools.ant.Task { } /** - * @exception org.apache.tools.ant.BuildException Something is stopping the build... + * @throws BuildException Something is stopping the build... */ public void execute() throws org.apache.tools.ant.BuildException { int result = 0; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java index 2e1331f68..a2b53db18 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/AbstractAccessTask.java @@ -32,6 +32,7 @@ package org.apache.tools.ant.taskdefs.optional.unix; import java.io.File; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.ExecuteOn; import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.FileSet; @@ -42,8 +43,7 @@ import org.apache.tools.ant.types.FileSet; * @ant.task category="filesystem" */ -public abstract class AbstractAccessTask - extends org.apache.tools.ant.taskdefs.ExecuteOn { +public abstract class AbstractAccessTask extends ExecuteOn { /** * Chmod task for setting file and directory permissions. diff --git a/src/main/org/apache/tools/ant/types/RedirectorElement.java b/src/main/org/apache/tools/ant/types/RedirectorElement.java index e72d394eb..79ab146b8 100644 --- a/src/main/org/apache/tools/ant/types/RedirectorElement.java +++ b/src/main/org/apache/tools/ant/types/RedirectorElement.java @@ -27,6 +27,7 @@ import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Redirector; +import org.apache.tools.ant.util.MergingMapper; /** * Element representation of a Redirector. @@ -556,8 +557,7 @@ public class RedirectorElement extends DataType { */ protected Mapper createMergeMapper(File destfile) { Mapper result = new Mapper(getProject()); - result.setClassname( - org.apache.tools.ant.util.MergingMapper.class.getName()); + result.setClassname(MergingMapper.class.getName()); result.setTo(destfile.getAbsolutePath()); return result; } diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java b/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java index fac02bfa4..ee432b123 100644 --- a/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java +++ b/src/main/org/apache/tools/ant/types/optional/ScriptCondition.java @@ -38,7 +38,7 @@ public class ScriptCondition extends AbstractScriptComponent implements Conditio * * @return true if the condition is true * - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if an error occurs */ public boolean eval() throws BuildException { diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java index c07ed13d8..45e8784f0 100644 --- a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java +++ b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java @@ -85,7 +85,7 @@ public class ScriptSelector extends BaseSelector { /** * Initialize on demand. * - * @throws org.apache.tools.ant.BuildException + * @throws BuildException * if something goes wrong */ private void init() throws BuildException { diff --git a/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java b/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java index cc87786d2..ed899e4c0 100644 --- a/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java +++ b/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java @@ -78,7 +78,8 @@ public class TokenizedPath { tokenizedPath[parent.tokenizedPath.length] = child; } - /* package */ TokenizedPath(String path, String[] tokens) { + /* package */ + TokenizedPath(String path, String[] tokens) { this.path = path; this.tokenizedPath = tokens; } diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java index 0899f9128..c1bcac7a9 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java @@ -397,6 +397,7 @@ public class ModifiedSelector extends BaseExtendSelector * @param type the type to check against * @return a castable object */ + @SuppressWarnings("unchecked") protected T loadClass(String classname, String msg, Class type) { try { // load the specified class diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java index 2a754ae76..4a73aec82 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -244,7 +244,7 @@ public class ZipTest { @Test public void testTarFileSet() throws IOException { - buildRule.executeTarget("testTarFileSet"); + buildRule.executeTarget("testTarFileSet"); org.apache.tools.zip.ZipFile zf = null; try { zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java index ac4462d53..b557f4497 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs.optional; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.types.Commandline; @@ -32,7 +33,7 @@ public class RpmTest { @Test public void testShouldThrowExceptionWhenRpmFails() throws Exception { Rpm rpm = new MyRpm(); - rpm.setProject(new org.apache.tools.ant.Project()); + rpm.setProject(new Project()); rpm.setFailOnError(true); // execute try { From 2495b9a97e4a392c6dc05ca3464b6a4a889f9f71 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Sun, 20 May 2018 17:45:43 +0200 Subject: [PATCH 3/4] add basedir attribute to https://bz.apache.org/bugzilla/show_bug.cgi?id=62379 --- WHATSNEW | 5 +++++ manual/Types/resources.html | 9 ++++++++ .../ant/types/resources/ResourceList.java | 22 +++++++++++++++++++ src/tests/antunit/taskdefs/copy-test.xml | 18 +++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/WHATSNEW b/WHATSNEW index 8834fadcc..66e7399a0 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -43,6 +43,11 @@ Other changes: availableProcessors, freeMemory, maxMemory and totalMemory methods of the Java Runtime class. + * has a new basedir attribute that can be used to + resolve relative names and provides a root for the FileResources + generated. + Bugzilla Report 62379 + Changes from Ant 1.9.10 TO Ant 1.9.11 ===================================== diff --git a/manual/Types/resources.html b/manual/Types/resources.html index 8ba77aa12..5bdc2314f 100644 --- a/manual/Types/resources.html +++ b/manual/Types/resources.html @@ -1334,6 +1334,15 @@ collection. Since Ant 1.9.5.

The encoding of the nested resources No, default is platform default + + basedir + Base directory that is used to resolve + relative file names against. Is also used to provide a base + directory to the FileResources created by this resource + collection. Since Ant 1.9.12 + + No + diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java index b24277dda..79cbbb5cb 100644 --- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java +++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.types.resources; import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; @@ -49,6 +50,7 @@ public class ResourceList extends DataType implements ResourceCollection { private final Union cachedResources = new Union(); private volatile boolean cached = false; private String encoding = null; + private File baseDir; public ResourceList() { cachedResources.setCache(true); @@ -99,6 +101,21 @@ public class ResourceList extends DataType implements ResourceCollection { this.encoding = encoding; } + /** + * Basedir to use for file resources read from nested resources - + * this allows the resources contained inside this collection to + * be considered relative to a certain base directory. + * + * @param basedir the basedir + * @since Ant 1.9.12 + */ + public final void setBasedir(File baseDir) { + if (isReference()) { + throw tooManyAttributes(); + } + this.baseDir = baseDir; + } + /** * Makes this instance in effect a reference to another ResourceList * instance. @@ -250,6 +267,11 @@ public class ResourceList extends DataType implements ResourceCollection { // resource } } + if (baseDir != null) { + FileResource fr = new FileResource(baseDir, expandedLine); + fr.setProject(getProject()); + return fr; + } return new FileResource(getProject(), expandedLine); } } diff --git a/src/tests/antunit/taskdefs/copy-test.xml b/src/tests/antunit/taskdefs/copy-test.xml index 5bca72480..1fd4b59f1 100644 --- a/src/tests/antunit/taskdefs/copy-test.xml +++ b/src/tests/antunit/taskdefs/copy-test.xml @@ -484,4 +484,22 @@ public class NullByteStreamResource extends Resource { + + + + + + + Testfile + + + + + + + + + + From fee6d73d57e1c06c49d9515a0ed077dfcaf19d18 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Sun, 20 May 2018 18:37:16 +0200 Subject: [PATCH 4/4] add encoding attribute to in/excludesfile https://bz.apache.org/bugzilla/show_bug.cgi?id=62379 --- WHATSNEW | 5 ++ manual/Types/patternset.html | 5 ++ src/etc/testcases/types/fileset.xml | 40 ++++++++++ .../org/apache/tools/ant/taskdefs/Delete.java | 4 +- .../tools/ant/taskdefs/MatchingTask.java | 4 +- .../tools/ant/types/AbstractFileSet.java | 4 +- .../apache/tools/ant/types/PatternSet.java | 78 ++++++++++++++++--- .../tools/ant/types/resources/Files.java | 4 +- .../apache/tools/ant/types/FileSetTest.java | 28 ++++++- .../tools/ant/types/PatternSetTest.java | 29 +++++++ 10 files changed, 179 insertions(+), 22 deletions(-) create mode 100644 src/etc/testcases/types/fileset.xml diff --git a/WHATSNEW b/WHATSNEW index 66e7399a0..9e096c9d8 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -48,6 +48,11 @@ Other changes: generated. Bugzilla Report 62379 + * The and nested elements of + and now support an encoding attribute that + can be used to specify the file's encoding. + Bugzilla Report 62379 + Changes from Ant 1.9.10 TO Ant 1.9.11 ===================================== diff --git a/manual/Types/patternset.html b/manual/Types/patternset.html index 4ad433dbc..1cfcb8f0b 100644 --- a/manual/Types/patternset.html +++ b/manual/Types/patternset.html @@ -125,6 +125,11 @@ you can use to test the existence of a property.

not set. No + + encoding + The encoding of the file. Since Ant 1.9.12 + No, default is platform default +

patternset

Patternsets may be nested within one another, adding the nested diff --git a/src/etc/testcases/types/fileset.xml b/src/etc/testcases/types/fileset.xml new file mode 100644 index 000000000..c0f6949ff --- /dev/null +++ b/src/etc/testcases/types/fileset.xml @@ -0,0 +1,40 @@ + + + + + fileset.xml + + + + + + + ${property} + + + + fileset.xml + + + + + + + ${property} + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Delete.java b/src/main/org/apache/tools/ant/taskdefs/Delete.java index b22c7cc91..bf266a09c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Delete.java +++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java @@ -247,7 +247,7 @@ public class Delete extends MatchingTask { /** * add a name entry on the include files list - * @return a NameEntry object to be configured + * @return a PatternFileNameEntry object to be configured */ public PatternSet.NameEntry createIncludesFile() { usedMatchingTask = true; @@ -265,7 +265,7 @@ public class Delete extends MatchingTask { /** * add a name entry on the include files list - * @return a NameEntry object to be configured + * @return a PatternFileNameEntry object to be configured */ public PatternSet.NameEntry createExcludesFile() { usedMatchingTask = true; diff --git a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java index c35af03a2..8707a39a3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java @@ -77,7 +77,7 @@ public abstract class MatchingTask extends Task implements SelectorContainer { /** * add a name entry on the include files list - * @return an NameEntry object to be configured + * @return an PatternFileNameEntry object to be configured */ public PatternSet.NameEntry createIncludesFile() { return fileset.createIncludesFile(); @@ -93,7 +93,7 @@ public abstract class MatchingTask extends Task implements SelectorContainer { /** * add a name entry on the include files list - * @return an NameEntry object to be configured + * @return an PatternFileNameEntry object to be configured */ public PatternSet.NameEntry createExcludesFile() { return fileset.createExcludesFile(); diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java index 0c1d57d4e..1dca341c1 100644 --- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java +++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java @@ -189,7 +189,7 @@ public abstract class AbstractFileSet extends DataType /** * Add a name entry to the include files list. - * @return PatternSet.NameEntry. + * @return PatternSet.PatternFileNameEntry. */ public synchronized PatternSet.NameEntry createIncludesFile() { if (isReference()) { @@ -213,7 +213,7 @@ public abstract class AbstractFileSet extends DataType /** * Add a name entry to the excludes files list. - * @return PatternSet.NameEntry. + * @return PatternSet.PatternFileNameEntry. */ public synchronized PatternSet.NameEntry createExcludesFile() { if (isReference()) { diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java index 9fb94050c..cd5797b2d 100644 --- a/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/src/main/org/apache/tools/ant/types/PatternSet.java @@ -19,8 +19,10 @@ package org.apache.tools.ant.types; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; @@ -40,8 +42,8 @@ import org.apache.tools.ant.util.FileUtils; public class PatternSet extends DataType implements Cloneable { private List includeList = new ArrayList(); private List excludeList = new ArrayList(); - private List includesFileList = new ArrayList(); - private List excludesFileList = new ArrayList(); + private List includesFileList = new ArrayList(); + private List excludesFileList = new ArrayList(); /** * inner class to hold a name on list. "If" and "Unless" attributes @@ -176,6 +178,45 @@ public class PatternSet extends DataType implements Cloneable { } } + /** + * Adds encoding support to {@link NameEntry}. + * @since Ant 1.9.12 + */ + public class PatternFileNameEntry extends NameEntry { + private String encoding; + + /** + * Encoding to use when reading the file, defaults to the platform's default + * encoding. + * + *

+ * For a list of possible values see + * + * https://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.html. + *

+ * + * @param encoding String + */ + public final void setEncoding(String encoding) { + this.encoding = encoding; + } + + /** + * Encoding to use when reading the file, defaults to the platform's default + * encoding. + */ + public final String getEncoding() { + return encoding; + } + + @Override + public String toString() { + String baseString = super.toString(); + return encoding == null ? baseString + : new StringBuilder(baseString).append(";encoding->").append(encoding).toString(); + } + } + private static final class InvertedPatternSet extends PatternSet { private InvertedPatternSet(PatternSet p) { setProject(p.getProject()); @@ -255,7 +296,7 @@ public class PatternSet extends DataType implements Cloneable { if (isReference()) { throw noChildrenAllowed(); } - return addPatternToList(includesFileList); + return addPatternFileToList(includesFileList); } /** @@ -277,7 +318,7 @@ public class PatternSet extends DataType implements Cloneable { if (isReference()) { throw noChildrenAllowed(); } - return addPatternToList(excludesFileList); + return addPatternFileToList(excludesFileList); } /** @@ -325,6 +366,15 @@ public class PatternSet extends DataType implements Cloneable { return result; } + /** + * add a pattern file name entry to the given list + */ + private PatternFileNameEntry addPatternFileToList(List list) { + PatternFileNameEntry result = new PatternFileNameEntry(); + list.add(result); + return result; + } + /** * Sets the name of the file containing the includes patterns. * @@ -355,13 +405,17 @@ public class PatternSet extends DataType implements Cloneable { * Reads path matching patterns from a file and adds them to the * includes or excludes list (as appropriate). */ - private void readPatterns(File patternfile, List patternlist, Project p) + private void readPatterns(File patternfile, String encoding, List patternlist, Project p) throws BuildException { BufferedReader patternReader = null; try { // Get a FileReader - patternReader = new BufferedReader(new FileReader(patternfile)); + if (encoding == null) { + patternReader = new BufferedReader(new FileReader(patternfile)); + } else { + patternReader = new BufferedReader(new InputStreamReader(new FileInputStream(patternfile), encoding)); + } // Create one NameEntry in the appropriate pattern list for each // line in the file. @@ -478,7 +532,7 @@ public class PatternSet extends DataType implements Cloneable { */ private void readFiles(Project p) { if (includesFileList.size() > 0) { - for (NameEntry ne : includesFileList) { + for (PatternFileNameEntry ne : includesFileList) { String fileName = ne.evalName(p); if (fileName != null) { File inclFile = p.resolveFile(fileName); @@ -486,13 +540,13 @@ public class PatternSet extends DataType implements Cloneable { throw new BuildException("Includesfile " + inclFile.getAbsolutePath() + " not found."); } - readPatterns(inclFile, includeList, p); + readPatterns(inclFile, ne.getEncoding(), includeList, p); } } includesFileList.clear(); } if (excludesFileList.size() > 0) { - for (NameEntry ne : excludesFileList) { + for (PatternFileNameEntry ne : excludesFileList) { String fileName = ne.evalName(p); if (fileName != null) { File exclFile = p.resolveFile(fileName); @@ -500,7 +554,7 @@ public class PatternSet extends DataType implements Cloneable { throw new BuildException("Excludesfile " + exclFile.getAbsolutePath() + " not found."); } - readPatterns(exclFile, excludeList, p); + readPatterns(exclFile, ne.getEncoding(), excludeList, p); } } excludesFileList.clear(); @@ -523,8 +577,8 @@ public class PatternSet extends DataType implements Cloneable { PatternSet ps = (PatternSet) super.clone(); ps.includeList = new ArrayList(includeList); ps.excludeList = new ArrayList(excludeList); - ps.includesFileList = new ArrayList(includesFileList); - ps.excludesFileList = new ArrayList(excludesFileList); + ps.includesFileList = new ArrayList(includesFileList); + ps.excludesFileList = new ArrayList(excludesFileList); return ps; } catch (CloneNotSupportedException e) { throw new BuildException(e); diff --git a/src/main/org/apache/tools/ant/types/resources/Files.java b/src/main/org/apache/tools/ant/types/resources/Files.java index 521bcc8d2..a28e3a75c 100644 --- a/src/main/org/apache/tools/ant/types/resources/Files.java +++ b/src/main/org/apache/tools/ant/types/resources/Files.java @@ -124,7 +124,7 @@ public class Files extends AbstractSelectorContainer /** * Add a name entry to the include files list. - * @return PatternSet.NameEntry. + * @return PatternSet.PatternFileNameEntry. */ public synchronized PatternSet.NameEntry createIncludesFile() { if (isReference()) { @@ -148,7 +148,7 @@ public class Files extends AbstractSelectorContainer /** * Add a name entry to the excludes files list. - * @return PatternSet.NameEntry. + * @return PatternSet.PatternFileNameEntry. */ public synchronized PatternSet.NameEntry createExcludesFile() { if (isReference()) { diff --git a/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java index e5aa8758f..3ca5faa46 100644 --- a/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java @@ -18,17 +18,41 @@ package org.apache.tools.ant.types; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * JUnit 4 testcases for org.apache.tools.ant.types.FileSet. - * - *

This doesn't actually test much, mainly reference handling.

*/ public class FileSetTest extends AbstractFileSetTest { + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void buildFileRuleSetUp() { + buildRule.configureProject("src/etc/testcases/types/fileset.xml"); + } + protected AbstractFileSet getInstance() { return new FileSet(); } + @Test + public void testNoEncoding() { + buildRule.executeTarget("no-encoding"); + assertEquals("/abc/fileset.xml", buildRule.getLog()); + } + + @Test + public void testEncoding() { + buildRule.executeTarget("encoding"); + assertEquals("/abc/fileset.xml", buildRule.getLog()); + } + } diff --git a/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java index a4f27b0ce..6baecbb89 100644 --- a/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java @@ -20,11 +20,18 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; import org.junit.Before; import org.junit.Test; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -202,4 +209,26 @@ public class PatternSetTest { assertEquals("Includes", "**/*.java", includes[0]); assertEquals("Excludes", "**/*.class", excludes[0]); } + + @Test + public void testEncodingOfIncludesFile() throws IOException { + File testFile = File.createTempFile("ant-", ".pattern"); + testFile.deleteOnExit(); + OutputStream o = null; + Writer w = null; + try { + o = new FileOutputStream(testFile); + w = new OutputStreamWriter(o, "UTF-16LE"); + w.write("\u00e4\n"); + } finally { + FileUtils.close(w); + FileUtils.close(o); + } + PatternSet p = new PatternSet(); + PatternSet.PatternFileNameEntry ne = + (PatternSet.PatternFileNameEntry) p.createIncludesFile(); + ne.setName(testFile.getAbsolutePath()); + ne.setEncoding("UTF-16LE"); + assertArrayEquals(new String[] { "\u00e4" }, p.getIncludePatterns(project)); + } }