Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5a32dd3c635fbcd0a7d61dd1f997b445416b813f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.core;

import java.io.File;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.junit.Assert;

public class CommandLineCVSClient implements ICVSClient {
	public static final ICVSClient INSTANCE = new CommandLineCVSClient();
	private static final String cvsExecutable =
		System.getProperty("eclipse.cvs.command");
		
	@Override
	public void executeCommand(ICVSRepositoryLocation repositoryLocation,
		IContainer localRoot, String command, String[] globalOptions,
		String[] localOptions, String[] arguments) throws CVSException {
		execute(repositoryLocation.getLocation(false), localRoot.getLocation().toFile(), command,
			globalOptions, localOptions, arguments);
		try {
			localRoot.refreshLocal(IResource.DEPTH_INFINITE, null);
		} catch (CoreException e) {
			throw new CVSClientException("CoreException during refreshLocal: " + e.getMessage());
		}
	}
	
	public static void execute(
		String repositoryLocation, File localRoot, String command,
		String[] globalOptions, String[] localOptions,
		String[] arguments) throws CVSException {
		// test arguments
		Assert.assertNotNull(repositoryLocation);
		Assert.assertNotNull(localRoot);
		Assert.assertNotNull(command);
		Assert.assertNotNull(globalOptions);
		Assert.assertNotNull(localOptions);
		Assert.assertNotNull(arguments);
		Assert.assertTrue(localRoot.exists());

		// build command line
		StringBuffer commandLineBuf = new StringBuffer(cvsExecutable);
		commandLineBuf.append(" -d \"");
		commandLineBuf.append(repositoryLocation);
		commandLineBuf.append('"');
		appendStrings(commandLineBuf, globalOptions);
		commandLineBuf.append(' ');
		commandLineBuf.append(command);
		appendStrings(commandLineBuf, localOptions);
		appendStrings(commandLineBuf, arguments);
		
		// execute command
		JUnitTestCase.waitMsec(1500);
		int returnCode = CVSTestSetup.executeCommand(commandLineBuf.toString(), null, localRoot);
		if (returnCode != 0) {
			throw new CVSClientException("Command line client returned non-zero code: " + returnCode);
		}
	}
		
	private static void appendStrings(StringBuffer commandLine, String[] strings) {	
		for (int i = 0; i < strings.length; i++) {
			String string = strings[i];
			if (string != null && string.length() != 0) {
				commandLine.append(" \"");
				commandLine.append(string);
				commandLine.append('"');
			}
		}
	}
}

Back to the top