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.SVNArgument;
019: import org.tmatesoft.svn.cli.SVNCommand;
020: import org.tmatesoft.svn.core.SVNException;
021: import org.tmatesoft.svn.core.internal.io.fs.FSFS;
022: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
023: import org.tmatesoft.svn.core.internal.wc.SVNAdminHelper;
024: import org.tmatesoft.svn.core.wc.SVNRevision;
025: import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
026:
027: /**
028: * @version 1.1.1
029: * @author TMate Software Ltd.
030: * @since 1.1.1
031: */
032: public class SVNLookPropgetCommand extends SVNCommand {
033:
034: public void run(PrintStream out, PrintStream err)
035: throws SVNException {
036: if (!getCommandLine().hasPaths()) {
037: SVNCommand.println(err,
038: "jsvnlook: Repository argument required");
039: System.exit(1);
040: }
041:
042: boolean isRevProp = getCommandLine().hasArgument(
043: SVNArgument.REV_PROP);
044: File reposRoot = new File(getCommandLine().getPathAt(0));
045: String propertyName = getCommandLine().getPathCount() < 2 ? null
046: : getCommandLine().getPathAt(1);
047: SVNRevision revision = SVNRevision.HEAD;
048: SVNLookClient lookClient = getClientManager().getLookClient();
049:
050: if (getCommandLine().hasArgument(SVNArgument.TRANSACTION)) {
051: String transactionName = (String) getCommandLine()
052: .getArgumentValue(SVNArgument.TRANSACTION);
053: String path = null;
054: String value = null;
055: if (isRevProp) {
056: value = lookClient.doGetRevisionProperty(reposRoot,
057: propertyName, transactionName);
058: } else {
059: path = getCommandLine().getPathCount() < 3 ? null
060: : SVNPathUtil
061: .canonicalizeAbsPath(getCommandLine()
062: .getPathAt(2));
063: value = lookClient.doGetProperty(reposRoot,
064: propertyName, path, transactionName);
065: }
066: if (value == null) {
067: if (path == null) {
068: SVNCommand.println(err, "Property '" + propertyName
069: + "' not found on transaction '"
070: + transactionName + "'");
071: System.exit(1);
072: } else {
073: SVNCommand.println(err, "Property '" + propertyName
074: + "' not found on path '" + path
075: + "' in transaction '" + transactionName
076: + "'");
077: System.exit(1);
078: }
079: }
080: SVNCommand.print(out, value);
081: return;
082: } else if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
083: revision = SVNRevision.parse((String) getCommandLine()
084: .getArgumentValue(SVNArgument.REVISION));
085: }
086:
087: String path = null;
088: String value = null;
089: if (isRevProp) {
090: value = lookClient.doGetRevisionProperty(reposRoot,
091: propertyName, revision);
092: } else {
093: path = getCommandLine().getPathCount() < 3 ? null
094: : SVNPathUtil.canonicalizeAbsPath(getCommandLine()
095: .getPathAt(2));
096: value = lookClient.doGetProperty(reposRoot, propertyName,
097: path, revision);
098: }
099: if (value == null) {
100: long revNum = -1;
101: if (SVNRevision.isValidRevisionNumber(revision.getNumber())) {
102: revNum = revision.getNumber();
103: } else {
104: FSFS fsfs = SVNAdminHelper.openRepository(reposRoot);
105: revNum = SVNAdminHelper.getRevisionNumber(revision,
106: fsfs.getYoungestRevision(), fsfs);
107: }
108: if (path == null) {
109: SVNCommand.println(err, "Property '" + propertyName
110: + "' not found on revision " + revNum);
111: System.exit(1);
112: } else {
113: SVNCommand.println(err, "Property '" + propertyName
114: + "' not found on path '" + path
115: + "' in revision " + revNum);
116: System.exit(1);
117: }
118: }
119: SVNCommand.print(out, value);
120: }
121:
122: public void run(InputStream in, PrintStream out, PrintStream err)
123: throws SVNException {
124: run(out, err);
125: }
126:
127: }
|