diff options
18 files changed, 1863 insertions, 1863 deletions
diff --git a/src/main/org/apache/tools/ant/TaskConfigurationChecker.java b/src/main/org/apache/tools/ant/TaskConfigurationChecker.java index 8cf6a4a1f..4aef6be73 100644 --- a/src/main/org/apache/tools/ant/TaskConfigurationChecker.java +++ b/src/main/org/apache/tools/ant/TaskConfigurationChecker.java @@ -1,113 +1,113 @@ -/*
- * 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.tools.ant;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * <p>Helper class for the check of the configuration of a given task.
- * This class provides methods for making assumptions about the task configuration.
- * After collecting all violations with <tt>assert*</tt> and <tt>fail</tt>
- * methods the <tt>checkErrors</tt> will throw a BuildException with all collected
- * messages or does nothing if there wasn't any error.</p>
- *
- * <p>Example:</p>
- *
- * <pre>
- * public class MyTask extends Task {
- * ...
- * public void execute() {
- * TaskConfigurationChecker checker = TaskConfigurationChecker(this);
- * checker.assertConfig(
- * srcdir != null,
- * "Attribute 'srcdir' must be set.
- * );
- * checker.assertConfig(
- * srcdir.exists(),
- * "Srcdir (" + srcdir + ") must exist."
- * );
- * if (someComplexCondition()) {
- * fail("Complex condition failed.");
- * }
- * checker.checkErrors();
- * }
- * }
- * </pre>
- *
- * @see <a href="http://martinfowler.com/eaaDev/Notification.html">Notification Pattern</a>
- */
-public class TaskConfigurationChecker {
-
- /** List of all collected error messages. */
- private List/*<String>*/ errors = new ArrayList();
-
- /** Task for which the configuration should be checked. */
- private final Task task;
-
- /**
- * Constructor.
- * @param task which task should be checked
- */
- public TaskConfigurationChecker(Task task) {
- this.task = task;
- }
-
- /**
- * Asserts that a condition is true.
- * @param condition which condition to check
- * @param errormessage errormessage to throw if a condition failed
- */
- public void assertConfig(boolean condition, String errormessage) {
- if (!condition) {
- errors.add(errormessage);
- }
- }
-
- /**
- * Registers an error.
- * @param errormessage the message for the registered error
- */
- public void fail(String errormessage) {
- errors.add(errormessage);
- }
-
- /**
- * Checks if there are any collected errors and throws a BuildException
- * with all messages if there was one or more.
- * @throws BuildException if one or more errors were registered
- */
- public void checkErrors() throws BuildException {
- if (!errors.isEmpty()) {
- StringBuffer sb = new StringBuffer();
- sb.append("Configurationerror on <");
- sb.append(task.getTaskName());
- sb.append(">:");
- sb.append(System.getProperty("line.separator"));
- for (Iterator it = errors.iterator(); it.hasNext();) {
- String msg = (String) it.next();
- sb.append("- ");
- sb.append(msg);
- sb.append(System.getProperty("line.separator"));
- }
- throw new BuildException(sb.toString(), task.getLocation());
- }
- }
-
-}
+/* + * 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.tools.ant; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * <p>Helper class for the check of the configuration of a given task. + * This class provides methods for making assumptions about the task configuration. + * After collecting all violations with <tt>assert*</tt> and <tt>fail</tt> + * methods the <tt>checkErrors</tt> will throw a BuildException with all collected + * messages or does nothing if there wasn't any error.</p> + * + * <p>Example:</p> + * + * <pre> + * public class MyTask extends Task { + * ... + * public void execute() { + * TaskConfigurationChecker checker = TaskConfigurationChecker(this); + * checker.assertConfig( + * srcdir != null, + * "Attribute 'srcdir' must be set. + * ); + * checker.assertConfig( + * srcdir.exists(), + * "Srcdir (" + srcdir + ") must exist." + * ); + * if (someComplexCondition()) { + * fail("Complex condition failed."); + * } + * checker.checkErrors(); + * } + * } + * </pre> + * + * @see <a href="http://martinfowler.com/eaaDev/Notification.html">Notification Pattern</a> + */ +public class TaskConfigurationChecker { + + /** List of all collected error messages. */ + private List/*<String>*/ errors = new ArrayList(); + + /** Task for which the configuration should be checked. */ + private final Task task; + + /** + * Constructor. + * @param task which task should be checked + */ + public TaskConfigurationChecker(Task task) { + this.task = task; + } + + /** + * Asserts that a condition is true. + * @param condition which condition to check + * @param errormessage errormessage to throw if a condition failed + */ + public void assertConfig(boolean condition, String errormessage) { + if (!condition) { + errors.add(errormessage); + } + } + + /** + * Registers an error. + * @param errormessage the message for the registered error + */ + public void fail(String errormessage) { + errors.add(errormessage); + } + + /** + * Checks if there are any collected errors and throws a BuildException + * with all messages if there was one or more. + * @throws BuildException if one or more errors were registered + */ + public void checkErrors() throws BuildException { + if (!errors.isEmpty()) { + StringBuffer sb = new StringBuffer(); + sb.append("Configurationerror on <"); + sb.append(task.getTaskName()); + sb.append(">:"); + sb.append(System.getProperty("line.separator")); + for (Iterator it = errors.iterator(); it.hasNext();) { + String msg = (String) it.next(); + sb.append("- "); + sb.append(msg); + sb.append(System.getProperty("line.separator")); + } + throw new BuildException(sb.toString(), task.getLocation()); + } + } + +} diff --git a/src/main/org/apache/tools/ant/input/SecureInputHandler.java b/src/main/org/apache/tools/ant/input/SecureInputHandler.java index 71d1cfd08..ca935efd9 100644 --- a/src/main/org/apache/tools/ant/input/SecureInputHandler.java +++ b/src/main/org/apache/tools/ant/input/SecureInputHandler.java @@ -1,60 +1,60 @@ -/*
- * 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.tools.ant.input;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.util.ReflectUtil;
-
-/**
- * Prompts and requests input. May loop until a valid input has
- * been entered. Doesn't echo input (requires Java6). If Java6 is not
- * available, fallsback to the DefaultHandler (insecure).
- * @since Ant 1.7.1
- */
-public class SecureInputHandler extends DefaultInputHandler {
-
- /**
- * Default no-args constructor
- */
- public SecureInputHandler() {
- }
-
- /**
- * Handle the input
- * @param request the request to handle
- * @throws BuildException if not possible to read from console
- */
- public void handleInput(InputRequest request) throws BuildException {
- String prompt = getPrompt(request);
- try {
- Class system = Class.forName("java.lang.System");
- Object console = ReflectUtil.invokeStatic(system, "console");
- do {
- char[] input = (char[]) ReflectUtil.invoke(
- console, "readPassword", String.class, prompt,
- Object[].class, (Object[]) null);
- request.setInput(new String(input));
- /* for security zero char array after retrieving value */
- java.util.Arrays.fill(input, ' ');
- } while (!request.isInputValid());
- } catch (Exception e) {
- /* Java6 not present use default handler */
- super.handleInput(request);
- }
- }
+/* + * 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.tools.ant.input; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.ReflectUtil; + +/** + * Prompts and requests input. May loop until a valid input has + * been entered. Doesn't echo input (requires Java6). If Java6 is not + * available, fallsback to the DefaultHandler (insecure). + * @since Ant 1.7.1 + */ +public class SecureInputHandler extends DefaultInputHandler { + + /** + * Default no-args constructor + */ + public SecureInputHandler() { + } + + /** + * Handle the input + * @param request the request to handle + * @throws BuildException if not possible to read from console + */ + public void handleInput(InputRequest request) throws BuildException { + String prompt = getPrompt(request); + try { + Class system = Class.forName("java.lang.System"); + Object console = ReflectUtil.invokeStatic(system, "console"); + do { + char[] input = (char[]) ReflectUtil.invoke( + console, "readPassword", String.class, prompt, + Object[].class, (Object[]) null); + request.setInput(new String(input)); + /* for security zero char array after retrieving value */ + java.util.Arrays.fill(input, ' '); + } while (!request.isInputValid()); + } catch (Exception e) { + /* Java6 not present use default handler */ + super.handleInput(request); + } + } }
\ No newline at end of file diff --git a/src/main/org/apache/tools/ant/listener/ProfileLogger.java b/src/main/org/apache/tools/ant/listener/ProfileLogger.java index 5517b7608..5c7cfb1fb 100644 --- a/src/main/org/apache/tools/ant/listener/ProfileLogger.java +++ b/src/main/org/apache/tools/ant/listener/ProfileLogger.java @@ -1,112 +1,112 @@ -/*
- * 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.tools.ant.listener;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildEvent;
-import org.apache.tools.ant.DefaultLogger;
-import org.apache.tools.ant.util.StringUtils;
-
-/**
- * This is a special logger that is designed to profile builds.
- *
- * @since Ant1.8
- */
-public class ProfileLogger extends DefaultLogger {
-
- private Map profileData = new HashMap(); // <Object, Date>
-
- /**
- * Logs a message to say that the target has started.
- *
- * @param event
- * An event with any relevant extra information. Must not be
- * <code>null</code>.
- */
- public void targetStarted(BuildEvent event) {
- Date now = new Date();
- String name = "Target " + event.getTarget().getName();
- logStart(event, now, name);
- profileData.put(event.getTarget(), now);
- }
-
- /**
- * Logs a message to say that the target has finished.
- *
- * @param event
- * An event with any relevant extra information. Must not be
- * <code>null</code>.
- */
- public void targetFinished(BuildEvent event) {
- Date start = (Date) profileData.remove(event.getTarget());
- String name = "Target " + event.getTarget().getName();
- logFinish(event, start, name);
- }
-
- /**
- * Logs a message to say that the task has started.
- *
- * @param event
- * An event with any relevant extra information. Must not be
- * <code>null</code>.
- */
- public void taskStarted(BuildEvent event) {
- String name = event.getTask().getTaskName();
- Date now = new Date();
- logStart(event, now, name);
- profileData.put(event.getTask(), now);
- }
-
- /**
- * Logs a message to say that the task has finished.
- *
- * @param event
- * An event with any relevant extra information. Must not be
- * <code>null</code>.
- */
- public void taskFinished(BuildEvent event) {
- Date start = (Date) profileData.remove(event.getTask());
- String name = event.getTask().getTaskName();
- logFinish(event, start, name);
- }
-
- private void logFinish(BuildEvent event, Date start, String name) {
- Date now = new Date();
- String msg = null;
- if (start != null) {
- long diff = now.getTime() - start.getTime();
- msg = StringUtils.LINE_SEP + name + ": finished" + now + " ("
- + diff + "ms)";
- } else {
- msg = StringUtils.LINE_SEP + name + ": finished" + now
- + " (unknown duration, start not detected)";
- }
- printMessage(msg, out, event.getPriority());
- log(msg);
- }
-
- private void logStart(BuildEvent event, Date start, String name) {
- String msg = StringUtils.LINE_SEP + name + ": started " + start;
- printMessage(msg, out, event.getPriority());
- log(msg);
- }
-
-}
+/* + * 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.tools.ant.listener; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.util.StringUtils; + +/** + * This is a special logger that is designed to profile builds. + * + * @since Ant1.8 + */ +public class ProfileLogger extends DefaultLogger { + + private Map profileData = new HashMap(); // <Object, Date> + + /** + * Logs a message to say that the target has started. + * + * @param event + * An event with any relevant extra information. Must not be + * <code>null</code>. + */ + public void targetStarted(BuildEvent event) { + Date now = new Date(); + String name = "Target " + event.getTarget().getName(); + logStart(event, now, name); + profileData.put(event.getTarget(), now); + } + + /** + * Logs a message to say that the target has finished. + * + * @param event + * An event with any relevant extra information. Must not be + * <code>null</code>. + */ + public void targetFinished(BuildEvent event) { + Date start = (Date) profileData.remove(event.getTarget()); + String name = "Target " + event.getTarget().getName(); + logFinish(event, start, name); + } + + /** + * Logs a message to say that the task has started. + * + * @param event + * An event with any relevant extra information. Must not be + * <code>null</code>. + */ + public void taskStarted(BuildEvent event) { + String name = event.getTask().getTaskName(); + Date now = new Date(); + logStart(event, now, name); + profileData.put(event.getTask(), now); + } + + /** + * Logs a message to say that the task has finished. + * + * @param event + * An event with any relevant extra information. Must not be + * <code>null</code>. + */ + public void taskFinished(BuildEvent event) { + Date start = (Date) profileData.remove(event.getTask()); + String name = event.getTask().getTaskName(); + logFinish(event, start, name); + } + + private void logFinish(BuildEvent event, Date start, String name) { + Date now = new Date(); + String msg = null; + if (start != null) { + long diff = now.getTime() - start.getTime(); + msg = StringUtils.LINE_SEP + name + ": finished" + now + " (" + + diff + "ms)"; + } else { + msg = StringUtils.LINE_SEP + name + ": finished" + now + + " (unknown duration, start not detected)"; + } + printMessage(msg, out, event.getPriority()); + log(msg); + } + + private void logStart(BuildEvent event, Date start, String name) { + String msg = StringUtils.LINE_SEP + name + ": started " + start; + printMessage(msg, out, event.getPriority()); + log(msg); + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/HostInfo.java b/src/main/org/apache/tools/ant/taskdefs/HostInfo.java index 3aca2f748..1b1b03019 100644 --- a/src/main/org/apache/tools/ant/taskdefs/HostInfo.java +++ b/src/main/org/apache/tools/ant/taskdefs/HostInfo.java @@ -1,247 +1,247 @@ -/*
- * 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.tools.ant.taskdefs;
-
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-/**
- * Sets properties to the host provided, or localhost if no information is
- * provided. The default properties are NAME, FQDN, ADDR4, ADDR6;
- *
- * @since Ant 1.8
- * @ant.task category="utility"
- */
-
-
-public class HostInfo extends Task {
- private static final String DEF_REM_ADDR6 = "::";
-
- private static final String DEF_REM_ADDR4 = "0.0.0.0";
-
- private static final String DEF_LOCAL_ADDR6 = "::1";
-
- private static final String DEF_LOCAL_ADDR4 = "127.0.0.1";
-
- private static final String DEF_LOCAL_NAME = "localhost";
- private static final String DEF_DOMAIN = "localdomain";
-
- private static final String DOMAIN = "DOMAIN";
-
- private static final String NAME = "NAME";
-
- private static final String ADDR4 = "ADDR4";
-
- private static final String ADDR6 = "ADDR6";
-
- private String prefix = "";
-
- private String host;
-
- private InetAddress nameAddr;
-
- private InetAddress best6;
-
- private InetAddress best4;
-
- private List inetAddrs;
-
- /**
- * Set a prefix for the properties. If the prefix does not end with a "."
- * one is automatically added.
- *
- * @param aPrefix
- * the prefix to use.
- * @since Ant 1.8
- */
- public void setPrefix(String aPrefix) {
- prefix = aPrefix;
- if (!prefix.endsWith(".")) {
- prefix += ".";
- }
- }
-
- /**
- * Set the host to be retrieved.
- *
- * @param aHost
- * the name or the address of the host, data for the local host
- * will be retrieved if ommited.
- * @since Ant 1.8
- */
- public void setHost(String aHost) {
- host = aHost;
- }
-
- /**
- * set the properties.
- *
- * @throws BuildException
- * on error.
- */
- public void execute() throws BuildException {
- if (host == null || "".equals(host)) {
- executeLocal();
- } else {
- executeRemote();
- }
- }
-
- private void executeLocal() {
- try {
- Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
- inetAddrs = new LinkedList();
- while (interfaces.hasMoreElements()) {
- NetworkInterface currentif = (NetworkInterface) interfaces
- .nextElement();
- Enumeration addrs = currentif.getInetAddresses();
- while (addrs.hasMoreElements())
- {
- inetAddrs.add(addrs.nextElement());
- }
- }
- selectAddresses();
-
- if (nameAddr != null) {
- setDomainAndName(nameAddr.getCanonicalHostName());
- } else {
- setProperty(DOMAIN, DEF_DOMAIN);
- setProperty(NAME, DEF_LOCAL_NAME);
- }
- if (best4 != null) {
- setProperty(ADDR4, best4.getHostAddress());
- } else {
- setProperty(ADDR4, DEF_LOCAL_ADDR4);
- }
- if (best6 != null) {
- setProperty(ADDR6, best6.getHostAddress());
- } else {
- setProperty(ADDR6, DEF_LOCAL_ADDR6);
- }
- } catch (Exception e) {
- log("Error retrieving local host information", e, Project.MSG_WARN);
- setProperty(DOMAIN, DEF_DOMAIN);
- setProperty(NAME, DEF_LOCAL_NAME);
- setProperty(ADDR4, DEF_LOCAL_ADDR4);
- setProperty(ADDR6, DEF_LOCAL_ADDR6);
- }
- }
-
- private void selectAddresses() {
- Iterator i = inetAddrs.iterator();
- while (i.hasNext()) {
- InetAddress current = (InetAddress) i.next();
- if (!current.isMulticastAddress()) {
- if (current instanceof Inet4Address) {
- best4 = selectBestAddress(best4, current);
- } else if (current instanceof Inet6Address) {
- best6 = selectBestAddress(best6, current);
- }
- }
- }
-
- nameAddr = selectBestAddress(best6, best4);
- }
-
- private InetAddress selectBestAddress(InetAddress bestSoFar,
- InetAddress current) {
- InetAddress best = bestSoFar;
- if (best == null) {
- // none selected so far, so this one is better.
- best = current;
- } else {
- if (current.isLoopbackAddress()) {
- // definitely not better than the previously selected address.
- } else if (current.isLinkLocalAddress()) {
- // link local considered better than loopback
- if (best.isLoopbackAddress()) {
- best = current;
- }
- } else if (current.isSiteLocalAddress()) {
- // site local considered better than link local (and loopback)
- if (best.isLoopbackAddress() || best.isLinkLocalAddress()) {
- best = current;
- }
- } else {
- // current is a global address, and therefore best (at least
- // equally well)
- best = current;
- }
- }
- return best;
- }
-
- private void executeRemote() {
- try {
- inetAddrs = Arrays.asList(InetAddress.getAllByName(host));
-
- selectAddresses();
-
- if (nameAddr != null) {
- setDomainAndName(nameAddr.getCanonicalHostName());
- } else {
- setDomainAndName(host);
- }
- if (best4 != null) {
- setProperty(ADDR4, best4.getHostAddress());
- } else {
- setProperty(ADDR4, DEF_REM_ADDR4);
- }
- if (best6 != null) {
- setProperty(ADDR6, best6.getHostAddress());
- } else {
- setProperty(ADDR6, DEF_REM_ADDR6);
- }
- } catch (Exception e) {
- log("Error retrieving remote host information for host:" + host
- + ".", e, Project.MSG_WARN);
- setDomainAndName(host);
- setProperty(ADDR4, DEF_REM_ADDR4);
- setProperty(ADDR6, DEF_REM_ADDR6);
- }
- }
-
- private void setDomainAndName(String fqdn)
- {
- int idx = fqdn.indexOf('.');
- if (idx > 0) {
- setProperty(NAME, fqdn.substring(0, idx));
- setProperty(DOMAIN, fqdn.substring(idx+1));
- } else {
- setProperty(NAME, fqdn);
- setProperty(DOMAIN, DEF_DOMAIN);
- }
- }
-
- private void setProperty(String name, String value) {
- getProject().setNewProperty(prefix + name, value);
- }
-
-}
+/* + * 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.tools.ant.taskdefs; + +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +/** + * Sets properties to the host provided, or localhost if no information is + * provided. The default properties are NAME, FQDN, ADDR4, ADDR6; + * + * @since Ant 1.8 + * @ant.task category="utility" + */ + + +public class HostInfo extends Task { + private static final String DEF_REM_ADDR6 = "::"; + + private static final String DEF_REM_ADDR4 = "0.0.0.0"; + + private static final String DEF_LOCAL_ADDR6 = "::1"; + + private static final String DEF_LOCAL_ADDR4 = "127.0.0.1"; + + private static final String DEF_LOCAL_NAME = "localhost"; + private static final String DEF_DOMAIN = "localdomain"; + + private static final String DOMAIN = "DOMAIN"; + + private static final String NAME = "NAME"; + + private static final String ADDR4 = "ADDR4"; + + private static final String ADDR6 = "ADDR6"; + + private String prefix = ""; + + private String host; + + private InetAddress nameAddr; + + private InetAddress best6; + + private InetAddress best4; + + private List inetAddrs; + + /** + * Set a prefix for the properties. If the prefix does not end with a "." + * one is automatically added. + * + * @param aPrefix + * the prefix to use. + * @since Ant 1.8 + */ + public void setPrefix(String aPrefix) { + prefix = aPrefix; + if (!prefix.endsWith(".")) { + prefix += "."; + } + } + + /** + * Set the host to be retrieved. + * + * @param aHost + * the name or the address of the host, data for the local host + * will be retrieved if ommited. + * @since Ant 1.8 + */ + public void setHost(String aHost) { + host = aHost; + } + + /** + * set the properties. + * + * @throws BuildException + * on error. + */ + public void execute() throws BuildException { + if (host == null || "".equals(host)) { + executeLocal(); + } else { + executeRemote(); + } + } + + private void executeLocal() { + try { + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + inetAddrs = new LinkedList(); + while (interfaces.hasMoreElements()) { + NetworkInterface currentif = (NetworkInterface) interfaces + .nextElement(); + Enumeration addrs = currentif.getInetAddresses(); + while (addrs.hasMoreElements()) + { + inetAddrs.add(addrs.nextElement()); + } + } + selectAddresses(); + + if (nameAddr != null) { + setDomainAndName(nameAddr.getCanonicalHostName()); + } else { + setProperty(DOMAIN, DEF_DOMAIN); + setProperty(NAME, DEF_LOCAL_NAME); + } + if (best4 != null) { + setProperty(ADDR4, best4.getHostAddress()); + } else { + setProperty(ADDR4, DEF_LOCAL_ADDR4); + } + if (best6 != null) { + setProperty(ADDR6, best6.getHostAddress()); + } else { + setProperty(ADDR6, DEF_LOCAL_ADDR6); + } + } catch (Exception e) { + log("Error retrieving local host information", e, Project.MSG_WARN); + setProperty(DOMAIN, DEF_DOMAIN); + setProperty(NAME, DEF_LOCAL_NAME); + setProperty(ADDR4, DEF_LOCAL_ADDR4); + setProperty(ADDR6, DEF_LOCAL_ADDR6); + } + } + + private void selectAddresses() { + Iterator i = inetAddrs.iterator(); + while (i.hasNext()) { + InetAddress current = (InetAddress) i.next(); + if (!current.isMulticastAddress()) { + if (current instanceof Inet4Address) { + best4 = selectBestAddress(best4, current); + } else if (current instanceof Inet6Address) { + best6 = selectBestAddress(best6, current); + } + } + } + + nameAddr = selectBestAddress(best6, best4); + } + + private InetAddress selectBestAddress(InetAddress bestSoFar, + InetAddress current) { + InetAddress best = bestSoFar; + if (best == null) { + // none selected so far, so this one is better. + best = current; + } else { + if (current.isLoopbackAddress()) { + // definitely not better than the previously selected address. + } else if (current.isLinkLocalAddress()) { + // link local considered better than loopback + if (best.isLoopbackAddress()) { + best = current; + } + } else if (current.isSiteLocalAddress()) { + // site local considered better than link local (and loopback) + if (best.isLoopbackAddress() || best.isLinkLocalAddress()) { + best = current; + } + } else { + // current is a global address, and therefore best (at least + // equally well) + best = current; + } + } + return best; + } + + private void executeRemote() { + try { + inetAddrs = Arrays.asList(InetAddress.getAllByName(host)); + + selectAddresses(); + + if (nameAddr != null) { + setDomainAndName(nameAddr.getCanonicalHostName()); + } else { + setDomainAndName(host); + } + if (best4 != null) { + setProperty(ADDR4, best4.getHostAddress()); + } else { + setProperty(ADDR4, DEF_REM_ADDR4); + } + if (best6 != null) { + setProperty(ADDR6, best6.getHostAddress()); + } else { + setProperty(ADDR6, DEF_REM_ADDR6); + } + } catch (Exception e) { + log("Error retrieving remote host information for host:" + host + + ".", e, Project.MSG_WARN); + setDomainAndName(host); + setProperty(ADDR4, DEF_REM_ADDR4); + setProperty(ADDR6, DEF_REM_ADDR6); + } + } + + private void setDomainAndName(String fqdn) + { + int idx = fqdn.indexOf('.'); + if (idx > 0) { + setProperty(NAME, fqdn.substring(0, idx)); + setProperty(DOMAIN, fqdn.substring(idx+1)); + } else { + setProperty(NAME, fqdn); + setProperty(DOMAIN, DEF_DOMAIN); + } + } + + private void setProperty(String name, String value) { + getProject().setNewProperty(prefix + name, value); + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/Retry.java b/src/main/org/apache/tools/ant/taskdefs/Retry.java index 200259e16..ece55a025 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Retry.java +++ b/src/main/org/apache/tools/ant/taskdefs/Retry.java @@ -1,89 +1,89 @@ -/*
- * 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.tools.ant.taskdefs;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.TaskContainer;
-import org.apache.tools.ant.util.StringUtils;
-
-/**
- * Retries the nested task a set number of times
- * @since Ant 1.7.1
- */
-public class Retry extends Task implements TaskContainer {
-
- /**
- * task to execute n times
- */
- private Task nestedTask;
-
- /**
- * set retryCount to 1 by default
- */
- private int retryCount = 1;
-
- /**
- * set the task
- * @param t the task to retry.
- */
- public synchronized void addTask(Task t) {
- if (nestedTask != null) {
- throw new BuildException(
- "The retry task container accepts a single nested task"
- + " (which may be a sequential task container)");
- }
- nestedTask = t;
- }
-
- /**
- * set the number of times to retry the task
- * @param n the number to use.
- */
- public void setRetryCount(int n) {
- retryCount = n;
- }
-
- /**
- * perform the work
- * @throws BuildException if there is an error.
- */
- public void execute() throws BuildException {
- StringBuffer errorMessages = new StringBuffer();
- for (int i = 0; i <= retryCount; i++) {
- try {
- nestedTask.perform();
- break;
- } catch (Exception e) {
- errorMessages.append(e.getMessage());
- if (i >= retryCount) {
- StringBuffer exceptionMessage = new StringBuffer();
- exceptionMessage.append("Task [").append(nestedTask.getTaskName());
- exceptionMessage.append("] failed after [").append(retryCount);
- exceptionMessage.append("] attempts; giving up.").append(StringUtils.LINE_SEP);
- exceptionMessage.append("Error messages:").append(StringUtils.LINE_SEP);
- exceptionMessage.append(errorMessages);
- throw new BuildException(exceptionMessage.toString(), getLocation());
- }
- log("Attempt [" + i + "]: error occurred; retrying...", e, Project.MSG_INFO);
- errorMessages.append(StringUtils.LINE_SEP);
- }
- }
- }
+/* + * 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.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.TaskContainer; +import org.apache.tools.ant.util.StringUtils; + +/** + * Retries the nested task a set number of times + * @since Ant 1.7.1 + */ +public class Retry extends Task implements TaskContainer { + + /** + * task to execute n times + */ + private Task nestedTask; + + /** + * set retryCount to 1 by default + */ + private int retryCount = 1; + + /** + * set the task + * @param t the task to retry. + */ + public synchronized void addTask(Task t) { + if (nestedTask != null) { + throw new BuildException( + "The retry task container accepts a single nested task" + + " (which may be a sequential task container)"); + } + nestedTask = t; + } + + /** + * set the number of times to retry the task + * @param n the number to use. + */ + public void setRetryCount(int n) { + retryCount = n; + } + + /** + * perform the work + * @throws BuildException if there is an error. + */ + public void execute() throws BuildException { + StringBuffer errorMessages = new StringBuffer(); + for (int i = 0; i <= retryCount; i++) { + try { + nestedTask.perform(); + break; + } catch (Exception e) { + errorMessages.append(e.getMessage()); + if (i >= retryCount) { + StringBuffer exceptionMessage = new StringBuffer(); + exceptionMessage.append("Task [").append(nestedTask.getTaskName()); + exceptionMessage.append("] failed after [").append(retryCount); + exceptionMessage.append("] attempts; giving up.").append(StringUtils.LINE_SEP); + exceptionMessage.append("Error messages:").append(StringUtils.LINE_SEP); + exceptionMessage.append(errorMessages); + throw new BuildException(exceptionMessage.toString(), getLocation()); + } + log("Attempt [" + i + "]: error occurred; retrying...", e, Project.MSG_INFO); + errorMessages.append(StringUtils.LINE_SEP); + } + } + } }
\ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java b/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java index 7afe87f26..420c18946 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/HasFreeSpace.java @@ -1,101 +1,101 @@ -/*
- * 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.tools.ant.taskdefs.condition;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.util.JavaEnvUtils;
-import org.apache.tools.ant.util.ReflectWrapper;
-import org.apache.tools.ant.util.StringUtils;
-
-/**
- * <hasfreespace>
- * <p>Condition returns true if selected partition
- * has the requested space, false otherwise.</p>
- * @since Ant 1.7
- */
-public class HasFreeSpace implements Condition {
-
- private String partition;
- private String needed;
-
- /**
- * Evaluate the condition.
- * @return true if there enough free space.
- * @throws BuildException if there is a problem.
- */
- public boolean eval() throws BuildException {
- validate();
- try {
- if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) {
- //reflection to avoid bootstrap/build problems
- File fs = new File(partition);
- ReflectWrapper w = new ReflectWrapper(fs);
- long free = ((Long) w.invoke("getFreeSpace")).longValue();
- return free >= StringUtils.parseHumanSizes(needed);
- } else {
- throw new BuildException("HasFreeSpace condition not supported on Java5 or less.");
- }
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
-
- private void validate() throws BuildException {
- if (null == partition) {
- throw new BuildException("Please set the partition attribute.");
- }
- if (null == needed) {
- throw new BuildException("Please set the needed attribute.");
- }
- }
-
- /**
- * The partition/device to check
- * @return the partition.
- */
- public String getPartition() {
- return partition;
- }
-
- /**
- * Set the partition name.
- * @param partition the name to use.
- */
- public void setPartition(String partition) {
- this.partition = partition;
- }
-
- /**
- * The amount of free space required
- * @return the amount required
- */
- public String getNeeded() {
- return needed;
- }
-
- /**
- * Set the amount of space required.
- * @param needed the amount required.
- */
- public void setNeeded(String needed) {
- this.needed = needed;
- }
-}
+/* + * 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.tools.ant.taskdefs.condition; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.apache.tools.ant.util.ReflectWrapper; +import org.apache.tools.ant.util.StringUtils; + +/** + * <hasfreespace> + * <p>Condition returns true if selected partition + * has the requested space, false otherwise.</p> + * @since Ant 1.7 + */ +public class HasFreeSpace implements Condition { + + private String partition; + private String needed; + + /** + * Evaluate the condition. + * @return true if there enough free space. + * @throws BuildException if there is a problem. + */ + public boolean eval() throws BuildException { + validate(); + try { + if (JavaEnvUtils.isAtLeastJavaVersion("1.6")) { + //reflection to avoid bootstrap/build problems + File fs = new File(partition); + ReflectWrapper w = new ReflectWrapper(fs); + long free = ((Long) w.invoke("getFreeSpace")).longValue(); + return free >= StringUtils.parseHumanSizes(needed); + } else { + throw new BuildException("HasFreeSpace condition not supported on Java5 or less."); + } + } catch (Exception e) { + throw new BuildException(e); + } + } + + private void validate() throws BuildException { + if (null == partition) { + throw new BuildException("Please set the partition attribute."); + } + if (null == needed) { + throw new BuildException("Please set the needed attribute."); + } + } + + /** + * The partition/device to check + * @return the partition. + */ + public String getPartition() { + return partition; + } + + /** + * Set the partition name. + * @param partition the name to use. + */ + public void setPartition(String partition) { + this.partition = partition; + } + + /** + * The amount of free space required + * @return the amount required + */ + public String getNeeded() { + return needed; + } + + /** + * Set the amount of space required. + * @param needed the amount required. + */ + public void setNeeded(String needed) { + this.needed = needed; + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/ResourceContains.java b/src/main/org/apache/tools/ant/taskdefs/condition/ResourceContains.java index f636ad063..76a9ad35d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/ResourceContains.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/ResourceContains.java @@ -1,165 +1,165 @@ -/*
- * 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.tools.ant.taskdefs.condition;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceCollection;
-import org.apache.tools.ant.types.resources.FileResource;
-import org.apache.tools.ant.util.FileUtils;
-
-/**
- * <resourcecontains>
- * Is a string contained in a resource (file currently)?
- * @since Ant 1.7.1
- */
-public class ResourceContains implements Condition {
-
- private Project project;
- private String substring;
- private Resource resource;
- private String refid;
- private boolean casesensitive = true;
-
- /**
- * Set this condition's Project.
- * @param project Project
- */
- public void setProject(Project project) {
- this.project = project;
- }
-
- /**
- * Get this condition's Project.
- * @return Project
- */
- public Project getProject() {
- return project;
- }
-
- /**
- * Sets the resource to search
- * @param r the value to use.
- */
- public void setResource(String r) {
- this.resource = new FileResource(new File(r));
- }
-
- /**
- * Sets the refid to search; should indicate a resource directly
- * or by way of a single-element ResourceCollection.
- * @param refid the value to use.
- */
- public void setRefid(String refid) {
- this.refid = refid;
- }
-
- private void resolveRefid() {
- try {
- if (getProject() == null) {
- throw new BuildException("Cannot retrieve refid; project unset");
- }
- Object o = getProject().getReference(refid);
- if (!(o instanceof Resource)) {
- if (o instanceof ResourceCollection) {
- ResourceCollection rc = (ResourceCollection) o;
- if (rc.size() == 1) {
- o = rc.iterator().next();
- }
- } else {
- throw new BuildException(
- "Illegal value at '" + refid + "': " + String.valueOf(o));
- }
- }
- this.resource = (Resource) o;
- } finally {
- refid = null;
- }
- }
-
- /**
- * Sets the substring to look for
- * @param substring the value to use.
- */
- public void setSubstring(String substring) {
- this.substring = substring;
- }
-
- /**
- * Sets case sensitivity attribute.
- * @param casesensitive the value to use.
- */
- public void setCasesensitive(boolean casesensitive) {
- this.casesensitive = casesensitive;
- }
-
- private void validate() {
- if (resource != null && refid != null) {
- throw new BuildException("Cannot set both resource and refid");
- }
- if (resource == null && refid != null) {
- resolveRefid();
- }
- if (resource == null || substring == null) {
- throw new BuildException("both resource and substring are required "
- + "in <resourcecontains>");
- }
- }
-
- /**
- * Evaluates the condition.
- * @return true if the substring is contained in the resource
- * @throws BuildException if there is a problem.
- */
- public synchronized boolean eval() throws BuildException {
- validate();
-
- if (substring.length() == 0) {
- if (getProject() != null) {
- getProject().log("Substring is empty; returning true",
- Project.MSG_VERBOSE);
- }
- return true;
- }
- if (resource.getSize() == 0) {
- return false;
- }
-
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
- String contents = FileUtils.safeReadFully(reader);
- String sub = substring;
- if (!casesensitive) {
- contents = contents.toLowerCase();
- sub = sub.toLowerCase();
- }
- return contents.indexOf(sub) >= 0;
- } catch (IOException e) {
- throw new BuildException("There was a problem accessing resource : " + resource);
- } finally {
- FileUtils.close(reader);
- }
- }
-}
+/* + * 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.tools.ant.taskdefs.condition; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.util.FileUtils; + +/** + * <resourcecontains> + * Is a string contained in a resource (file currently)? + * @since Ant 1.7.1 + */ +public class ResourceContains implements Condition { + + private Project project; + private String substring; + private Resource resource; + private String refid; + private boolean casesensitive = true; + + /** + * Set this condition's Project. + * @param project Project + */ + public void setProject(Project project) { + this.project = project; + } + + /** + * Get this condition's Project. + * @return Project + */ + public Project getProject() { + return project; + } + + /** + * Sets the resource to search + * @param r the value to use. + */ + public void setResource(String r) { + this.resource = new FileResource(new File(r)); + } + + /** + * Sets the refid to search; should indicate a resource directly + * or by way of a single-element ResourceCollection. + * @param refid the value to use. + */ + public void setRefid(String refid) { + this.refid = refid; + } + + private void resolveRefid() { + try { + if (getProject() == null) { + throw new BuildException("Cannot retrieve refid; project unset"); + } + Object o = getProject().getReference(refid); + if (!(o instanceof Resource)) { + if (o instanceof ResourceCollection) { + ResourceCollection rc = (ResourceCollection) o; + if (rc.size() == 1) { + o = rc.iterator().next(); + } + } else { + throw new BuildException( + "Illegal value at '" + refid + "': " + String.valueOf(o)); + } + } + this.resource = (Resource) o; + } finally { + refid = null; + } + } + + /** + * Sets the substring to look for + * @param substring the value to use. + */ + public void setSubstring(String substring) { + this.substring = substring; + } + + /** + * Sets case sensitivity attribute. + * @param casesensitive the value to use. + */ + public void setCasesensitive(boolean casesensitive) { + this.casesensitive = casesensitive; + } + + private void validate() { + if (resource != null && refid != null) { + throw new BuildException("Cannot set both resource and refid"); + } + if (resource == null && refid != null) { + resolveRefid(); + } + if (resource == null || substring == null) { + throw new BuildException("both resource and substring are required " + + "in <resourcecontains>"); + } + } + + /** + * Evaluates the condition. + * @return true if the substring is contained in the resource + * @throws BuildException if there is a problem. + */ + public synchronized boolean eval() throws BuildException { + validate(); + + if (substring.length() == 0) { + if (getProject() != null) { + getProject().log("Substring is empty; returning true", + Project.MSG_VERBOSE); + } + return true; + } + if (resource.getSize() == 0) { + return false; + } + + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(resource.getInputStream())); + String contents = FileUtils.safeReadFully(reader); + String sub = substring; + if (!casesensitive) { + contents = contents.toLowerCase(); + sub = sub.toLowerCase(); + } + return contents.indexOf(sub) >= 0; + } catch (IOException e) { + throw new BuildException("There was a problem accessing resource : " + resource); + } finally { + FileUtils.close(reader); + } + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java index cf40922de..36dcddbb6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java @@ -1,425 +1,425 @@ -/*
- * 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.tools.ant.taskdefs.optional.junit;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.Vector;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-
-import org.apache.tools.ant.BuildEvent;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildListener;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.util.FileUtils;
-
-/**
- * <p>Collects all failing test <i>cases</i> and creates a new JUnit test class containing
- * a suite() method which calls these failed tests.</p>
- * <p>Having classes <i>A</i> ... <i>D</i> with each several testcases you could earn a new
- * test class like
- * <pre>
- * // generated on: 2007.08.06 09:42:34,555
- * import junit.framework.*;
- * public class FailedTests extends TestCase {
- * public FailedTests(String testname) {
- * super(testname);
- * }
- * public static Test suite() {
- * TestSuite suite = new TestSuite();
- * suite.addTest( new B("test04") );
- * suite.addTest( new org.D("test10") );
- * return suite;
- * }
- * }
- * </pre>
- *
- * Because each running test case gets its own formatter, we collect
- * the failing test cases in a static list. Because we dont have a finalizer
- * method in the formatters "lifecycle", we register this formatter as
- * BuildListener and generate the new java source on taskFinished event.
- *
- * @since Ant 1.8.0
- */
-public class FailureRecorder extends ProjectComponent implements JUnitResultFormatter, BuildListener {
-
- /**
- * This is the name of a magic System property ({@value}). The value of this
- * <b>System</b> property should point to the location where to store the
- * generated class (without suffix).
- * Default location and name is defined in DEFAULT_CLASS_LOCATION.
- * @see #DEFAULT_CLASS_LOCATION
- */
- public static final String MAGIC_PROPERTY_CLASS_LOCATION
- = "ant.junit.failureCollector";
-
- /** Default location and name for the generated JUnit class file. {@value} */
- public static final String DEFAULT_CLASS_LOCATION
- = System.getProperty("java.io.tmpdir") + "FailedTests";
-
- /** Prefix for logging. {@value} */
- private static final String LOG_PREFIX = " [junit]";
-
- /** Class names of failed tests without duplicates. */
- private static SortedSet/*<TestInfos>*/ failedTests = new TreeSet();
-
- /** A writer for writing the generated source to. */
- private PrintWriter writer;
-
- /**
- * Location and name of the generated JUnit class.
- * Lazy instantiated via getLocationName().
- */
- private static String locationName;
-
- /**
- * Returns the (lazy evaluated) location for the collector class.
- * Order for evaluation: System property > Ant property > default value
- * @return location for the collector class
- * @see #MAGIC_PROPERTY_CLASS_LOCATION
- * @see #DEFAULT_CLASS_LOCATION
- */
- private String getLocationName() {
- if (locationName == null) {
- String syspropValue = System.getProperty(MAGIC_PROPERTY_CLASS_LOCATION);
- String antpropValue = getProject().getProperty(MAGIC_PROPERTY_CLASS_LOCATION);
-
- if (syspropValue != null) {
- locationName = syspropValue;
- verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' set, so use "
- + "its value '" + syspropValue + "' as location for collector class.");
- } else if (antpropValue != null) {
- locationName = antpropValue;
- verbose("Ant property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' set, so use "
- + "its value '" + antpropValue + "' as location for collector class.");
- } else {
- locationName = DEFAULT_CLASS_LOCATION;
- verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' not set, so use "
- + "value as location for collector class: '"
- + DEFAULT_CLASS_LOCATION + "'");
- }
-
- File locationFile = new File(locationName);
- if (!locationFile.isAbsolute()) {
- File f = new File(getProject().getBaseDir(), locationName);
- locationName = f.getAbsolutePath();
- verbose("Location file is relative (" + locationFile + ")"
- + " use absolute path instead (" + locationName + ")");
- }
- }
-
- return locationName;
- }
-
- /**
- * This method is called by the Ant runtime by reflection. We use the project reference for
- * registration of this class as BuildListener.
- *
- * @param project
- * project reference
- */
- public void setProject(Project project) {
- // store project reference for logging
- super.setProject(project);
- // check if already registered
- boolean alreadyRegistered = false;
- Vector allListeners = project.getBuildListeners();
- for (int i = 0; i < allListeners.size(); i++) {
- Object listener = allListeners.get(i);
- if (listener instanceof FailureRecorder) {
- alreadyRegistered = true;
- continue;
- }
- }
- // register if needed
- if (!alreadyRegistered) {
- verbose("Register FailureRecorder (@" + this.hashCode() + ") as BuildListener");
- project.addBuildListener(this);
- }
- }
-
- // ===== JUnitResultFormatter =====
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void endTestSuite(JUnitTest suite) throws BuildException {
- }
-
- /**
- * Add the failed test to the list.
- * @param test the test that errored.
- * @param throwable the reason it errored.
- * @see junit.framework.TestListener#addError(junit.framework.Test, java.lang.Throwable)
- */
- public void addError(Test test, Throwable throwable) {
- failedTests.add(new TestInfos(test));
- }
-
- // CheckStyle:LineLengthCheck OFF - @see is long
- /**
- * Add the failed test to the list.
- * @param test the test that failed.
- * @param error the assertion that failed.
- * @see junit.framework.TestListener#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
- */
- // CheckStyle:LineLengthCheck ON
- public void addFailure(Test test, AssertionFailedError error) {
- failedTests.add(new TestInfos(test));
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void setOutput(OutputStream out) {
- // unused, close output file so it can be deleted before the VM exits
- if (out != System.out) {
- FileUtils.close(out);
- }
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void setSystemError(String err) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void setSystemOutput(String out) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void startTestSuite(JUnitTest suite) throws BuildException {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void endTest(Test test) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void startTest(Test test) {
- }
-
- // ===== "Templates" for generating the JUnit class =====
-
- private void writeJavaClass() {
- try {
- File sourceFile = new File((getLocationName() + ".java"));
- verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");
-
- sourceFile.delete();
- writer = new PrintWriter(new FileOutputStream(sourceFile));
-
- createClassHeader();
- createSuiteMethod();
- createClassFooter();
-
- FileUtils.close(writer);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
-
- private void createClassHeader() {
- String className = getLocationName().replace('\\', '/');
- if (className.indexOf('/') > -1) {
- className = className.substring(className.lastIndexOf('/') + 1);
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss,SSS");
- writer.print("// generated on: ");
- writer.println(sdf.format(new Date()));
- writer.println("import junit.framework.*;");
- writer.print("public class ");
- writer.print(className);
- // If this class does not extend TC, Ant doesnt run these
- writer.println(" extends TestCase {");
- // standard String-constructor
- writer.print(" public ");
- writer.print(className);
- writer.println("(String testname) {");
- writer.println(" super(testname);");
- writer.println(" }");
- }
-
- private void createSuiteMethod() {
- writer.println(" public static Test suite() {");
- writer.println(" TestSuite suite = new TestSuite();");
- for (Iterator iter = failedTests.iterator(); iter.hasNext();) {
- TestInfos testInfos = (TestInfos) iter.next();
- writer.print(" suite.addTest(");
- writer.print(testInfos);
- writer.println(");");
- }
- writer.println(" return suite;");
- writer.println(" }");
- }
-
- private void createClassFooter() {
- writer.println("}");
- }
-
- // ===== Helper classes and methods =====
-
- /**
- * Logging facade in INFO-mode.
- * @param message Log-message
- */
- public void log(String message) {
- getProject().log(LOG_PREFIX + " " + message, Project.MSG_INFO);
- }
-
- /**
- * Logging facade in VERBOSE-mode.
- * @param message Log-message
- */
- public void verbose(String message) {
- getProject().log(LOG_PREFIX + " " + message, Project.MSG_VERBOSE);
- }
-
- /**
- * TestInfos holds information about a given test for later use.
- */
- public class TestInfos implements Comparable {
-
- /** The class name of the test. */
- private String className;
-
- /** The method name of the testcase. */
- private String methodName;
-
- /**
- * This constructor extracts the needed information from the given test.
- * @param test Test to analyze
- */
- public TestInfos(Test test) {
- className = test.getClass().getName();
- methodName = test.toString();
- methodName = methodName.substring(0, methodName.indexOf('('));
- }
-
- /**
- * This String-Representation can directly be used for instantiation of
- * the JUnit testcase.
- * @return the string representation.
- * @see java.lang.Object#toString()
- * @see FailureRecorder#createSuiteMethod()
- */
- public String toString() {
- return "new " + className + "(\"" + methodName + "\")";
- }
-
- /**
- * The SortedMap needs comparable elements.
- * @param other the object to compare to.
- * @return the result of the comparison.
- * @see java.lang.Comparable#compareTo(T)
- * @see SortedSet#comparator()
- */
- public int compareTo(Object other) {
- if (other instanceof TestInfos) {
- TestInfos otherInfos = (TestInfos) other;
- return toString().compareTo(otherInfos.toString());
- } else {
- return -1;
- }
- }
- }
-
- // ===== BuildListener =====
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void buildFinished(BuildEvent event) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void buildStarted(BuildEvent event) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void messageLogged(BuildEvent event) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void targetFinished(BuildEvent event) {
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void targetStarted(BuildEvent event) {
- }
-
- /**
- * The task outside of this JUnitResultFormatter is the <junit> task. So all tests passed
- * and we could create the new java class.
- * @param event not used
- * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
- */
- public void taskFinished(BuildEvent event) {
- if (!failedTests.isEmpty()) {
- writeJavaClass();
- }
- }
-
- /**
- * Not used
- * {@inheritDoc}
- */
- public void taskStarted(BuildEvent event) {
- }
-
-}
+/* + * 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.tools.ant.taskdefs.optional.junit; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.Vector; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectComponent; +import org.apache.tools.ant.util.FileUtils; + +/** + * <p>Collects all failing test <i>cases</i> and creates a new JUnit test class containing + * a suite() method which calls these failed tests.</p> + * <p>Having classes <i>A</i> ... <i>D</i> with each several testcases you could earn a new + * test class like + * <pre> + * // generated on: 2007.08.06 09:42:34,555 + * import junit.framework.*; + * public class FailedTests extends TestCase { + * public FailedTests(String testname) { + * super(testname); + * } + * public static Test suite() { + * TestSuite suite = new TestSuite(); + * suite.addTest( new B("test04") ); + * suite.addTest( new org.D("test10") ); + * return suite; + * } + * } + * </pre> + * + * Because each running test case gets its own formatter, we collect + * the failing test cases in a static list. Because we dont have a finalizer + * method in the formatters "lifecycle", we register this formatter as + * BuildListener and generate the new java source on taskFinished event. + * + * @since Ant 1.8.0 + */ +public class FailureRecorder extends ProjectComponent implements JUnitResultFormatter, BuildListener { + + /** + * This is the name of a magic System property ({@value}). The value of this + * <b>System</b> property should point to the location where to store the + * generated class (without suffix). + * Default location and name is defined in DEFAULT_CLASS_LOCATION. + * @see #DEFAULT_CLASS_LOCATION + */ + public static final String MAGIC_PROPERTY_CLASS_LOCATION + = "ant.junit.failureCollector"; + + /** Default location and name for the generated JUnit class file. {@value} */ + public static final String DEFAULT_CLASS_LOCATION + = System.getProperty("java.io.tmpdir") + "FailedTests"; + + /** Prefix for logging. {@value} */ + private static final String LOG_PREFIX = " [junit]"; + + /** Class names of failed tests without duplicates. */ + private static SortedSet/*<TestInfos>*/ failedTests = new TreeSet(); + + /** A writer for writing the generated source to. */ + private PrintWriter writer; + + /** + * Location and name of the generated JUnit class. + * Lazy instantiated via getLocationName(). + */ + private static String locationName; + + /** + * Returns the (lazy evaluated) location for the collector class. + * Order for evaluation: System property > Ant property > default value + * @return location for the collector class + * @see #MAGIC_PROPERTY_CLASS_LOCATION + * @see #DEFAULT_CLASS_LOCATION + */ + private String getLocationName() { + if (locationName == null) { + String syspropValue = System.getProperty(MAGIC_PROPERTY_CLASS_LOCATION); + String antpropValue = getProject().getProperty(MAGIC_PROPERTY_CLASS_LOCATION); + + if (syspropValue != null) { + locationName = syspropValue; + verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' set, so use " + + "its value '" + syspropValue + "' as location for collector class."); + } else if (antpropValue != null) { + locationName = antpropValue; + verbose("Ant property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' set, so use " + + "its value '" + antpropValue + "' as location for collector class."); + } else { + locationName = DEFAULT_CLASS_LOCATION; + verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' not set, so use " + + "value as location for collector class: '" + + DEFAULT_CLASS_LOCATION + "'"); + } + + File locationFile = new File(locationName); + if (!locationFile.isAbsolute()) { + File f = new File(getProject().getBaseDir(), locationName); + locationName = f.getAbsolutePath(); + verbose("Location file is relative (" + locationFile + ")" + + " use absolute path instead (" + locationName + ")"); + } + } + + return locationName; + } + + /** + * This method is called by the Ant runtime by reflection. We use the project reference for + * registration of this class as BuildListener. + * + * @param project + * project reference + */ + public void setProject(Project project) { + // store project reference for logging + super.setProject(project); + // check if already registered + boolean alreadyRegistered = false; + Vector allListeners = project.getBuildListeners(); + for (int i = 0; i < allListeners.size(); i++) { + Object listener = allListeners.get(i); + if (listener instanceof FailureRecorder) { + alreadyRegistered = true; + continue; + } + } + // register if needed + if (!alreadyRegistered) { + verbose("Register FailureRecorder (@" + this.hashCode() + ") as BuildListener"); + project.addBuildListener(this); + } + } + + // ===== JUnitResultFormatter ===== + + /** + * Not used + * {@inheritDoc} + */ + public void endTestSuite(JUnitTest suite) throws BuildException { + } + + /** + * Add the failed test to the list. + * @param test the test that errored. + * @param throwable the reason it errored. + * @see junit.framework.TestListener#addError(junit.framework.Test, java.lang.Throwable) + */ + public void addError(Test test, Throwable throwable) { + failedTests.add(new TestInfos(test)); + } + + // CheckStyle:LineLengthCheck OFF - @see is long + /** + * Add the failed test to the list. + * @param test the test that failed. + * @param error the assertion that failed. + * @see junit.framework.TestListener#addFailure(junit.framework.Test, junit.framework.AssertionFailedError) + */ + // CheckStyle:LineLengthCheck ON + public void addFailure(Test test, AssertionFailedError error) { + failedTests.add(new TestInfos(test)); + } + + /** + * Not used + * {@inheritDoc} + */ + public void setOutput(OutputStream out) { + // unused, close output file so it can be deleted before the VM exits + if (out != System.out) { + FileUtils.close(out); + } + } + + /** + * Not used + * {@inheritDoc} + */ + public void setSystemError(String err) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void setSystemOutput(String out) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void startTestSuite(JUnitTest suite) throws BuildException { + } + + /** + * Not used + * {@inheritDoc} + */ + public void endTest(Test test) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void startTest(Test test) { + } + + // ===== "Templates" for generating the JUnit class ===== + + private void writeJavaClass() { + try { + File sourceFile = new File((getLocationName() + ".java")); + verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'"); + + sourceFile.delete(); + writer = new PrintWriter(new FileOutputStream(sourceFile)); + + createClassHeader(); + createSuiteMethod(); + createClassFooter(); + + FileUtils.close(writer); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private void createClassHeader() { + String className = getLocationName().replace('\\', '/'); + if (className.indexOf('/') > -1) { + className = className.substring(className.lastIndexOf('/') + 1); + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss,SSS"); + writer.print("// generated on: "); + writer.println(sdf.format(new Date())); + writer.println("import junit.framework.*;"); + writer.print("public class "); + writer.print(className); + // If this class does not extend TC, Ant doesnt run these + writer.println(" extends TestCase {"); + // standard String-constructor + writer.print(" public "); + writer.print(className); + writer.println("(String testname) {"); + writer.println(" super(testname);"); + writer.println(" }"); + } + + private void createSuiteMethod() { + writer.println(" public static Test suite() {"); + writer.println(" TestSuite suite = new TestSuite();"); + for (Iterator iter = failedTests.iterator(); iter.hasNext();) { + TestInfos testInfos = (TestInfos) iter.next(); + writer.print(" suite.addTest("); + writer.print(testInfos); + writer.println(");"); + } + writer.println(" return suite;"); + writer.println(" }"); + } + + private void createClassFooter() { + writer.println("}"); + } + + // ===== Helper classes and methods ===== + + /** + * Logging facade in INFO-mode. + * @param message Log-message + */ + public void log(String message) { + getProject().log(LOG_PREFIX + " " + message, Project.MSG_INFO); + } + + /** + * Logging facade in VERBOSE-mode. + * @param message Log-message + */ + public void verbose(String message) { + getProject().log(LOG_PREFIX + " " + message, Project.MSG_VERBOSE); + } + + /** + * TestInfos holds information about a given test for later use. + */ + public class TestInfos implements Comparable { + + /** The class name of the test. */ + private String className; + + /** The method name of the testcase. */ + private String methodName; + + /** + * This constructor extracts the needed information from the given test. + * @param test Test to analyze + */ + public TestInfos(Test test) { + className = test.getClass().getName(); + methodName = test.toString(); + methodName = methodName.substring(0, methodName.indexOf('(')); + } + + /** + * This String-Representation can directly be used for instantiation of + * the JUnit testcase. + * @return the string representation. + * @see java.lang.Object#toString() + * @see FailureRecorder#createSuiteMethod() + */ + public String toString() { + return "new " + className + "(\"" + methodName + "\")"; + } + + /** + * The SortedMap needs comparable elements. + * @param other the object to compare to. + * @return the result of the comparison. + * @see java.lang.Comparable#compareTo(T) + * @see SortedSet#comparator() + */ + public int compareTo(Object other) { + if (other instanceof TestInfos) { + TestInfos otherInfos = (TestInfos) other; + return toString().compareTo(otherInfos.toString()); + } else { + return -1; + } + } + } + + // ===== BuildListener ===== + + /** + * Not used + * {@inheritDoc} + */ + public void buildFinished(BuildEvent event) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void buildStarted(BuildEvent event) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void messageLogged(BuildEvent event) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void targetFinished(BuildEvent event) { + } + + /** + * Not used + * {@inheritDoc} + */ + public void targetStarted(BuildEvent event) { + } + + /** + * The task outside of this JUnitResultFormatter is the <junit> task. So all tests passed + * and we could create the new java class. + * @param event not used + * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent) + */ + public void taskFinished(BuildEvent event) { + if (!failedTests.isEmpty()) { + writeJavaClass(); + } + } + + /** + * Not used + * {@inheritDoc} + */ + public void taskStarted(BuildEvent event) { + } + +} diff --git a/src/main/org/apache/tools/ant/types/resources/FileProvider.java b/src/main/org/apache/tools/ant/types/resources/FileProvider.java index 593f08824..aa283004b 100644 --- a/src/main/org/apache/tools/ant/types/resources/FileProvider.java +++ b/src/main/org/apache/tools/ant/types/resources/FileProvider.java @@ -1,36 +1,36 @@ -/*
- * 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.tools.ant.types.resources;
-
-import java.io.File;
-
-/**
- * This is an interface that resources that can provide a file should implement.
- * This is a refactoring of {@link FileResource}, to allow other resources
- * to act as sources of files (and to make components that only support
- * file-based resources from only support FileResource resources.
- * @since Ant 1.8
- */
-public interface FileProvider {
- /**
- * Get the file represented by this Resource.
- * @return the file.
- */
- File getFile();
-}
+/* + * 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.tools.ant.types.resources; + +import java.io.File; + +/** + * This is an interface that resources that can provide a file should implement. + * This is a refactoring of {@link FileResource}, to allow other resources + * to act as sources of files (and to make components that only support + * file-based resources from only support FileResource resources. + * @since Ant 1.8 + */ +public interface FileProvider { + /** + * Get the file represented by this Resource. + * @return the file. + */ + File getFile(); +} diff --git a/src/tests/antunit/core/location/location.xml b/src/tests/antunit/core/location/location.xml index 74c9ff0ef..091d6f337 100644 --- a/src/tests/antunit/core/location/location.xml +++ b/src/tests/antunit/core/location/location.xml @@ -1,4 +1,4 @@ -<?xml version="1.0"?>
+<?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,79 +15,79 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project name="location-test" basedir="." default="all"
- xmlns:au="antlib:org.apache.ant.antunit">
-
- <property name="ant.build.dir" location="../../../../../build"/>
- <property name="working.dir"
- location="${ant.build.dir}/ant-unit/location-dir"/>
- <property name="classes.dir" location="${working.dir}/classes"/>
-
- <target name="all">
- <au:antunit>
- <fileset file="${ant.file}"/>
- <au:plainlistener/>
- </au:antunit>
- </target>
-
- <target name="setUp">
- <mkdir dir="${classes.dir}"/>
- <javac srcdir="src" destdir="${classes.dir}" debug="yes"/>
- <taskdef name="echo-location" classname="task.EchoLocation"
- classpath="${classes.dir}"/>
- </target>
-
- <target name="define">
- <taskdef name="echoloc"
- classname="task.EchoLocation">
- <classpath>
- <pathelement location="${classes.dir}" />
- <pathelement path="${java.class.path}"/>
- </classpath>
- </taskdef>
- </target>
-
- <target name="macrodef" depends="define">
- <macrodef name="echoloc2" backtrace="false">
- <sequential>
- <echoloc/>
- </sequential>
- </macrodef>
- </target>
-
- <target name="presetdef" depends="define">
- <presetdef name="echoloc3">
- <echoloc/>
- </presetdef>
- </target>
-
- <target name="tearDown">
- <delete dir="${working.dir}"/>
- </target>
-
- <target name="test-plain-task">
- <echo id="echo">Hello</echo>
- <au:assertLogContains text="Hello"/>
- </target>
-
- <target name="test-standalone-type">
- <!-- TODO -->
- </target>
-
- <target name="test-condition-task">
- <!-- TODO -->
- </target>
-
- <target name="test-macrodef-wrapped-task" depends="macrodef">
- <echo id="echo3">Hello</echo>
- <echoloc2/>
- <au:assertLogContains text="Line: "/>
- </target>
-
- <target name="test-presetdef-wrapped-task" depends="presetdef">
- <echo id="echo4">Hello</echo>
- <echoloc3/>
- <au:assertLogContains text="Line: "/>
- </target>
-
-</project>
+<project name="location-test" basedir="." default="all" + xmlns:au="antlib:org.apache.ant.antunit"> + + <property name="ant.build.dir" location="../../../../../build"/> + <property name="working.dir" + location="${ant.build.dir}/ant-unit/location-dir"/> + <property name="classes.dir" location="${working.dir}/classes"/> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + + <target name="setUp"> + <mkdir dir="${classes.dir}"/> + <javac srcdir="src" destdir="${classes.dir}" debug="yes"/> + <taskdef name="echo-location" classname="task.EchoLocation" + classpath="${classes.dir}"/> + </target> + + <target name="define"> + <taskdef name="echoloc" + classname="task.EchoLocation"> + <classpath> + <pathelement location="${classes.dir}" /> + <pathelement path="${java.class.path}"/> + </classpath> + </taskdef> + </target> + + <target name="macrodef" depends="define"> + <macrodef name="echoloc2" backtrace="false"> + <sequential> + <echoloc/> + </sequential> + </macrodef> + </target> + + <target name="presetdef" depends="define"> + <presetdef name="echoloc3"> + <echoloc/> + </presetdef> + </target> + + <target name="tearDown"> + <delete dir="${working.dir}"/> + </target> + + <target name="test-plain-task"> + <echo id="echo">Hello</echo> + <au:assertLogContains text="Hello"/> + </target> + + <target name="test-standalone-type"> + <!-- TODO --> + </target> + + <target name="test-condition-task"> + <!-- TODO --> + </target> + + <target name="test-macrodef-wrapped-task" depends="macrodef"> + <echo id="echo3">Hello</echo> + <echoloc2/> + <au:assertLogContains text="Line: "/> + </target> + + <target name="test-presetdef-wrapped-task" depends="presetdef"> + <echo id="echo4">Hello</echo> + <echoloc3/> + <au:assertLogContains text="Line: "/> + </target> + +</project> diff --git a/src/tests/antunit/core/location/src/task/EchoLocation.java b/src/tests/antunit/core/location/src/task/EchoLocation.java index 9743c5286..014314511 100644 --- a/src/tests/antunit/core/location/src/task/EchoLocation.java +++ b/src/tests/antunit/core/location/src/task/EchoLocation.java @@ -1,26 +1,26 @@ -/*
-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 task;
-
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-public class EchoLocation extends Task {
- public void execute() {
- log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO);
- }
+/* +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 task; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +public class EchoLocation extends Task { + public void execute() { + log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO); + } }
\ No newline at end of file diff --git a/src/tests/antunit/taskdefs/condition/antversion-test.xml b/src/tests/antunit/taskdefs/condition/antversion-test.xml index 01ebe1d68..b9d673f2e 100644 --- a/src/tests/antunit/taskdefs/condition/antversion-test.xml +++ b/src/tests/antunit/taskdefs/condition/antversion-test.xml @@ -1,4 +1,4 @@ -<?xml version="1.0"?>
+<?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,56 +15,56 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project name="antversion-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit">
-
- <target name="test-atleast">
- <au:assertTrue message="Expected antversion of ${ant.version} to be at least 1.7.0">
- <!-- AntVersion was introduced like AntUnit in 1.7 - so this must be true -->
- <antversion atleast="1.7.0"/>
- </au:assertTrue>
- </target>
-
- <target name="test-exactly">
- <antversion property="ant.actual.version"/>
- <au:assertTrue message="Expected antversion of ${ant.actual.version}">
- <antversion exactly="${ant.actual.version}"/>
- </au:assertTrue>
- </target>
-
- <target name="test-atleast-fail">
- <property name="version" value="1.8.9"/>
- <au:assertFalse>
- <antversion atleast="1.9.0"/>
- </au:assertFalse>
- </target>
-
- <target name="test-task">
- <antversion property="antversion"/>
- <au:assertPropertySet name="antversion" message="Property 'antversion' should be set."/>
- <echo>AntVersion=${antversion}</echo>
- </target>
-
- <target name="test-property-conditional1">
- <antversion property="antversion" atleast="2.0.0"/>
- <au:assertTrue message="Property 'antversion' should not be set because this is not Ant 2.0.0+.">
- <not>
- <isset property="antversion"/>
- </not>
- </au:assertTrue>
- </target>
-
- <target name="test-property-conditional2">
- <antversion property="antversion" atleast="1.7.0"/>
- <au:assertTrue message="Property 'antversion' should be set because we should have Ant 1.7.0+ (${ant.version}).">
- <isset property="antversion"/>
- </au:assertTrue>
- </target>
-
- <target name="all">
- <au:antunit>
- <fileset file="${ant.file}"/>
- <au:plainlistener/>
- </au:antunit>
- </target>
-
-</project>
+<project name="antversion-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="test-atleast"> + <au:assertTrue message="Expected antversion of ${ant.version} to be at least 1.7.0"> + <!-- AntVersion was introduced like AntUnit in 1.7 - so this must be true --> + <antversion atleast="1.7.0"/> + </au:assertTrue> + </target> + + <target name="test-exactly"> + <antversion property="ant.actual.version"/> + <au:assertTrue message="Expected antversion of ${ant.actual.version}"> + <antversion exactly="${ant.actual.version}"/> + </au:assertTrue> + </target> + + <target name="test-atleast-fail"> + <property name="version" value="1.8.9"/> + <au:assertFalse> + <antversion atleast="1.9.0"/> + </au:assertFalse> + </target> + + <target name="test-task"> + <antversion property="antversion"/> + <au:assertPropertySet name="antversion" message="Property 'antversion' should be set."/> + <echo>AntVersion=${antversion}</echo> + </target> + + <target name="test-property-conditional1"> + <antversion property="antversion" atleast="2.0.0"/> + <au:assertTrue message="Property 'antversion' should not be set because this is not Ant 2.0.0+."> + <not> + <isset property="antversion"/> + </not> + </au:assertTrue> + </target> + + <target name="test-property-conditional2"> + <antversion property="antversion" atleast="1.7.0"/> + <au:assertTrue message="Property 'antversion' should be set because we should have Ant 1.7.0+ (${ant.version})."> + <isset property="antversion"/> + </au:assertTrue> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + +</project> diff --git a/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml b/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml index 94b184f61..7507e300e 100644 --- a/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml +++ b/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml @@ -1,4 +1,4 @@ -<?xml version="1.0"?>
+<?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,43 +15,43 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project name="hasfreespace-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit">
-
- <available property="jdk6.available" classname="java.util.ServiceLoader"/>
-
- <property name="partition" value="${user.home}" />
-
-
- <target name="test-not-enough-space-human" if="jdk6.available">
- <au:assertFalse>
- <hasfreespace partition="${partition}" needed="1P"/>
- </au:assertFalse>
- </target>
-
- <target name="test-enough-space-human" if="jdk6.available">
- <au:assertTrue>
- <hasfreespace partition="${partition}" needed="1K"/>
- </au:assertTrue>
- </target>
-
- <target name="test-not-enough-space" if="jdk6.available">
- <property name="long.max-value" value="9223372036854775807"/>
- <au:assertFalse>
- <hasfreespace partition="${partition}" needed="${long.max-value}"/>
- </au:assertFalse>
- </target>
-
- <target name="test-enough-space" if="jdk6.available">
- <au:assertTrue>
- <hasfreespace partition="${partition}" needed="1"/>
- </au:assertTrue>
- </target>
-
- <target name="all">
- <au:antunit>
- <fileset file="${ant.file}"/>
- <au:plainlistener/>
- </au:antunit>
- </target>
-
+<project name="hasfreespace-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit"> + + <available property="jdk6.available" classname="java.util.ServiceLoader"/> + + <property name="partition" value="${user.home}" /> + + + <target name="test-not-enough-space-human" if="jdk6.available"> + <au:assertFalse> + <hasfreespace partition="${partition}" needed="1P"/> + </au:assertFalse> + </target> + + <target name="test-enough-space-human" if="jdk6.available"> + <au:assertTrue> + <hasfreespace partition="${partition}" needed="1K"/> + </au:assertTrue> + </target> + + <target name="test-not-enough-space" if="jdk6.available"> + <property name="long.max-value" value="9223372036854775807"/> + <au:assertFalse> + <hasfreespace partition="${partition}" needed="${long.max-value}"/> + </au:assertFalse> + </target> + + <target name="test-enough-space" if="jdk6.available"> + <au:assertTrue> + <hasfreespace partition="${partition}" needed="1"/> + </au:assertTrue> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + </project>
\ No newline at end of file diff --git a/src/tests/antunit/taskdefs/echoxml-test.xml b/src/tests/antunit/taskdefs/echoxml-test.xml index a8bd2cbc1..d461d3d83 100644 --- a/src/tests/antunit/taskdefs/echoxml-test.xml +++ b/src/tests/antunit/taskdefs/echoxml-test.xml @@ -1,87 +1,87 @@ -<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
-
- <!-- note relies on antunit 1.1 -->
- <import file="../antunit-base.xml"/>
-
- <target name="setUp">
- <property name="file" location="${output}/echoed.xml"/>
- <mkdir dir="${output}"/>
- <echoxml file="${file}">
- <project>
- <property name="foo" value="bar" />
- <fail message="$$$${foo}=$${foo}">
- <condition>
- <istrue value="${mustfail}" />
- </condition>
- </fail>
- </project>
- </echoxml>
- </target>
-
- <target name="testPass">
- <ant antfile="${file}"/>
- </target>
-
- <target name="testFail">
- <au:expectfailure expectedmessage="${foo}=bar" message="Should have thrown an exception">
- <ant antfile="${file}">
- <property name="mustfail" value="true" />
- </ant>
- </au:expectfailure>
- </target>
-
- <target name="testEmpty">
- <au:expectfailure expectedmessage="No nested XML specified" message="Should have thrown an exception">
- <echoxml />
- </au:expectfailure>
- </target>
-
- <!-- comment this and the next targets if you don't have the svn
- trunk of antunit -->
- <target name="test-ns-all">
- <echoxml file="${file}" xmlns:a="antlib:a"
- namespacepolicy="all">
- <a:something a:foo="bar"/>
- </echoxml>
- <au:assertResourceContains resource="${file}" value="a:something"/>
- <au:assertResourceContains resource="${file}" value="antlib:a"/>
- </target>
-
- <target name="test-ns-elementsOnly">
- <echoxml file="${file}" xmlns:a="antlib:a"
- namespacepolicy="elementsOnly">
- <a:something a:foo="bar"/>
- </echoxml>
- <au:assertResourceContains resource="${file}" value="a:something"/>
- <au:assertResourceContains resource="${file}" value="antlib:a"/>
- </target>
-
- <target name="test-ns-ignore">
- <echoxml file="${file}" xmlns:a="antlib:a"
- namespacepolicy="ignore">
- <a:something a:foo="bar"/>
- </echoxml>
- <au:assertResourceContains resource="${file}" value="a:something"/>
- <au:assertFalse message="Didn't expecte ${file} to contain antlib:a">
- <resourcecontains resource="${file}" substring="antlib:a"/>
- </au:assertFalse>
- </target>
-
-</project>
+<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <!-- note relies on antunit 1.1 --> + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <property name="file" location="${output}/echoed.xml"/> + <mkdir dir="${output}"/> + <echoxml file="${file}"> + <project> + <property name="foo" value="bar" /> + <fail message="$$$${foo}=$${foo}"> + <condition> + <istrue value="${mustfail}" /> + </condition> + </fail> + </project> + </echoxml> + </target> + + <target name="testPass"> + <ant antfile="${file}"/> + </target> + + <target name="testFail"> + <au:expectfailure expectedmessage="${foo}=bar" message="Should have thrown an exception"> + <ant antfile="${file}"> + <property name="mustfail" value="true" /> + </ant> + </au:expectfailure> + </target> + + <target name="testEmpty"> + <au:expectfailure expectedmessage="No nested XML specified" message="Should have thrown an exception"> + <echoxml /> + </au:expectfailure> + </target> + + <!-- comment this and the next targets if you don't have the svn + trunk of antunit --> + <target name="test-ns-all"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="all"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertResourceContains resource="${file}" value="antlib:a"/> + </target> + + <target name="test-ns-elementsOnly"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="elementsOnly"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertResourceContains resource="${file}" value="antlib:a"/> + </target> + + <target name="test-ns-ignore"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="ignore"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertFalse message="Didn't expecte ${file} to contain antlib:a"> + <resourcecontains resource="${file}" substring="antlib:a"/> + </au:assertFalse> + </target> + +</project> diff --git a/src/tests/antunit/taskdefs/gzip-test.xml b/src/tests/antunit/taskdefs/gzip-test.xml index da18c6d09..38f0a7a68 100644 --- a/src/tests/antunit/taskdefs/gzip-test.xml +++ b/src/tests/antunit/taskdefs/gzip-test.xml @@ -1,46 +1,46 @@ -<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
-
- <!-- note relies on antunit 1.1 -->
- <import file="../antunit-base.xml" />
-
- <target name="setUp">
- <mkdir dir="${output}" />
- <mkdir dir="${output}/empty" />
- <touch file="${output}/fileone" />
- <touch file="${output}/filetwo" />
- </target>
-
- <target name="testFailNone">
- <au:expectfailure expectedmessage="No resource selected, gzip needs exactly one resource." message="Should have thrown an exception">
- <gzip destfile="${output}/file.gz">
- <fileset dir="${output}/empty" />
- </gzip>
- </au:expectfailure>
- </target>
-
- <target name="testFailTwo">
- <au:expectfailure expectedmessage="gzip cannot handle multiple resources at once. (2 resources were selected.)" message="Should have thrown an exception">
- <gzip destfile="${output}/file.gz">
- <fileset dir="${output}" />
- </gzip>
- </au:expectfailure>
- </target>
-
-</project>
+<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <!-- note relies on antunit 1.1 --> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + <mkdir dir="${output}/empty" /> + <touch file="${output}/fileone" /> + <touch file="${output}/filetwo" /> + </target> + + <target name="testFailNone"> + <au:expectfailure expectedmessage="No resource selected, gzip needs exactly one resource." message="Should have thrown an exception"> + <gzip destfile="${output}/file.gz"> + <fileset dir="${output}/empty" /> + </gzip> + </au:expectfailure> + </target> + + <target name="testFailTwo"> + <au:expectfailure expectedmessage="gzip cannot handle multiple resources at once. (2 resources were selected.)" message="Should have thrown an exception"> + <gzip destfile="${output}/file.gz"> + <fileset dir="${output}" /> + </gzip> + </au:expectfailure> + </target> + +</project> diff --git a/src/tests/antunit/taskdefs/hostinfo-test.xml b/src/tests/antunit/taskdefs/hostinfo-test.xml index 43fc7b5a4..eb5afd647 100644 --- a/src/tests/antunit/taskdefs/hostinfo-test.xml +++ b/src/tests/antunit/taskdefs/hostinfo-test.xml @@ -1,94 +1,94 @@ -<?xml version="1.0"?>
-<!--
- 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.
--->
-<project name="hostinfo-test" default="antunit"
- xmlns:au="antlib:org.apache.ant.antunit">
-
- <import file="../antunit-base.xml" />
-
- <property name="undef-name" value="nonexistenthost.nonexistentdomain" />
- <property name="undef-hostname" value="nonexistenthost" />
- <property name="undef-domainname" value="nonexistentdomain" />
-
- <property name="undef-ip4" value="0.0.0.0" />
- <property name="undef-ip6" value="::" />
-
- <property name="apache-hostname" value="www.apache.org" />
- <property name="apache-domain" value="apache.org" />
- <property name="apache-realhost" value="eos" />
- <property name="apache-ip4" value="140.211.11.130" />
-
- <property name="xs4all-hostname" value="www.xs4all.nl" />
- <property name="xs4all-domain" value="xs4all.nl" />
- <property name="xs4all-realhost" value="www" />
- <property name="xs4all-ip4" value="194.109.6.92" />
-
- <target name="setUp">
- </target>
-
- <target name="testLocal" depends="setUp">
- <hostinfo prefix="local" />
- <!-- Do not know what to expect here, machine dependent -->
- </target>
-
- <target name="testApache" depends="setUp">
- <hostinfo prefix="apache" host="${apache-hostname}"/>
- <au:assertTrue>
- <and>
- <equals arg1="${apache.NAME}" arg2="${apache-realhost}" />
- <equals arg1="${apache.DOMAIN}" arg2="${apache-domain}" />
- <equals arg1="${apache.ADDR4}" arg2="${apache-ip4}" />
- </and>
- </au:assertTrue>
- </target>
-
- <target name="testApacheNoPrefix" depends="setUp">
- <hostinfo host="${apache-hostname}"/>
- <au:assertTrue>
- <and>
- <equals arg1="${NAME}" arg2="${apache-realhost}" />
- <equals arg1="${DOMAIN}" arg2="${apache-domain}" />
- <equals arg1="${ADDR4}" arg2="${apache-ip4}" />
- </and>
- </au:assertTrue>
- </target>
-
- <target name="testReverse" depends="setUp">
- <hostinfo prefix="reverse" host="${xs4all-ip4}"/>
- <au:assertTrue>
- <and>
- <equals arg1="${reverse.NAME}" arg2="${xs4all-realhost}" />
- <equals arg1="${reverse.DOMAIN}" arg2="${xs4all-domain}" />
- <equals arg1="${reverse.ADDR4}" arg2="${xs4all-ip4}" />
- </and>
- </au:assertTrue>
- </target>
-
-
- <target name="testUndef" depends="setUp">
- <hostinfo prefix="undef" host="${undef-name}"/>
- <au:assertTrue>
- <and>
- <equals arg1="${undef.NAME}" arg2="${undef-hostname}" />
- <equals arg1="${undef.DOMAIN}" arg2="${undef-domainname}" />
- <equals arg1="${undef.ADDR4}" arg2="${undef-ip4}" />
- <equals arg1="${undef.ADDR6}" arg2="${undef-ip6}" />
- </and>
- </au:assertTrue>
- </target>
-
-</project>
+<?xml version="1.0"?> +<!-- + 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. +--> +<project name="hostinfo-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="undef-name" value="nonexistenthost.nonexistentdomain" /> + <property name="undef-hostname" value="nonexistenthost" /> + <property name="undef-domainname" value="nonexistentdomain" /> + + <property name="undef-ip4" value="0.0.0.0" /> + <property name="undef-ip6" value="::" /> + + <property name="apache-hostname" value="www.apache.org" /> + <property name="apache-domain" value="apache.org" /> + <property name="apache-realhost" value="eos" /> + <property name="apache-ip4" value="140.211.11.130" /> + + <property name="xs4all-hostname" value="www.xs4all.nl" /> + <property name="xs4all-domain" value="xs4all.nl" /> + <property name="xs4all-realhost" value="www" /> + <property name="xs4all-ip4" value="194.109.6.92" /> + + <target name="setUp"> + </target> + + <target name="testLocal" depends="setUp"> + <hostinfo prefix="local" /> + <!-- Do not know what to expect here, machine dependent --> + </target> + + <target name="testApache" depends="setUp"> + <hostinfo prefix="apache" host="${apache-hostname}"/> + <au:assertTrue> + <and> + <equals arg1="${apache.NAME}" arg2="${apache-realhost}" /> + <equals arg1="${apache.DOMAIN}" arg2="${apache-domain}" /> + <equals arg1="${apache.ADDR4}" arg2="${apache-ip4}" /> + </and> + </au:assertTrue> + </target> + + <target name="testApacheNoPrefix" depends="setUp"> + <hostinfo host="${apache-hostname}"/> + <au:assertTrue> + <and> + <equals arg1="${NAME}" arg2="${apache-realhost}" /> + <equals arg1="${DOMAIN}" arg2="${apache-domain}" /> + <equals arg1="${ADDR4}" arg2="${apache-ip4}" /> + </and> + </au:assertTrue> + </target> + + <target name="testReverse" depends="setUp"> + <hostinfo prefix="reverse" host="${xs4all-ip4}"/> + <au:assertTrue> + <and> + <equals arg1="${reverse.NAME}" arg2="${xs4all-realhost}" /> + <equals arg1="${reverse.DOMAIN}" arg2="${xs4all-domain}" /> + <equals arg1="${reverse.ADDR4}" arg2="${xs4all-ip4}" /> + </and> + </au:assertTrue> + </target> + + + <target name="testUndef" depends="setUp"> + <hostinfo prefix="undef" host="${undef-name}"/> + <au:assertTrue> + <and> + <equals arg1="${undef.NAME}" arg2="${undef-hostname}" /> + <equals arg1="${undef.DOMAIN}" arg2="${undef-domainname}" /> + <equals arg1="${undef.ADDR4}" arg2="${undef-ip4}" /> + <equals arg1="${undef.ADDR6}" arg2="${undef-ip6}" /> + </and> + </au:assertTrue> + </target> + +</project> diff --git a/src/tests/antunit/taskdefs/loadresource-test.xml b/src/tests/antunit/taskdefs/loadresource-test.xml index fc7492a11..814ded5be 100644 --- a/src/tests/antunit/taskdefs/loadresource-test.xml +++ b/src/tests/antunit/taskdefs/loadresource-test.xml @@ -1,41 +1,41 @@ -<?xml version="1.0"?>
-<!--
- 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.
--->
-<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
-
- <import file="../antunit-base.xml" />
-
- <target name="test-resourceString">
- <loadresource property="p">
- <string value="one"/>
- </loadresource >
- <au:assertPropertyEquals name="p" value="one"/>
- </target>
-
- <target name="test-resourceSizeZero" description="Bug 42319">
- <loadresource property="p">
- <string value=""/>
- </loadresource >
- <au:assertTrue>
- <not>
- <isset property="p"/>
- </not>
- </au:assertTrue>
- <au:assertLogContains text="Do not set property p as its length is 0."/>
- </target>
-
-</project>
+<?xml version="1.0"?> +<!-- + 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="test-resourceString"> + <loadresource property="p"> + <string value="one"/> + </loadresource > + <au:assertPropertyEquals name="p" value="one"/> + </target> + + <target name="test-resourceSizeZero" description="Bug 42319"> + <loadresource property="p"> + <string value=""/> + </loadresource > + <au:assertTrue> + <not> + <isset property="p"/> + </not> + </au:assertTrue> + <au:assertLogContains text="Do not set property p as its length is 0."/> + </target> + +</project> diff --git a/src/tests/antunit/types/resources/files-test.xml b/src/tests/antunit/types/resources/files-test.xml index c33ed6c0f..f4051fbe6 100644 --- a/src/tests/antunit/types/resources/files-test.xml +++ b/src/tests/antunit/types/resources/files-test.xml @@ -1,53 +1,53 @@ -<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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.
--->
-<project name="files-test" default="antunit"
- xmlns:au="antlib:org.apache.ant.antunit">
-
- <target name="antunit">
- <au:antunit>
- <au:plainlistener />
- <file file="${ant.file}" />
- </au:antunit>
- </target>
-
- <target name="setUp">
- <property name="out" value="out"/>
- </target>
-
- <target name="tearDown">
- <delete dir="${out}"/>
- </target>
-
- <target name="testEmptyReference" description="Bug43048">
- <files id="foo"/>
- <mkdir dir="${out}"/>
- <copy todir="${out}">
- <!-- threw a java.lang.NullPointerException -->
- <files refid="foo"/>
- </copy>
- </target>
-
- <target name="testEmptyFiles" description="Bug43048">
- <mkdir dir="${out}"/>
- <copy todir="${out}">
- <files/>
- </copy>
- </target>
-
-
-</project>
+<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<project name="files-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="antunit"> + <au:antunit> + <au:plainlistener /> + <file file="${ant.file}" /> + </au:antunit> + </target> + + <target name="setUp"> + <property name="out" value="out"/> + </target> + + <target name="tearDown"> + <delete dir="${out}"/> + </target> + + <target name="testEmptyReference" description="Bug43048"> + <files id="foo"/> + <mkdir dir="${out}"/> + <copy todir="${out}"> + <!-- threw a java.lang.NullPointerException --> + <files refid="foo"/> + </copy> + </target> + + <target name="testEmptyFiles" description="Bug43048"> + <mkdir dir="${out}"/> + <copy todir="${out}"> + <files/> + </copy> + </target> + + +</project> |