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
|
package org.eclipse.team.internal.ccvs.core.client;
/*
* (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.ccvs.core.ICVSFile;
import org.eclipse.team.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher;
/**
* The ImportStructureVisitor sends the content of the folder it is
* used on to the server. It constructs the locations of the resources
* because the resources do not yet have a remote-location.<br>
* Up to that it can ignore certain files and decides wether to send
* a file in binary or text mode due to a specification that is passed
* as a "wrapper" argument.
*/
class ImportStructureVisitor extends AbstractStructureVisitor {
private static final String KEYWORD_OPTION = "-k"; //$NON-NLS-1$
private static final String QUOTE = "'"; //$NON-NLS-1$
private String[] wrappers;
private FileNameMatcher ignoreMatcher;
private FileNameMatcher wrapMatcher;
/**
* Constructor for ImportStructureVisitor.
* @param requestSender
* @param mRoot
* @param monitor
*/
public ImportStructureVisitor(Session session,
String[] wrappers, IProgressMonitor monitor) {
super(session, monitor);
this.wrappers = wrappers;
wrapMatcher = initWrapMatcher(wrappers);
}
/**
* Inits the wrapMatcher, that is responsible to find out
* whether a file is to be send as a binary (on an import)
* or not.
*
* Takes wrappers of this format:
* *.class -k 'o'
*
* and inits the FileNameMatcher to give
* -ko back if you call it with match("somename.class")
*
* ignores all wrappers, that do not contain -k
*/
private FileNameMatcher initWrapMatcher(String[] wrappers) {
FileNameMatcher wrapMatcher;
if (wrappers == null) {
return null;
}
wrapMatcher = new FileNameMatcher();
for (int i = 0; i < wrappers.length; i++) {
if (wrappers[i].indexOf(KEYWORD_OPTION) == -1) {
continue;
}
StringTokenizer st = new StringTokenizer(wrappers[i]);
String pattern = st.nextToken();
String option = st.nextToken();
// get rid of the quotes
StringTokenizer quoteSt =
new StringTokenizer(st.nextToken(),QUOTE);
option += quoteSt.nextToken();
wrapMatcher.register(pattern,option);
}
return wrapMatcher;
}
/**
* @see ICVSResourceVisitor#visitFile(IManagedFile)
*/
public void visitFile(ICVSFile mFile) throws CVSException {
if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) {
return;
}
String mode;
if (wrapMatcher != null) {
mode = wrapMatcher.getMatch(mFile.getName());
} else {
mode = ""; //$NON-NLS-1$
}
boolean binary = mode != null && mode.indexOf(ResourceSyncInfo.BINARY_TAG) != -1;
session.sendModified(mFile, binary, monitor);
}
/**
* @see ICVSResourceVisitor#visitFolder(ICVSFolder)
*/
public void visitFolder(ICVSFolder mFolder) throws CVSException {
if (ignoreMatcher != null && ignoreMatcher.match(mFolder.getName())) {
return;
}
sendFolder(mFolder,true,false);
mFolder.acceptChildren(this);
}
}
|