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.util.SVNPathUtil;
022: import org.tmatesoft.svn.core.wc.SVNRevision;
023: import org.tmatesoft.svn.core.wc.admin.ISVNTreeHandler;
024: import org.tmatesoft.svn.core.wc.admin.SVNAdminPath;
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 SVNLookTreeCommand extends SVNCommand implements
033: ISVNTreeHandler {
034: private PrintStream myOut;
035: private boolean myIsIncludeIDs;
036: private boolean myIsFullPaths;
037:
038: public void run(PrintStream out, PrintStream err)
039: throws SVNException {
040: if (!getCommandLine().hasPaths()) {
041: SVNCommand.println(err,
042: "jsvnlook: Repository argument required");
043: System.exit(1);
044: }
045:
046: myOut = out;
047: myIsIncludeIDs = getCommandLine().hasArgument(
048: SVNArgument.SHOW_IDS);
049: myIsFullPaths = getCommandLine().hasArgument(
050: SVNArgument.FULL_PATHS);
051: File reposRoot = new File(getCommandLine().getPathAt(0));
052: String path = getCommandLine().getPathCount() < 2 ? null
053: : SVNPathUtil.canonicalizeAbsPath(getCommandLine()
054: .getPathAt(1));
055: SVNRevision revision = SVNRevision.HEAD;
056: SVNLookClient lookClient = getClientManager().getLookClient();
057: if (getCommandLine().hasArgument(SVNArgument.TRANSACTION)) {
058: String transactionName = (String) getCommandLine()
059: .getArgumentValue(SVNArgument.TRANSACTION);
060: lookClient.doGetTree(reposRoot, path, transactionName,
061: myIsIncludeIDs, this );
062: return;
063: } else if (getCommandLine().hasArgument(SVNArgument.REVISION)) {
064: revision = SVNRevision.parse((String) getCommandLine()
065: .getArgumentValue(SVNArgument.REVISION));
066: }
067: lookClient.doGetTree(reposRoot, path, revision, myIsIncludeIDs,
068: this );
069: }
070:
071: public void run(InputStream in, PrintStream out, PrintStream err)
072: throws SVNException {
073: run(out, err);
074: }
075:
076: public void handlePath(SVNAdminPath adminPath) throws SVNException {
077: if (adminPath != null) {
078: String indentation = null;
079: if (!myIsFullPaths) {
080: indentation = "";
081: for (int i = 0; i < adminPath.getTreeDepth(); i++) {
082: indentation += " ";
083: }
084: }
085:
086: String path = adminPath.getPath();
087: if (myIsFullPaths) {
088: path = path.startsWith("/") && !"/".equals(path) ? path
089: .substring(1) : path;
090: if (adminPath.isDir() && !"/".equals(path)
091: && !path.endsWith("/")) {
092: path += "/";
093: }
094: SVNCommand.print(myOut, path);
095: } else {
096: path = !"/".equals(path) ? SVNPathUtil.tail(path)
097: : path;
098: if (adminPath.isDir() && !"/".equals(path)
099: && !path.endsWith("/")) {
100: path += "/";
101: }
102: SVNCommand.print(myOut, indentation + path);
103: }
104:
105: if (myIsIncludeIDs) {
106: SVNCommand.print(myOut, " <"
107: + (adminPath.getNodeID() != null ? adminPath
108: .getNodeID() : "unknown") + ">");
109: }
110: SVNCommand.println(myOut, "");
111: }
112: }
113:
114: }
|