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.cli.command;
013:
014: import java.io.File;
015: import java.io.InputStream;
016: import java.io.PrintStream;
017:
018: import org.tmatesoft.svn.cli.SVNCommand;
019: import org.tmatesoft.svn.core.SVNCancelException;
020: import org.tmatesoft.svn.core.SVNException;
021: import org.tmatesoft.svn.core.SVNLock;
022: import org.tmatesoft.svn.core.internal.util.SVNTimeUtil;
023: import org.tmatesoft.svn.core.wc.SVNEvent;
024: import org.tmatesoft.svn.core.wc.admin.ISVNAdminEventHandler;
025: import org.tmatesoft.svn.core.wc.admin.SVNAdminClient;
026: import org.tmatesoft.svn.core.wc.admin.SVNAdminEvent;
027: import org.tmatesoft.svn.core.wc.admin.SVNAdminEventAction;
028:
029: /**
030: * @version 1.1.2
031: * @author TMate Software Ltd.
032: * @since 1.1.2
033: */
034: public class SVNAdminListLocksCommand extends SVNCommand implements
035: ISVNAdminEventHandler {
036: private PrintStream myOut;
037:
038: public void run(PrintStream out, PrintStream err)
039: throws SVNException {
040: if (!getCommandLine().hasPaths()) {
041: SVNCommand.println(out,
042: "svnadmin: Repository argument required");
043: System.exit(1);
044: }
045: File reposRoot = new File(getCommandLine().getPathAt(0));
046:
047: myOut = out;
048: SVNAdminClient adminClient = getClientManager()
049: .getAdminClient();
050: adminClient.setEventHandler(this );
051: adminClient.doListLocks(reposRoot);
052:
053: }
054:
055: public void run(InputStream in, PrintStream out, PrintStream err)
056: throws SVNException {
057: run(out, err);
058: }
059:
060: public void handleAdminEvent(SVNAdminEvent event, double progress)
061: throws SVNException {
062: if (event != null
063: && event.getAction() == SVNAdminEventAction.LOCK_LISTED) {
064: SVNLock lock = event.getLock();
065: if (lock != null) {
066: String creationDate = SVNTimeUtil.formatDate(lock
067: .getCreationDate());
068: String expirationDate = lock.getExpirationDate() != null ? SVNTimeUtil
069: .formatDate(lock.getExpirationDate())
070: : "";
071:
072: int commentLines = 0;
073: if (lock.getComment() != null) {
074: commentLines = getLinesCount(lock.getComment());
075: }
076:
077: SVNCommand.println(myOut, "Path: " + lock.getPath());
078: SVNCommand
079: .println(myOut, "UUID Token: " + lock.getID());
080: SVNCommand.println(myOut, "Owner: " + lock.getOwner());
081: SVNCommand.println(myOut, "Created: " + creationDate);
082: SVNCommand.println(myOut, "Expires: " + expirationDate);
083: if (commentLines != 1) {
084: SVNCommand.println(myOut, "Comment ("
085: + commentLines + " lines):");
086: SVNCommand.println(myOut,
087: lock.getComment() != null ? lock
088: .getComment() : "");
089: } else {
090: SVNCommand.println(myOut, "Comment ("
091: + commentLines + " line):");
092: SVNCommand.println(myOut,
093: lock.getComment() != null ? lock
094: .getComment() : "");
095: }
096: SVNCommand.println(myOut, "");
097: }
098: }
099: }
100:
101: public void checkCancelled() throws SVNCancelException {
102: }
103:
104: public void handleEvent(SVNEvent event, double progress)
105: throws SVNException {
106: }
107:
108: }
|