Author: mbenson
Date: Mon Oct 24 08:18:52 2005
New Revision: 328083
URL: http://svn.apache.org/viewcvs?rev=328083&view=rev
Log:
Bugzilla 37184; submitted by Frank Harnack. Also replaced extra listener
Vector instances by synchronization for ConcurrentModificationException guards.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/Project.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL:
http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?rev=328083&r1=328082&r2=328083&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Mon Oct 24
08:18:52 2005
@@ -324,18 +324,12 @@
* be notified of build events for this project.
*
* @param listener The listener to add to the list.
- * Must not be <code>null</code>.
+ * Ignored if <code>null</code>.
*/
public synchronized void addBuildListener(BuildListener listener) {
- // If the listeners already has this listener, do nothing
- if (listeners.contains(listener)) {
- return;
+ if (!(listener == null || listeners.contains(listener))) {
+ listeners.add(listener);
}
- // create a new Vector to avoid ConcurrentModificationExc when
- // the listeners get added/removed while we are in fire
- Vector newListeners = getBuildListeners();
- newListeners.addElement(listener);
- listeners = newListeners;
}
/**
@@ -346,11 +340,7 @@
* Should not be <code>null</code>.
*/
public synchronized void removeBuildListener(BuildListener listener) {
- // create a new Vector to avoid ConcurrentModificationExc when
- // the listeners get added/removed while we are in fire
- Vector newListeners = getBuildListeners();
- newListeners.removeElement(listener);
- listeners = newListeners;
+ listeners.remove(listener);
}
/**
@@ -1847,7 +1837,7 @@
* Send a "build started" event
* to the build listeners for this project.
*/
- public void fireBuildStarted() {
+ public synchronized void fireBuildStarted() {
BuildEvent event = new BuildEvent(this);
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
@@ -1863,7 +1853,7 @@
* failure. May be <code>null</code>, indicating
* a successful build.
*/
- public void fireBuildFinished(Throwable exception) {
+ public synchronized void fireBuildFinished(Throwable exception) {
BuildEvent event = new BuildEvent(this);
event.setException(exception);
Iterator iter = listeners.iterator();
@@ -1879,7 +1869,7 @@
*
* @since Ant 1.6.2
*/
- public void fireSubBuildStarted() {
+ public synchronized void fireSubBuildStarted() {
BuildEvent event = new BuildEvent(this);
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
@@ -1899,7 +1889,7 @@
*
* @since Ant 1.6.2
*/
- public void fireSubBuildFinished(Throwable exception) {
+ public synchronized void fireSubBuildFinished(Throwable exception) {
BuildEvent event = new BuildEvent(this);
event.setException(exception);
Iterator iter = listeners.iterator();
@@ -1918,7 +1908,7 @@
* @param target The target which is starting to build.
* Must not be <code>null</code>.
*/
- protected void fireTargetStarted(Target target) {
+ protected synchronized void fireTargetStarted(Target target) {
BuildEvent event = new BuildEvent(target);
Iterator iter = listeners.iterator();
while (iter.hasNext()) {
@@ -1937,7 +1927,8 @@
* failure. May be <code>null</code>, indicating
* a successful build.
*/
- protected void fireTargetFinished(Target target, Throwable exception) {
+ protected synchronized void fireTargetFinished(Target target,
+ Throwable exception) {
BuildEvent event = new BuildEvent(target);
event.setException(exception);
Iterator iter = listeners.iterator();
@@ -1954,7 +1945,7 @@
* @param task The target which is starting to execute.
* Must not be <code>null</code>.
*/
- protected void fireTaskStarted(Task task) {
+ protected synchronized void fireTaskStarted(Task task) {
// register this as the current task on the current thread.
registerThreadTask(Thread.currentThread(), task);
BuildEvent event = new BuildEvent(task);
@@ -1975,7 +1966,7 @@
* failure. May be <code>null</code>, indicating
* a successful build.
*/
- protected void fireTaskFinished(Task task, Throwable exception) {
+ protected synchronized void fireTaskFinished(Task task, Throwable
exception) {
registerThreadTask(Thread.currentThread(), null);
System.out.flush();
System.err.flush();
@@ -1999,8 +1990,9 @@
* @param message The message to send. Should not be <code>null</code>.
* @param priority The priority of the message.
*/
- private void fireMessageLoggedEvent(BuildEvent event, String message,
- int priority) {
+ private synchronized void fireMessageLoggedEvent(BuildEvent event,
+ String message,
+ int priority) {
if (message.endsWith(StringUtils.LINE_SEP)) {
int endIndex = message.length() - StringUtils.LINE_SEP.length();
@@ -2047,8 +2039,8 @@
* @param message The message to send. Should not be <code>null</code>.
* @param priority The priority of the message.
*/
- protected void fireMessageLogged(Project project, String message,
- int priority) {
+ protected synchronized void fireMessageLogged(Project project, String
message,
+ int priority) {
BuildEvent event = new BuildEvent(project);
fireMessageLoggedEvent(event, message, priority);
}
@@ -2062,8 +2054,8 @@
* @param message The message to send. Should not be <code>null</code>.
* @param priority The priority of the message.
*/
- protected void fireMessageLogged(Target target, String message,
- int priority) {
+ protected synchronized void fireMessageLogged(Target target, String
message,
+ int priority) {
BuildEvent event = new BuildEvent(target);
fireMessageLoggedEvent(event, message, priority);
}
@@ -2077,7 +2069,8 @@
* @param message The message to send. Should not be <code>null</code>.
* @param priority The priority of the message.
*/
- protected void fireMessageLogged(Task task, String message, int priority) {
+ protected synchronized void fireMessageLogged(Task task, String message,
+ int priority) {
BuildEvent event = new BuildEvent(task);
fireMessageLoggedEvent(event, message, priority);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]