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.SVNCancelException;
021: import org.tmatesoft.svn.core.SVNException;
022: import org.tmatesoft.svn.core.wc.SVNEvent;
023: import org.tmatesoft.svn.core.wc.admin.ISVNAdminEventHandler;
024: import org.tmatesoft.svn.core.wc.admin.SVNAdminClient;
025: import org.tmatesoft.svn.core.wc.admin.SVNAdminEvent;
026: import org.tmatesoft.svn.core.wc.admin.SVNAdminEventAction;
027: import org.tmatesoft.svn.core.wc.admin.SVNUUIDAction;
028:
029: /**
030: * @version 1.1.1
031: * @author TMate Software Ltd.
032: * @since 1.1.1
033: */
034: public class SVNAdminLoadCommand extends SVNCommand implements
035: ISVNAdminEventHandler {
036: private boolean myIsQuiet;
037: private PrintStream myOut;
038: private boolean myIsNodeOpened;
039:
040: public void run(PrintStream out, PrintStream err)
041: throws SVNException {
042: run(System.in, out, err);
043: }
044:
045: public void run(InputStream in, PrintStream out, PrintStream err)
046: throws SVNException {
047: if (!getCommandLine().hasPaths()) {
048: SVNCommand.println(out,
049: "jsvnadmin: Repository argument required");
050: System.exit(1);
051: }
052: File reposRoot = new File(getCommandLine().getPathAt(0));
053:
054: boolean ignoreUUID = getCommandLine().hasArgument(
055: SVNArgument.IGNORE_UUID);
056: boolean forceUUID = getCommandLine().hasArgument(
057: SVNArgument.FORCE_UUID);
058: SVNUUIDAction uuidAction = null;
059: if (!ignoreUUID && !forceUUID) {
060: uuidAction = SVNUUIDAction.DEFAULT;
061: } else if (ignoreUUID) {
062: uuidAction = SVNUUIDAction.IGNORE_UUID;
063: } else {
064: uuidAction = SVNUUIDAction.FORCE_UUID;
065: }
066:
067: boolean usePreCommitHook = getCommandLine().hasArgument(
068: SVNArgument.USE_PRECOMMIT_HOOK);
069: boolean usePostCommitHook = getCommandLine().hasArgument(
070: SVNArgument.USE_POSTCOMMIT_HOOK);
071: String parentDir = (String) getCommandLine().getArgumentValue(
072: SVNArgument.PARENT_DIR);
073:
074: myIsQuiet = getCommandLine().hasArgument(SVNArgument.QUIET);
075: myOut = out;
076:
077: SVNAdminClient adminClient = getClientManager()
078: .getAdminClient();
079: adminClient.setEventHandler(this );
080: adminClient.doLoad(reposRoot, in, usePreCommitHook,
081: usePostCommitHook, uuidAction, parentDir);
082: }
083:
084: public void handleAdminEvent(SVNAdminEvent event, double progress)
085: throws SVNException {
086: if (!myIsQuiet && event != null) {
087: if (event.getAction() != SVNAdminEventAction.REVISION_LOAD
088: && myIsNodeOpened) {
089: myOut.println(" done.");
090: myIsNodeOpened = false;
091: }
092: if (event.getAction() == SVNAdminEventAction.REVISION_LOADED) {
093: myOut.println();
094: }
095: myOut.println(event.getMessage());
096: if (event.getAction() == SVNAdminEventAction.REVISION_LOADED) {
097: myOut.println();
098: }
099: myIsNodeOpened = event.getAction() != SVNAdminEventAction.REVISION_LOAD;
100: }
101: }
102:
103: public void handleEvent(SVNEvent event, double progress)
104: throws SVNException {
105: }
106:
107: public void checkCancelled() throws SVNCancelException {
108: }
109: }
|