01 /*
02 * CommitEventHandler.java
03 * Copyright (c) 1998-2008, The University of Sheffield.
04 *
05 * This code is from the GATE project (http://gate.ac.uk/) and is free
06 * software licenced under the GNU General Public License version 3. It is
07 * distributed without any warranty. For more details see COPYING.txt in the
08 * top level directory (or at http://gatewiki.sf.net/COPYING.txt).
09 *
10 * Hamish Cunningham 8th January 2007
11 *
12 * Based on example code from SVNKit in the
13 * org.tmatesoft.svn.examples.wc
14 * package. Thanks TMate Software Ltd.
15 */
16 package gate.versioning.svnkit;
17
18 import org.tmatesoft.svn.core.SVNProperty;
19 import org.tmatesoft.svn.core.wc.ISVNEventHandler;
20 import org.tmatesoft.svn.core.wc.SVNEvent;
21 import org.tmatesoft.svn.core.wc.SVNEventAction;
22
23 import org.apache.log4j.Logger;
24
25 /*
26 * This class is an implementation of ISVNEventHandler intended for processing
27 * events generated by do*() methods of an SVNCommitClient object. An instance
28 * of this handler will be provided to an SVNCommitClient. When calling, for
29 * example, SVNCommitClient.doCommit(..) on a WC path, this method will generate
30 * an event for each 'adding'/'deleting'/'sending'/.. action it will perform
31 * upon every path being committed. And this event is passed to
32 *
33 * ISVNEventHandler.handleEvent(SVNEvent event, double progress)
34 *
35 * to notify the handler. The event contains detailed information about the
36 * path, action performed upon the path and some other.
37 */
38 public class CommitEventHandler extends SandboxCanceller implements ISVNEventHandler {
39 /** Logger. */
40 static Logger lgr = Logger.getLogger(CommitEventHandler.class);
41
42 public CommitEventHandler(Sandbox sandbox) {
43 super(sandbox);
44 }
45
46 /*
47 * progress is currently reserved for future purposes and now is always
48 * ISVNEventHandler.UNKNOWN
49 */
50 public void handleEvent(SVNEvent event, double progress) {
51 /*
52 * Gets the current action. An action is represented by SVNEventAction. In
53 * case of a commit an action can be determined via comparing
54 * SVNEvent.getAction() with SVNEventAction.COMMIT_-like constants.
55 */
56 SVNEventAction action = event.getAction();
57 if(action == SVNEventAction.COMMIT_MODIFIED) {
58 lgr.info("Sending " + event.getFile().getPath());
59 } else if(action == SVNEventAction.COMMIT_DELETED) {
60 lgr.info("Deleting " + event.getFile().getPath());
61 } else if(action == SVNEventAction.COMMIT_REPLACED) {
62 lgr.info("Replacing " + event.getFile().getPath());
63 } else if(action == SVNEventAction.COMMIT_DELTA_SENT) {
64 lgr.info("Transmitting file data....");
65 } else if(action == SVNEventAction.COMMIT_ADDED) {
66 /*
67 * Gets the MIME-type of the item.
68 */
69 String mimeType = event.getMimeType();
70 if(SVNProperty.isBinaryMimeType(mimeType)) {
71 /*
72 * If the item is a binary file
73 */
74 lgr.info("Adding (bin) " + event.getFile().getPath());
75 } else {
76 lgr.info("Adding " + event.getFile().getPath());
77 }
78 }
79 }
80 }
|