01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html.
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.cli.command;
13:
14: import java.io.File;
15: import java.io.InputStream;
16: import java.io.PrintStream;
17: import java.text.DateFormat;
18: import java.text.SimpleDateFormat;
19: import java.util.Date;
20: import java.util.Locale;
21:
22: import org.tmatesoft.svn.cli.SVNArgument;
23: import org.tmatesoft.svn.cli.SVNCommand;
24: import org.tmatesoft.svn.core.SVNException;
25: import org.tmatesoft.svn.core.wc.SVNRevision;
26: import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
27:
28: /**
29: * @version 1.1.1
30: * @author TMate Software Ltd.
31: * @since 1.1.1
32: */
33: public class SVNLookDateCommand extends SVNCommand {
34: private static final DateFormat DATE_FORMAT = new SimpleDateFormat(
35: "yyyy-MM-dd HH:mm:ss Z (EE, d MMM yyyy)", Locale
36: .getDefault());
37:
38: public void run(PrintStream out, PrintStream err)
39: throws SVNException {
40: if (!getCommandLine().hasPaths()) {
41: SVNCommand.println(err,
42: "jsvnlook: Repository argument required");
43: System.exit(1);
44: }
45: File reposRoot = new File(getCommandLine().getPathAt(0));
46:
47: SVNRevision revision = SVNRevision.HEAD;
48: SVNLookClient lookClient = getClientManager().getLookClient();
49:
50: if (getCommandLine().hasArgument(SVNArgument.TRANSACTION)) {
51: String transactionName = (String) getCommandLine()
52: .getArgumentValue(SVNArgument.TRANSACTION);
53: Date date = lookClient
54: .doGetDate(reposRoot, transactionName);
55: String dateStamp = date != null ? formatDate(date) : "";
56: SVNCommand.println(out, dateStamp);
57: return;
58: } else if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
59: revision = SVNRevision.parse((String) getCommandLine()
60: .getArgumentValue(SVNArgument.REVISION));
61: }
62: Date date = lookClient.doGetDate(reposRoot, revision);
63: String dateStamp = date != null ? formatDate(date) : "";
64: SVNCommand.println(out, dateStamp);
65: }
66:
67: public void run(InputStream in, PrintStream out, PrintStream err)
68: throws SVNException {
69: run(out, err);
70: }
71:
72: public static String formatDate(Date date) {
73: return DATE_FORMAT.format(date);
74: }
75:
76: }
|