sbailliez 02/01/30 13:06:49
Added:
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote
EventDispatcher.java Messenger.java
TestRunEvent.java TestRunListener.java
Log:
Prepare for listener changes and event types.
Revision Changes Path
1.1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/EventDispatcher.java
Index: EventDispatcher.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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", "Ant", 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 [EMAIL PROTECTED]
*
* 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.taskdefs.optional.junit.remote;
import java.util.Vector;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class EventDispatcher {
/** the set of registered listeners */
private Vector listeners = new Vector();
/**
* Add a new listener.
* @param listener a listener that will receive events from the client.
*/
public void addListener(TestRunListener listener) {
listeners.addElement(listener);
}
public void
removeListener(org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener
listener) {
listeners.removeElement(listener);
}
/**
* Process a message from the client and dispatch the
* appropriate message to the listeners.
*/
public void dispatchEvent(TestRunEvent evt) {
// I hate switch/case but no need to design a complex
// system for limited events.
switch (evt.getType()){
case TestRunEvent.RUN_STARTED:
fireRunStarted(evt);
break;
case TestRunEvent.RUN_ENDED:
fireRunEnded(evt);
break;
case TestRunEvent.RUN_STOPPED:
fireRunStopped(evt);
break;
case TestRunEvent.TEST_STARTED:
fireTestStarted(evt);
break;
case TestRunEvent.TEST_ERROR:
fireTestError(evt);
break;
case TestRunEvent.TEST_FAILURE:
fireTestFailure(evt);
break;
case TestRunEvent.TEST_ENDED:
fireTestEnded(evt);
break;
case TestRunEvent.TESTSUITE_ENDED:
fireSuiteEnded(evt);
break;
case TestRunEvent.TESTSUITE_STARTED:
fireSuiteStarted(evt);
break;
default:
// should not happen
}
}
protected void fireRunStarted(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onRunStarted(evt);
}
}
}
protected void fireRunEnded(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onRunEnded(evt);
}
}
}
protected void fireTestStarted(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onTestStarted(evt);
}
}
}
protected void fireTestEnded(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onTestEnded(evt);
}
}
}
protected void fireTestFailure(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onTestFailure(evt);
}
}
}
protected void fireTestError(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onTestError(evt);
}
}
}
protected void fireSuiteStarted(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onSuiteStarted(evt);
}
}
}
protected void fireSuiteEnded(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onSuiteEnded(evt);
}
}
}
protected void fireRunStopped(TestRunEvent evt) {
synchronized (listeners) {
for (int i = 0; i < listeners.size(); i++) {
((org.apache.tools.ant.taskdefs.optional.junit.remote.TestRunListener)
listeners.elementAt(i)).onRunStopped(evt);
}
}
}
}
1.1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Messenger.java
Index: Messenger.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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", "Ant", 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 [EMAIL PROTECTED]
*
* 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.taskdefs.optional.junit.remote;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class Messenger {
private InputStream in;
private OutputStream out;
public Messenger(InputStream in, OutputStream out) throws IOException {
setOutputStream( new ObjectOutputStream(out) );
setInputStream( new ObjectInputStream(in) );
}
protected void finalize() throws Throwable {
close();
}
public void close() throws IOException {
if (in != null) {
in.close();
in = null;
}
if (out != null) {
out.flush();
out.close();
out = null;
}
}
public TestRunEvent read() throws IOException {
return (TestRunEvent)((ObjectInputStream)in).readObject();
}
public void writeEvent(TestRunEvent evt) throws IOException {
((ObjectOutputStream)out).writeObject(evt);
}
protected OutputStream getOutputStream(){
return out;
}
protected InputStream getInputStream(){
return in;
}
protected void setOutputStream(OutputStream out){
this.out = out;
}
protected void setInputStream(InputStream in){
this.in = in;
}
}
1.1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunEvent.java
Index: TestRunEvent.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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", "Ant", 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 [EMAIL PROTECTED]
*
* 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.taskdefs.optional.junit.remote;
import java.util.EventObject;
import java.util.Properties;
import org.apache.tools.ant.util.StringUtils;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class TestRunEvent extends EventObject {
// received from clients
public final static int RUN_STARTED = 0;
public final static int RUN_ENDED = 1;
public final static int RUN_STOPPED = 2;
public final static int TEST_STARTED = 3;
public final static int TEST_FAILURE = 4;
public final static int TEST_ERROR = 5;
public final static int TEST_ENDED = 6;
public final static int SUITE_STARTED = 7;
public final static int SUITE_ENDED = 8;
// received from server
public final static int RUN_STOP = 9;
/** the type of event */
private int type = -1;
/** timestamp for all tests */
private long timestamp = System.currentTimeMillis();
/** name of testcase(method name) or testsuite (classname) */
private String name;
/** stacktrace for error or failure */
private String stacktrace;
/** properties for end of testrun */
private Properties props;
public TestRunEvent(Integer id, int type){
super(id);
this.type = type;
}
public TestRunEvent(Integer id, int type, String name){
this(id, type);
this.name = name;
}
public TestRunEvent(Integer id, int type, Properties props){
this(id, type);
this.props = props;
}
public TestRunEvent(Integer id, int type, String name, Throwable t){
this(id, type, name);
this.stacktrace = StringUtils.getStackTrace(t);
}
public void setType(int type) {
this.type = type;
}
public void setTimeStamp(long timestamp) {
this.timestamp = timestamp;
}
public void setStackTrace(String stacktrace) {
this.stacktrace = stacktrace;
}
public void setName(String name) {
this.name = name;
}
public void setProperties(Properties props) {
this.props = props;
}
public int getType(){
return type;
}
public long getTimeStamp(){
return timestamp;
}
public String getName(){
return name;
}
public String getStackTrace(){
return stacktrace;
}
public Properties getProperties(){
return props;
}
public String toString(){
return "Id: " + source + ", Type: " + type;
}
}
1.1
jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunListener.java
Index: TestRunListener.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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", "Ant", 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 [EMAIL PROTECTED]
*
* 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.taskdefs.optional.junit.remote;
import java.util.EventListener;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public interface TestRunListener extends EventListener {
void onRunStarted(TestRunEvent evt);
void onRunEnded(TestRunEvent evt);
void onRunStopped(TestRunEvent evt);
void onSuiteStarted(TestRunEvent evt);
void onSuiteEnded(TestRunEvent evt);
void onTestStarted(TestRunEvent evt);
void onTestError(TestRunEvent evt);
void onTestFailure(TestRunEvent evt);
void onTestEnded(TestRunEvent evt);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>