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;
13:
14: import java.io.File;
15: import java.util.HashSet;
16: import java.util.Set;
17:
18: import org.tmatesoft.svn.core.SVNException;
19: import org.tmatesoft.svn.core.wc.SVNClientManager;
20: import org.tmatesoft.svn.util.SVNDebugLog;
21:
22: /**
23: * @version 1.1.1
24: * @author TMate Software Ltd.
25: * @since 1.1.1
26: */
27: public class SVNVersion {
28:
29: private static final Set ourArguments;
30:
31: public static final SVNArgument NO_NEW_LINE = SVNArgument
32: .createUnaryArgument(new String[] { "--no-newline", "-n" });
33: public static final SVNArgument COMMITTED = SVNArgument
34: .createUnaryArgument(new String[] { "--committed", "-c" });
35:
36: static {
37: ourArguments = new HashSet();
38: ourArguments.add(NO_NEW_LINE);
39: ourArguments.add(COMMITTED);
40: }
41:
42: public static void main(String[] args) {
43: if (args == null) {
44: System.err
45: .println("usage: jsvnversion [OPTIONS] [WC_PATH [TRAIL_URL]]");
46: System.exit(1);
47: }
48: SVNCommandLine commandLine = null;
49: try {
50: try {
51: commandLine = new SVNCommandLine(args, ourArguments);
52: } catch (SVNException e) {
53: SVNDebugLog.getDefaultLog().info(e);
54: System.err.println(e.getMessage());
55: System.exit(1);
56: }
57: File dir = new File("").getAbsoluteFile();
58: String path = commandLine.getCommandName();
59: if (path != null) {
60: dir = new File(path).getAbsoluteFile();
61: }
62: String trailURL = commandLine.getPathCount() > 0 ? commandLine
63: .getPathAt(0)
64: : null;
65: String id = SVNClientManager.newInstance().getWCClient()
66: .doGetWorkingCopyID(dir, trailURL,
67: commandLine.hasArgument(COMMITTED));
68: if (id != null) {
69: System.out.print(id);
70: if (!commandLine.hasArgument(NO_NEW_LINE)) {
71: System.out.println();
72: }
73: } else {
74: System.err.println("svn: '" + dir.getAbsolutePath()
75: + "' does not exist");
76: System.exit(1);
77: }
78: } catch (SVNException e) {
79: System.err.println(e.getMessage());
80: SVNDebugLog.getDefaultLog().info(e);
81: System.exit(1);
82: } catch (Throwable th) {
83: SVNDebugLog.getDefaultLog().info(th);
84: System.exit(-1);
85: }
86: System.exit(0);
87: }
88:
89: }
|