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