Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f1b7917a0403ec6c64fda6930c3403f9a9c3eb1b (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
package org.eclipse.team.tests.ccvs.core;

import java.io.File;

import junit.framework.Assert;
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;

public class CommandLineCVSClient implements ICVSClient {
	public static final ICVSClient INSTANCE = new CommandLineCVSClient();
	private static final String cvsExecutable =
		System.getProperty("eclipse.cvs.command");
		
	public void executeCommand(ICVSRepositoryLocation repositoryLocation,
		IContainer localRoot, String command, String[] globalOptions,
		String[] localOptions, String[] arguments) throws CVSException {
		execute(repositoryLocation.getLocation(), 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