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:
013: package org.tmatesoft.svn.cli.command;
014:
015: import java.io.File;
016: import java.io.IOException;
017: import java.io.InputStream;
018: import java.io.PrintStream;
019:
020: import org.tmatesoft.svn.cli.SVNArgument;
021: import org.tmatesoft.svn.cli.SVNCommand;
022: import org.tmatesoft.svn.cli.SVNCommandLine;
023: import org.tmatesoft.svn.cli.SVNCommandStatusHandler;
024: import org.tmatesoft.svn.core.SVNException;
025: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
026: import org.tmatesoft.svn.core.internal.wc.SVNFileType;
027: import org.tmatesoft.svn.core.wc.ISVNStatusHandler;
028: import org.tmatesoft.svn.core.wc.SVNStatusClient;
029: import org.tmatesoft.svn.core.wc.SVNWCUtil;
030: import org.tmatesoft.svn.core.wc.xml.SVNXMLSerializer;
031: import org.tmatesoft.svn.core.wc.xml.SVNXMLStatusHandler;
032:
033: /**
034: * @version 1.1.1
035: * @author TMate Software Ltd.
036: */
037: public class SVNStatusCommand extends SVNCommand {
038:
039: public void run(InputStream in, PrintStream out, PrintStream err)
040: throws SVNException {
041: run(out, err);
042: }
043:
044: public void run(PrintStream out, PrintStream err)
045: throws SVNException {
046: SVNCommandLine line = getCommandLine();
047: boolean isEmpty = true;
048: String paths[] = new String[line.getPathCount()];
049: for (int i = 0; i < line.getPathCount(); i++) {
050: paths[i] = line.getPathAt(i).trim();
051: }
052: for (int i = 0; i < paths.length; i++) {
053: String path = paths[i];
054: File validatedPath = new File(SVNPathUtil
055: .validateFilePath(new File(path).getAbsolutePath()));
056: if (SVNFileType.getType(validatedPath) == SVNFileType.DIRECTORY
057: && !SVNWCUtil.isVersionedDirectory(validatedPath)
058: && !SVNWCUtil.isVersionedDirectory(validatedPath
059: .getParentFile())) {
060: err.println("svn: warning: '" + path
061: + "' is not a working copy");
062: paths[i] = null;
063: continue;
064: } else if (SVNFileType.getType(validatedPath) == SVNFileType.DIRECTORY
065: && !SVNWCUtil.isVersionedDirectory(validatedPath)
066: && "..".equals(path)) {
067: err.println("svn: warning: '" + path
068: + "' is not a working copy");
069: paths[i] = null;
070: continue;
071: } else if ("..".equals(path)) {
072: // hack for status test #2!
073: isEmpty = false;
074: paths[i] = "..";
075: continue;
076: }
077: paths[i] = validatedPath.getAbsolutePath();
078: isEmpty = false;
079: }
080: if (isEmpty) {
081: return;
082: }
083:
084: boolean showUpdates = getCommandLine().hasArgument(
085: SVNArgument.SHOW_UPDATES);
086: if (getCommandLine().getPathCount() == 0) {
087: getCommandLine().setPathAt(0, ".");
088: }
089: boolean recursive = !getCommandLine().hasArgument(
090: SVNArgument.NON_RECURSIVE);
091: boolean reportAll = getCommandLine().hasArgument(
092: SVNArgument.VERBOSE);
093: boolean ignored = getCommandLine().hasArgument(
094: SVNArgument.NO_IGNORE);
095: boolean quiet = getCommandLine().hasArgument(SVNArgument.QUIET);
096:
097: if (!getCommandLine().hasArgument(SVNArgument.XML)) {
098: getClientManager().setEventHandler(
099: new SVNCommandEventProcessor(out, err, false));
100: }
101: SVNStatusClient stClient = getClientManager().getStatusClient();
102: ISVNStatusHandler handler = new SVNCommandStatusHandler(out,
103: reportAll || showUpdates, reportAll, quiet, showUpdates);
104: SVNXMLSerializer serializer;
105: serializer = getCommandLine().hasArgument(SVNArgument.XML) ? new SVNXMLSerializer(
106: System.out)
107: : null;
108: if (serializer != null) {
109: handler = new SVNXMLStatusHandler(serializer);
110: if (!getCommandLine().hasArgument(SVNArgument.INCREMENTAL)) {
111: ((SVNXMLStatusHandler) handler).startDocument();
112: }
113: }
114: boolean error = false;
115: for (int i = 0; i < paths.length; i++) {
116: String path = paths[i];
117: if (path == null) {
118: continue;
119: }
120: File file = new File(path).getAbsoluteFile();
121: if (serializer != null) {
122: ((SVNXMLStatusHandler) handler).startTarget(new File(
123: getCommandLine().getPathAt(i)));
124: }
125: long rev = -1;
126: try {
127: rev = stClient.doStatus(file, recursive, showUpdates,
128: reportAll, ignored, handler);
129: } catch (SVNException e) {
130: stClient.getDebugLog().info(e);
131: err.println(e.getMessage());
132: error = true;
133: }
134: if (serializer != null) {
135: ((SVNXMLStatusHandler) handler).endTarget(rev);
136: }
137: }
138: if (serializer != null) {
139: if (!getCommandLine().hasArgument(SVNArgument.INCREMENTAL)) {
140: ((SVNXMLStatusHandler) handler).endDocument();
141: }
142: try {
143: serializer.flush();
144: } catch (IOException e) {
145: }
146: }
147: if (error) {
148: System.exit(1);
149: }
150: }
151: }
|