summaryrefslogtreecommitdiff
path: root/src/main/org/apache/tools/ant/BuildEvent.java
diff options
context:
space:
mode:
authorConor MacNeill <conor@apache.org>2000-06-24 10:55:45 +0000
committerConor MacNeill <conor@apache.org>2000-06-24 10:55:45 +0000
commit1ba5087df429abe38dd22fe5c9ddbc343280f0ae (patch)
tree3dab98fe4774bb6805da4a4640f0e1fabaf0d99e /src/main/org/apache/tools/ant/BuildEvent.java
parentd5bfb5609dde48b93877185c1f61067e009e8499 (diff)
downloadant-1ba5087df429abe38dd22fe5c9ddbc343280f0ae.tar.gz
Add BuildEvents to Ant
The basic idea is to keep the core build engine "clean" and free of any presentation logic, and to make it easier to extend Ant with other features without cluttering up the core. To do this, I've defined a BuildListener interface and added an "addBuildListener" method to Project that can be used to register listener objects. Listeners could be implemented to generate reports, send out emails when the build is complete, create a bill of materials, etc... The only new functionality visible to the end-user is a "-listener" option on the command line that will let you specify the name of a class. An instance of this class will be added as a listener to the project. I've included a listener that will generate an XML log file, which you can use by typing the command below. build -listener org.apache.tools.ant.XmlLogger PR: Obtained from: Submitted by: Matt Foemmel <mpfoemme@ThoughtWorks.com> Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267694 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache/tools/ant/BuildEvent.java')
-rw-r--r--src/main/org/apache/tools/ant/BuildEvent.java153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/main/org/apache/tools/ant/BuildEvent.java b/src/main/org/apache/tools/ant/BuildEvent.java
new file mode 100644
index 000000000..4f58fee20
--- /dev/null
+++ b/src/main/org/apache/tools/ant/BuildEvent.java
@@ -0,0 +1,153 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.ant;
+
+import java.util.EventObject;
+
+public class BuildEvent extends EventObject {
+ private Project project;
+ private Target target;
+ private Task task;
+ private String message;
+ private int priority;
+ private Throwable exception;
+
+ /**
+ * Constructs a new build event. Fields that are not relevant
+ * can be set to null, except for the project field which is
+ * required.
+ */
+ public BuildEvent(
+ Project project,
+ Target target,
+ Task task,
+ String message,
+ int priority,
+ Throwable exception) {
+
+ super(getSource(project, target, task));
+
+ this.project = project;
+ this.target = target;
+ this.task = task;
+ this.message = message;
+ this.priority = priority;
+ this.exception = exception;
+ }
+
+ /**
+ * Returns the project that fired this event.
+ */
+ public Project getProject() {
+ return project;
+ }
+
+ /**
+ * Returns the target that fired this event.
+ */
+ public Target getTarget() {
+ return target;
+ }
+
+ /**
+ * Returns the task that fired this event.
+ */
+ public Task getTask() {
+ return task;
+ }
+
+ /**
+ * Returns the logging message. This field will only be set
+ * for "messageLogged" events.
+ *
+ * @see BuildListener#messageLogged(BuildEvent)
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Returns the priority of the logging message. This field will only
+ * be set for "messageLogged" events.
+ *
+ * @see BuildListener#messageLogged(BuildEvent)
+ */
+ public int getPriority(){
+ return priority;
+ }
+
+ /**
+ * Returns the exception that was thrown, if any. This field will only
+ * be set for "taskFinished", "targetFinished", and "buildFinished" events.
+ *
+ * @see BuildListener#taskFinished(BuildEvent)
+ * @see BuildListener#targetFinished(BuildEvent)
+ * @see BuildListener#buildFinished(BuildEvent)
+ */
+ public Throwable getException() {
+ return exception;
+ }
+
+ /**
+ * Returns the object that fired this event.
+ */
+ private static Object getSource(Project project, Target target, Task task) {
+ if (task != null) return task;
+ if (target != null) return target;
+ if (project != null) return project;
+
+ throw new IllegalArgumentException("Project field cannot be null");
+ }
+} \ No newline at end of file