package com.perforce.reviewer; /** * Perforce Reviewer. * * Requires JavaMail and Activation packages from Sun. When you have these, * make sure mail.jar and activation.jar are on your CLASSPATH as well as * p4.jar. * * @author <a href="mailto:david@markley.cc">David Markley</a> * @version $Date: 2002/01/11 $ $Revision: #2 $ */ import java.util.*; import java.io.*; import com.perforce.api.*; public class Reviewer extends Thread { private Env env; private Counter cntr; private Hashtable user_listeners = null; private Vector listeners = null; private ChangeListener default_listener = null; /** * Constructor. */ public Reviewer(Env env) { this(env, env.getProperty("p4.counter","review")); } public Reviewer(Env env, String counter) { super(); this.env = env; this.cntr = new Counter(env, counter); this.user_listeners = new Hashtable(); this.listeners = new Vector(); this.default_listener = new MailListener(env); } /** * Adds a change listner associated with a particular user. When this * user appears on the reviews list for a change, the ChangeListener's * handleChange() method is invoked with the current Env and Change. The * User array passed to handleChange() is set to null. */ public void addUserListener(String user, ChangeListener listener) { if (null == user || null == listener) return; user_listeners.put(user, listener); } /** * Adds a change listner that will review every change. This ChangeListener's * handleChange() method will alway be invoked with the current Env, Change, * and list of reviewing users that that have not had a specific * ChangeListener added for them using the addUserListener method. * <p/> * There is a built-in listener that is set up as the default upon * instantiating this class. This listener will send e-mail to the list * of users. */ public void addDefaultUserListener(ChangeListener listener) { this.default_listener = listener; } /** * Adds a change listner that will review every change. This ChangeListener's * handleChange() method will alway be invoked with the current Env, Change, * and list of reviewing users that have nod had a specific * ChangeListener added for them using the addUserListener method. */ public void addChangeListener(ChangeListener listener) { if (null == listener) return; listeners.addElement(listener); } /** * Check the counter every five seconds. */ public void run() { while (true) { checkCounter(); try { sleep(5000); } catch (InterruptedException iex) { /* don't care */ } } } /** * Notify users about the change. */ private void notifyUsers(Change chng, User[] usrs) { Vector v_users = new Vector(); ChangeListener l = null; Enumeration en; for (int i = 0; i < usrs.length; i++) { l = (ChangeListener)user_listeners.get(usrs[i].getId()); if (null == l) { v_users.addElement(usrs[i]); } else { l.handleChange(env, chng, null); } } User[] a_users = new User[v_users.size()]; for (int i = 0; i < v_users.size(); i++) { a_users[i] = (User)v_users.elementAt(i); } if (null != default_listener) { default_listener.handleChange(env, chng, a_users); } en = listeners.elements(); while (en.hasMoreElements()) { l = (ChangeListener)en.nextElement(); l.handleChange(env, chng, a_users); } } /** * Check to see if the counter has changed and who reviews the change. */ private void checkCounter() { Change[] chngs; User[] usrs; int i, j, max = 0; try { chngs = cntr.review(); for (i = 0; i < chngs.length; i++) { System.out.println("Reviewing change: "+chngs[i].getNumber()); if (max < chngs[i].getNumber()) max = chngs[i].getNumber(); usrs = chngs[i].reviews(); if (null != usrs) notifyUsers(chngs[i], usrs); } } catch (Exception ex) { /* Print out the exception, but don't stop the reviewer! */ ex.printStackTrace(); } if (0 < max) { cntr.setValue(max); try { cntr.commit(); } catch (PerforceException pex) { /* If the counter can not be set, die an ugly death. */ /* It's better to die, then to spam users with e-mail. */ System.err.println("Reviewer: Could not set the counter!"); System.exit(-1); } } } public static void main(String[] argv) { /* Debug.setDebugLevel(Debug.VERBOSE); Debug.setLogLevel(Debug.LOG_SPLIT); */ Env env = null; try { env = new Env(argv[0]); env.checkValidity(); } catch (PerforceException ex) { ex.printStackTrace(); System.exit(-1); } System.out.println(env); Reviewer r = new Reviewer(env); r.start(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 2019 | David Markley | Corrected listing of affected files in the reviewer. | ||
#6 | 1670 | David Markley |
Completed the user documentation in preperation for the public depot. Includes example configuration for the Java Reviewer. |
||
#5 | 1642 | David Markley |
Corrected the Utils.wildPathMatch method so that it matches all wildcards properly. Added the extensible reviewer. |
||
#4 | 1633 | David Markley | Not sure why Java's Vector.toArray() method does not work properly. | ||
#3 | 1632 | David Markley | Added ChangeListener interface for more flexability. | ||
#2 | 1381 | David Markley | Corrected a serious defect in the FileEntry.parseFstat method. | ||
#1 | 1368 | David Markley |
Needed access to the Properties within the Env for the Reviewer. Moved things around to create the com.perforce.reviewer package. |