1 package org.apache.maven.scm;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28
29 import org.apache.maven.scm.command.add.AddScmResult;
30 import org.apache.maven.scm.command.checkin.CheckInScmResult;
31 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
32 import org.apache.maven.scm.command.edit.EditScmResult;
33 import org.apache.maven.scm.provider.ScmProvider;
34 import org.apache.maven.scm.repository.ScmRepository;
35 import org.codehaus.plexus.util.StringUtils;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public abstract class ScmTckTestCase
52 extends ScmTestCase
53 {
54 private ScmRepository scmRepository;
55
56 private List<String> scmFileNames;
57
58
59
60
61
62 public abstract String getScmUrl()
63 throws Exception;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 protected List<String> getScmFileNames()
79 {
80 return scmFileNames;
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public abstract void initRepo()
96 throws Exception;
97
98
99
100
101 protected void setUp()
102 throws Exception
103 {
104 super.setUp();
105
106 scmRepository = null;
107
108 scmFileNames = new ArrayList<String>( 4 );
109 scmFileNames.add( "/pom.xml" );
110 scmFileNames.add( "/readme.txt" );
111 scmFileNames.add( "/src/main/java/Application.java" );
112 scmFileNames.add( "/src/test/java/Test.java" );
113
114 initRepo();
115
116 checkOut( getWorkingCopy(), getScmRepository() );
117
118 Iterator<String> it = getScmFileNames().iterator();
119 while ( it.hasNext() )
120 {
121 assertFile( getWorkingCopy(), it.next() );
122 }
123 }
124
125
126
127
128
129
130
131 public void removeRepo()
132 throws Exception
133 {
134 }
135
136
137
138
139
140 @Override
141 protected void tearDown()
142 throws Exception
143 {
144 super.tearDown();
145 removeRepo();
146 }
147
148
149
150
151 protected ScmRepository getScmRepository()
152 throws Exception
153 {
154 if ( scmRepository == null )
155 {
156 scmRepository = getScmManager().makeScmRepository( getScmUrl() );
157 }
158
159 return scmRepository;
160 }
161
162
163
164
165 protected CheckOutScmResult checkOut( File workingDirectory, ScmRepository repository )
166 throws Exception
167 {
168 CheckOutScmResult result =
169 getScmManager().getProviderByUrl( getScmUrl() ).checkOut( repository, new ScmFileSet( workingDirectory ),
170 (ScmVersion) null );
171
172 assertTrue( "Check result was successful, output: " + result.getCommandOutput(), result.isSuccess() );
173
174 return result;
175 }
176
177
178
179
180 protected CheckInScmResult checkIn( File workingDirectory, ScmRepository repository )
181 throws Exception
182 {
183 CheckInScmResult result = getScmManager().getProviderByUrl( getScmUrl() )
184 .checkIn( repository, new ScmFileSet( workingDirectory ), (ScmVersion) null, "Initial Checkin" );
185
186 assertTrue( "Check result was successful, output: " + result.getCommandOutput(), result.isSuccess() );
187
188 return result;
189 }
190
191
192
193
194 protected void addToWorkingTree( File workingDirectory, File file, ScmRepository repository )
195 throws Exception
196 {
197 ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
198
199 CommandParameters commandParameters = new CommandParameters();
200 commandParameters.setString( CommandParameter.FORCE_ADD, Boolean.TRUE.toString() );
201
202 AddScmResult result = provider.add( repository, new ScmFileSet( workingDirectory, file ), commandParameters );
203
204 assertTrue( "Check result was successful, output: " + result.getCommandOutput(), result.isSuccess() );
205
206 List<ScmFile> addedFiles = result.getAddedFiles();
207
208 if ( new File( workingDirectory, file.getPath() ).isFile() )
209 {
210
211 assertEquals( "Expected 1 file in the added files list " + addedFiles, 1, addedFiles.size() );
212 }
213 }
214
215
216
217
218
219
220
221
222
223
224
225
226
227 protected Map<String, ScmFile> mapFilesByPath( List<ScmFile> files )
228 {
229 if ( files == null )
230 {
231 return null;
232 }
233
234 Map<String, ScmFile> mappedFiles = new TreeMap<String, ScmFile>();
235 for ( ScmFile scmFile : files )
236 {
237 String path = StringUtils.replace( scmFile.getPath(), "\\", "/" );
238 mappedFiles.put( path, scmFile );
239 }
240
241 return mappedFiles;
242 }
243
244 protected EditScmResult edit( File basedir, String includes, String excludes, ScmRepository repository )
245 throws Exception
246 {
247 if ( this.getScmManager().getProviderByRepository( this.getScmRepository() ).requiresEditMode() )
248 {
249 ScmFileSet fileSet = new ScmFileSet( basedir, includes, excludes );
250 return getScmManager().edit( getScmRepository(), fileSet );
251 }
252 return new EditScmResult( "", "", "", true );
253 }
254
255 }