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