001 /*
002 * UpdateEventHandler.java
003 * Copyright (c) 1998-2008, The University of Sheffield.
004 *
005 * This code is from the GATE project (http://gate.ac.uk/) and is free
006 * software licenced under the GNU General Public License version 3. It is
007 * distributed without any warranty. For more details see COPYING.txt in the
008 * top level directory (or at http://gatewiki.sf.net/COPYING.txt).
009 *
010 * Hamish Cunningham 8th January 2007
011 *
012 * Based on example code from SVNKit in the
013 * org.tmatesoft.svn.examples.wc
014 * package. Thanks TMate Software Ltd.
015 */
016 package gate.versioning.svnkit;
017
018 import org.tmatesoft.svn.core.wc.ISVNEventHandler;
019 import org.tmatesoft.svn.core.wc.SVNEvent;
020 import org.tmatesoft.svn.core.wc.SVNStatusType;
021 import org.tmatesoft.svn.core.wc.SVNEventAction;
022
023 import org.apache.log4j.Logger;
024
025 /*
026 * This class is an implementation of ISVNEventHandler intended for processing
027 * events generated by do*() methods of an SVNUpdateClient object. An instance
028 * of this handler will be provided to an SVNUpdateClient. When calling, for
029 * example, SVNWCClient.doUpdate(..) on some path, that method will generate an
030 * event for each 'update'/'add'/'delete'/.. action it will perform upon every
031 * path being updated. And this event is passed to
032 *
033 * ISVNEventHandler.handleEvent(SVNEvent event, double progress)
034 *
035 * to notify the handler. The event contains detailed information about the
036 * path, action performed upon the path and some other.
037 */
038 public class UpdateEventHandler extends SandboxCanceller implements ISVNEventHandler {
039 /** Logger. */
040 static Logger lgr = Logger.getLogger(UpdateEventHandler.class);
041
042 public UpdateEventHandler(Sandbox sandbox) {
043 super(sandbox);
044 }
045
046 /*
047 * progress is currently reserved for future purposes and now is always
048 * ISVNEventHandler.UNKNOWN
049 */
050 public void handleEvent(SVNEvent event, double progress) {
051 /*
052 * Gets the current action. An action is represented by SVNEventAction. In
053 * case of an update an action can be determined via comparing
054 * SVNEvent.getAction() and SVNEventAction.UPDATE_-like constants.
055 */
056 SVNEventAction action = event.getAction();
057 String pathChangeType = " ";
058 if(action == SVNEventAction.UPDATE_ADD) {
059 /*
060 * the item was added
061 */
062 pathChangeType = "A";
063 } else if(action == SVNEventAction.UPDATE_DELETE) {
064 /*
065 * the item was deleted
066 */
067 pathChangeType = "D";
068 } else if(action == SVNEventAction.UPDATE_UPDATE) {
069 /*
070 * Find out in details what state the item is (after having been updated).
071 *
072 * Gets the status of file/directory item contents. It is SVNStatusType
073 * who contains information on the state of an item.
074 */
075 SVNStatusType contentsStatus = event.getContentsStatus();
076 if(contentsStatus == SVNStatusType.CHANGED) {
077 /*
078 * the item was modified in the repository (got the changes from the
079 * repository
080 */
081 pathChangeType = "U";
082 } else if(contentsStatus == SVNStatusType.CONFLICTED) {
083 /*
084 * The file item is in a state of Conflict. That is, changes received
085 * from the repository during an update, overlap with local changes the
086 * user has in his working copy.
087 */
088 pathChangeType = "C";
089 } else if(contentsStatus == SVNStatusType.MERGED) {
090 /*
091 * The file item was merGed (those changes that came from the repository
092 * did not overlap local changes and were merged into the file).
093 */
094 pathChangeType = "G";
095 }
096 } else if(action == SVNEventAction.UPDATE_EXTERNAL) {
097 /* for externals definitions */
098 lgr.info("Fetching external item into '"
099 + event.getFile().getAbsolutePath() + "'");
100 lgr.info("External at revision " + event.getRevision());
101 return;
102 } else if(action == SVNEventAction.UPDATE_COMPLETED) {
103 /*
104 * Updating the working copy is completed. Prints out the revision.
105 */
106 lgr.info("At revision " + event.getRevision());
107 return;
108 } else if(action == SVNEventAction.ADD) {
109 lgr.info("A " + event.getFile().getPath());
110 return;
111 } else if(action == SVNEventAction.DELETE) {
112 lgr.info("D " + event.getFile().getPath());
113 return;
114 } else if(action == SVNEventAction.LOCKED) {
115 lgr.info("L " + event.getFile().getPath());
116 return;
117 } else if(action == SVNEventAction.LOCK_FAILED) {
118 lgr.info("failed to lock " + event.getFile().getPath());
119 return;
120 }
121 /*
122 * Now getting the status of properties of an item. SVNStatusType also
123 * contains information on the properties state.
124 */
125 SVNStatusType propertiesStatus = event.getPropertiesStatus();
126 /*
127 * At first consider properties are normal (unchanged).
128 */
129 String propertiesChangeType = " ";
130 if(propertiesStatus == SVNStatusType.CHANGED) {
131 /*
132 * Properties were updated.
133 */
134 propertiesChangeType = "U";
135 } else if(propertiesStatus == SVNStatusType.CONFLICTED) {
136 /*
137 * Properties are in conflict with the repository.
138 */
139 propertiesChangeType = "C";
140 } else if(propertiesStatus == SVNStatusType.MERGED) {
141 /*
142 * Properties that came from the repository were merged with the local
143 * ones.
144 */
145 propertiesChangeType = "G";
146 }
147 /*
148 * Gets the status of the lock.
149 */
150 String lockLabel = " ";
151 SVNStatusType lockType = event.getLockStatus();
152 if(lockType == SVNStatusType.LOCK_UNLOCKED) {
153 /*
154 * The lock is broken by someone.
155 */
156 lockLabel = "B";
157 }
158 lgr.info(pathChangeType + propertiesChangeType + lockLabel
159 + " " + event.getFile().getPath());
160 }
161 }
|