1 package org.apache.maven.scm.provider.local;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.CommandParameters;
23 import org.apache.maven.scm.ScmException;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.command.add.AddScmResult;
26 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
27 import org.apache.maven.scm.command.checkin.CheckInScmResult;
28 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
29 import org.apache.maven.scm.command.list.ListScmResult;
30 import org.apache.maven.scm.command.mkdir.MkdirScmResult;
31 import org.apache.maven.scm.command.update.UpdateScmResult;
32 import org.apache.maven.scm.command.status.StatusScmResult;
33 import org.apache.maven.scm.command.tag.TagScmResult;
34 import org.apache.maven.scm.provider.AbstractScmProvider;
35 import org.apache.maven.scm.provider.ScmProviderRepository;
36 import org.apache.maven.scm.provider.local.command.add.LocalAddCommand;
37 import org.apache.maven.scm.provider.local.command.changelog.LocalChangeLogCommand;
38 import org.apache.maven.scm.provider.local.command.checkin.LocalCheckInCommand;
39 import org.apache.maven.scm.provider.local.command.checkout.LocalCheckOutCommand;
40 import org.apache.maven.scm.provider.local.command.list.LocalListCommand;
41 import org.apache.maven.scm.provider.local.command.mkdir.LocalMkdirCommand;
42 import org.apache.maven.scm.provider.local.command.update.LocalUpdateCommand;
43 import org.apache.maven.scm.provider.local.command.status.LocalStatusCommand;
44 import org.apache.maven.scm.provider.local.command.tag.LocalTagCommand;
45 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
46 import org.apache.maven.scm.repository.ScmRepositoryException;
47 import org.codehaus.plexus.util.StringUtils;
48
49 import java.io.File;
50
51
52
53
54
55
56
57 public class LocalScmProvider
58 extends AbstractScmProvider
59 {
60
61 public String getScmType()
62 {
63 return "local";
64 }
65
66
67 public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
68 throws ScmRepositoryException
69 {
70 String[] tokens = StringUtils.split( scmSpecificUrl, Character.toString( delimiter ) );
71
72 if ( tokens.length != 2 )
73 {
74 throw new ScmRepositoryException( "The connection string didn't contain the expected number of tokens. "
75 + "Expected 2 tokens but got " + tokens.length + " tokens." );
76 }
77
78
79
80
81
82 String root = tokens[0];
83
84 File rootFile = new File( root );
85
86 if ( !rootFile.isAbsolute() )
87 {
88 String basedir = System.getProperty( "basedir", new File( "" ).getAbsolutePath() );
89
90 rootFile = new File( basedir, root );
91 }
92
93 if ( !rootFile.exists() )
94 {
95 throw new ScmRepositoryException( "The root doesn't exists (" + rootFile.getAbsolutePath() + ")." );
96 }
97
98 if ( !rootFile.isDirectory() )
99 {
100 throw new ScmRepositoryException( "The root isn't a directory (" + rootFile.getAbsolutePath() + ")." );
101 }
102
103
104
105
106
107 String module = tokens[1];
108
109 File moduleFile = new File( rootFile, module );
110
111 if ( !moduleFile.exists() )
112 {
113 throw new ScmRepositoryException(
114 "The module doesn't exist (root: " + rootFile.getAbsolutePath() + ", module: " + module + ")." );
115 }
116
117 if ( !moduleFile.isDirectory() )
118 {
119 throw new ScmRepositoryException( "The module isn't a directory." );
120 }
121
122 return new LocalScmProviderRepository( rootFile.getAbsolutePath(), module );
123 }
124
125
126
127
128
129 public static String fixModuleName( String module )
130 {
131 if ( module.endsWith( "/" ) )
132 {
133 module = module.substring( 0, module.length() - 1 );
134 }
135
136 if ( module.startsWith( "/" ) )
137 {
138 module = module.substring( 1 );
139 }
140
141 return module;
142 }
143
144
145 public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
146 throws ScmException
147 {
148 LocalStatusCommand command = new LocalStatusCommand();
149
150 command.setLogger( getLogger() );
151
152 return (StatusScmResult) command.execute( repository, fileSet, parameters );
153 }
154
155
156 public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
157 throws ScmException
158 {
159 LocalTagCommand command = new LocalTagCommand();
160
161 command.setLogger( getLogger() );
162
163 return (TagScmResult) command.execute( repository, fileSet, parameters );
164 }
165
166
167 public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
168 throws ScmException
169 {
170 LocalAddCommand command = new LocalAddCommand();
171
172 command.setLogger( getLogger() );
173
174 return (AddScmResult) command.execute( repository, fileSet, parameters );
175 }
176
177
178 protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
179 CommandParameters parameters )
180 throws ScmException
181 {
182 LocalChangeLogCommand command = new LocalChangeLogCommand();
183
184 command.setLogger( getLogger() );
185
186 return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
187 }
188
189
190 public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
191 CommandParameters parameters )
192 throws ScmException
193 {
194 LocalCheckInCommand command = new LocalCheckInCommand();
195
196 command.setLogger( getLogger() );
197
198 return (CheckInScmResult) command.execute( repository, fileSet, parameters );
199 }
200
201
202 public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
203 CommandParameters parameters )
204 throws ScmException
205 {
206 LocalCheckOutCommand command = new LocalCheckOutCommand();
207
208 command.setLogger( getLogger() );
209
210 return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
211 }
212
213
214 protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
215 throws ScmException
216 {
217 LocalListCommand command = new LocalListCommand();
218
219 command.setLogger( getLogger() );
220
221 return (ListScmResult) command.execute( repository, fileSet, parameters );
222 }
223
224
225 protected MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
226 throws ScmException
227 {
228 LocalMkdirCommand command = new LocalMkdirCommand();
229
230 command.setLogger( getLogger() );
231
232 return (MkdirScmResult) command.execute( repository, fileSet, parameters );
233 }
234
235
236 public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
237 throws ScmException
238 {
239 LocalUpdateCommand command = new LocalUpdateCommand();
240
241 command.setLogger( getLogger() );
242
243 return (UpdateScmResult) command.execute( repository, fileSet, parameters );
244 }
245 }