Skip to main content
summaryrefslogtreecommitdiffstats
blob: bffa517a125a4c6511dd1c9b140dc6b45337fe7d (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.eclipse.team.internal.ccvs.core.client.listeners;

/*
 * (c) Copyright IBM Corp. 2000, 2002.
 * All Rights Reserved.
 */
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.team.internal.ccvs.core.client.Checkout;
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;

/*
 * This class pares the output of the "cvs checkout -c" command which returns the list of modules 
 * defined in the CVSROOT/modules file.
 */
public class ModuleDefinitionsListener implements ICommandOutputListener {

	// the last line read from the context (used to accumulate multi-line definitions)
	private String lastLine = "";
	
	private Map moduleMap;
	
	public ModuleDefinitionsListener() {
		reset();
	}
	
	/*
	 * @see ICommandOutputListener#messageLine(String, ICVSFolder, IProgressMonitor)
	 */
	public IStatus messageLine(
		String line,
		ICVSFolder commandRoot,
		IProgressMonitor monitor) {
		
		// Lines that start with a space indicate a multi line entry
		if( line.charAt(0) == ' ' ) {
			lastLine += line;
			line = lastLine;
		}
		else
			lastLine = line;
		
		StringTokenizer tokenizer = new StringTokenizer(line);
		
		String module = tokenizer.nextToken();
		
		List expansions = new ArrayList(10);
		
		// Read the options associated with the module
		List localOptionsList = new ArrayList();
		String next = tokenizer.nextToken();
		while (next.charAt(0) == '-') {
			switch (next.charAt(1)) {
				case 'a': // alias
					localOptionsList.add(Checkout.ALIAS);
					break;
				case 'l': // don't recurse
					localOptionsList.add(Checkout.DO_NOT_RECURSE);
					break;
				case 'd': // directory
					localOptionsList.add(Checkout.makeDirectoryNameOption(tokenizer.nextToken()));
					break;
				case 'e':
				case 'i':
				case 'o':
				case 't':
				case 'u': // Ignore any programs
					tokenizer.nextToken();
					break;
				case 's': // status
					localOptionsList.add(Checkout.makeStatusOption(tokenizer.nextToken()));
					break;
				default: // unanticipated option. Ignore it and go on
			}
			next = tokenizer.nextToken();
		}
		LocalOption[] localOptions = (LocalOption[]) localOptionsList.toArray(new LocalOption[localOptionsList.size()]);
		
		if (Checkout.ALIAS.isElementOf(localOptions)) {
			// An alias expands to one or more projects or modules
			expansions.add(next);
			while (tokenizer.hasMoreTokens())
				expansions.add(tokenizer.nextToken());
		} else {
			// The module definition can have a leading directory followed by some files
			if (!(next.charAt(0) == '&')) {
				String directory = next;
				List files = new ArrayList();
				while (tokenizer.hasMoreTokens() && (next.charAt(0) != '&')) {
					next = tokenizer.nextToken() ;
					if ((next.charAt(0) != '&'))
						files.add(next);
				}
				if (files.size() > 0) {
					for (int i=0;i<files.size();i++)
						expansions.add(directory + "/" + (String)files.get(i));
				}
				else
					expansions.add(directory);
			} 
			// It can also have one or more module references
			if (next.charAt(0) == '&') {
				expansions.add(next);
				while (tokenizer.hasMoreTokens())
					expansions.add(tokenizer.nextToken());
			}
		}
		moduleMap.put(module, new ModuleExpansion(module, (String[])expansions.toArray(new String[expansions.size()]), localOptions));
		return OK;
	}

	/*
	 * @see ICommandOutputListener#errorLine(String, ICVSFolder, IProgressMonitor)
	 */
	public IStatus errorLine(
		String line,
		ICVSFolder commandRoot,
		IProgressMonitor monitor) {
			
		// XXX We should get any errors!!!
		return OK;
	}
	
	public ModuleExpansion[] getModuleExpansions() {
		return (ModuleExpansion[])moduleMap.values().toArray(new ModuleExpansion[moduleMap.size()]);
	}

	public void reset() {
		this.moduleMap = new HashMap();
	}
}

Back to the top