001package org.apache.maven.scm.provider.integrity; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.scm.CommandParameter; 023import org.apache.maven.scm.CommandParameters; 024import org.apache.maven.scm.ScmException; 025import org.apache.maven.scm.ScmFileSet; 026import org.apache.maven.scm.ScmResult; 027import org.apache.maven.scm.command.add.AddScmResult; 028import org.apache.maven.scm.command.blame.BlameScmResult; 029import org.apache.maven.scm.command.branch.BranchScmResult; 030import org.apache.maven.scm.command.changelog.ChangeLogScmResult; 031import org.apache.maven.scm.command.checkin.CheckInScmResult; 032import org.apache.maven.scm.command.checkout.CheckOutScmResult; 033import org.apache.maven.scm.command.diff.DiffScmResult; 034import org.apache.maven.scm.command.edit.EditScmResult; 035import org.apache.maven.scm.command.export.ExportScmResult; 036import org.apache.maven.scm.command.list.ListScmResult; 037import org.apache.maven.scm.command.login.LoginScmResult; 038import org.apache.maven.scm.command.mkdir.MkdirScmResult; 039import org.apache.maven.scm.command.remove.RemoveScmResult; 040import org.apache.maven.scm.command.status.StatusScmResult; 041import org.apache.maven.scm.command.tag.TagScmResult; 042import org.apache.maven.scm.command.unedit.UnEditScmResult; 043import org.apache.maven.scm.command.update.UpdateScmResult; 044import org.apache.maven.scm.provider.AbstractScmProvider; 045import org.apache.maven.scm.provider.ScmProviderRepository; 046import org.apache.maven.scm.provider.integrity.command.add.IntegrityAddCommand; 047import org.apache.maven.scm.provider.integrity.command.blame.IntegrityBlameCommand; 048import org.apache.maven.scm.provider.integrity.command.branch.IntegrityBranchCommand; 049import org.apache.maven.scm.provider.integrity.command.changelog.IntegrityChangeLogCommand; 050import org.apache.maven.scm.provider.integrity.command.checkin.IntegrityCheckInCommand; 051import org.apache.maven.scm.provider.integrity.command.checkout.IntegrityCheckOutCommand; 052import org.apache.maven.scm.provider.integrity.command.diff.IntegrityDiffCommand; 053import org.apache.maven.scm.provider.integrity.command.edit.IntegrityEditCommand; 054import org.apache.maven.scm.provider.integrity.command.export.IntegrityExportCommand; 055import org.apache.maven.scm.provider.integrity.command.fileinfo.IntegrityFileInfoCommand; 056import org.apache.maven.scm.provider.integrity.command.list.IntegrityListCommand; 057import org.apache.maven.scm.provider.integrity.command.lock.IntegrityLockCommand; 058import org.apache.maven.scm.provider.integrity.command.login.IntegrityLoginCommand; 059import org.apache.maven.scm.provider.integrity.command.mkdir.IntegrityMkdirCommand; 060import org.apache.maven.scm.provider.integrity.command.remove.IntegrityRemoveCommand; 061import org.apache.maven.scm.provider.integrity.command.status.IntegrityStatusCommand; 062import org.apache.maven.scm.provider.integrity.command.tag.IntegrityTagCommand; 063import org.apache.maven.scm.provider.integrity.command.unedit.IntegrityUnEditCommand; 064import org.apache.maven.scm.provider.integrity.command.unlock.IntegrityUnlockCommand; 065import org.apache.maven.scm.provider.integrity.command.update.IntegrityUpdateCommand; 066import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository; 067import org.apache.maven.scm.repository.ScmRepositoryException; 068import org.codehaus.plexus.util.StringUtils; 069 070/** 071 * MKS Integrity SCM Provider for Maven 072 * 073 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a> 074 * @version $Id: IntegrityScmProvider.java 1.7 2011/08/22 13:06:46EDT Cletus D'Souza (dsouza) Exp $ 075 * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="integrity" 076 * @since 1.6 077 */ 078public class IntegrityScmProvider 079 extends AbstractScmProvider 080{ 081 public static final String INTEGRITY_CM_URL = "[[user][/pass]@host[:port]]|configPath"; 082 083 /** 084 * Returns the name of our SCM Provider 085 */ 086 public String getScmType() 087 { 088 return "integrity"; 089 } 090 091 /** 092 * This class is the central point of the SCM provider. The Maven-SCM framework will know only this class in the 093 * provider, so this class will validate the scm url, populate the IntegrityScmProviderRepository and provide all 094 * commands that we support. 095 * 096 * @param scmSpecificUrl The SCM URL specific to our implementation for this plugin 097 * @param delimiter The character that separates the information above 098 * @throws ScmRepositoryException 099 */ 100 public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter ) 101 throws ScmRepositoryException 102 { 103 // Initialize our variables need to create the IntegrityScmProvderRepository 104 String hostName = ""; 105 int port = 0; 106 String userName = ""; 107 String password = ""; 108 String configPath = ""; 109 110 // Looking for a string in the following format: 111 // [[user][/pass]@host[:port]]|configPath 112 // Where '|' is the delimiter... 113 String[] tokens = StringUtils.split( scmSpecificUrl, String.valueOf( delimiter ) ); 114 // Expecting a minimum of one token to a maximum of two tokens 115 if ( tokens.length < 1 || tokens.length > 2 ) 116 { 117 throw new ScmRepositoryException( 118 "Invalid SCM URL '" + scmSpecificUrl + "'. Expecting a url using format: " + INTEGRITY_CM_URL ); 119 } 120 else 121 { 122 // Inspect the first token to see if it contains connection information 123 if ( tokens[0].indexOf( '@' ) >= 0 ) 124 { 125 // First split up the username and password string from the host:port information 126 String userPassStr = tokens[0].substring( 0, tokens[0].indexOf( '@' ) ); 127 getLogger().debug( "User/Password information supplied: " + userPassStr ); 128 String hostPortStr = tokens[0].substring( tokens[0].indexOf( '@' ) + 1, tokens[0].length() ); 129 getLogger().debug( "Host/Port information supplied: " + hostPortStr ); 130 131 if ( userPassStr.length() > 0 ) 132 { 133 // Next, make sure the username and password are separated using a forward slash '/' 134 int userPassDelimIndx = userPassStr.indexOf( '/' ); 135 if ( userPassDelimIndx > 0 ) 136 { 137 userName = userPassStr.substring( 0, userPassStr.indexOf( '/' ) ); 138 if ( userPassStr.length() > ( userPassDelimIndx + 1 ) ) 139 { 140 password = userPassStr.substring( userPassStr.indexOf( '/' ) + 1, userPassStr.length() ); 141 } 142 } 143 else 144 { 145 userName = userPassStr; 146 } 147 } 148 // Now, check to see what we've got for the host:port information 149 if ( hostPortStr.length() > 0 ) 150 { 151 int hostPortDelimIndx = hostPortStr.indexOf( ':' ); 152 if ( hostPortDelimIndx > 0 ) 153 { 154 hostName = hostPortStr.substring( 0, hostPortStr.indexOf( ':' ) ); 155 if ( hostPortStr.length() > ( hostPortDelimIndx + 1 ) ) 156 { 157 port = Integer.parseInt( 158 hostPortStr.substring( hostPortStr.indexOf( ':' ) + 1, hostPortStr.length() ) ); 159 } 160 } 161 else 162 { 163 hostName = hostPortStr; 164 } 165 } 166 } 167 // Grab the last token (or first token depends how you look at it) 168 configPath = tokens[tokens.length - 1]; 169 } 170 171 return new IntegrityScmProviderRepository( hostName, port, userName, password, configPath, getLogger() ); 172 } 173 174 /** 175 * Maps to si connect and initialization of the project with si projectinfo 176 */ 177 @Override 178 protected LoginScmResult login( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 179 throws ScmException 180 { 181 IntegrityLoginCommand command = new IntegrityLoginCommand(); 182 command.setLogger( getLogger() ); 183 return (LoginScmResult) command.execute( repository, fileSet, params ); 184 } 185 186 /** 187 * Maps to si rlog --rfilter=daterange:date1-date2 188 */ 189 @Override 190 protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet, 191 CommandParameters parameters ) 192 throws ScmException 193 { 194 IntegrityChangeLogCommand command = new IntegrityChangeLogCommand(); 195 command.setLogger( getLogger() ); 196 return (ChangeLogScmResult) command.execute( repository, fileSet, parameters ); 197 } 198 199 /** 200 * Maps to si viewnonmembers and then si add for every non-member 201 */ 202 @Override 203 public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 204 throws ScmException 205 { 206 IntegrityAddCommand command = new IntegrityAddCommand(); 207 command.setLogger( getLogger() ); 208 return (AddScmResult) command.execute( repository, fileSet, params ); 209 } 210 211 /** 212 * Maps to si dropsandbox 213 */ 214 @Override 215 protected RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 216 throws ScmException 217 { 218 IntegrityRemoveCommand command = new IntegrityRemoveCommand(); 219 command.setLogger( getLogger() ); 220 return (RemoveScmResult) command.execute( repository, fileSet, params ); 221 } 222 223 224 /** 225 * Maps to a si ci 226 */ 227 @Override 228 protected CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 229 throws ScmException 230 { 231 IntegrityCheckInCommand command = new IntegrityCheckInCommand(); 232 command.setLogger( getLogger() ); 233 return (CheckInScmResult) command.execute( repository, fileSet, params ); 234 } 235 236 /** 237 * Maps to si createsandbox and/or si resync 238 */ 239 @Override 240 protected CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet, 241 CommandParameters params ) 242 throws ScmException 243 { 244 IntegrityCheckOutCommand command = new IntegrityCheckOutCommand(); 245 command.setLogger( getLogger() ); 246 return (CheckOutScmResult) command.execute( repository, fileSet, params ); 247 } 248 249 /** 250 * Maps to si diff 251 */ 252 @Override 253 protected DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 254 throws ScmException 255 { 256 IntegrityDiffCommand command = new IntegrityDiffCommand(); 257 command.setLogger( getLogger() ); 258 return (DiffScmResult) command.execute( repository, fileSet, params ); 259 } 260 261 /** 262 * Maps to si makewritable 263 */ 264 @Override 265 protected EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 266 throws ScmException 267 { 268 IntegrityEditCommand command = new IntegrityEditCommand(); 269 command.setLogger( getLogger() ); 270 return (EditScmResult) command.execute( repository, fileSet, params ); 271 } 272 273 /** 274 * Maps to si viewsandbox with a filter of locally changed files 275 */ 276 @Override 277 protected StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 278 throws ScmException 279 { 280 IntegrityStatusCommand command = new IntegrityStatusCommand(); 281 command.setLogger( getLogger() ); 282 return (StatusScmResult) command.execute( repository, fileSet, params ); 283 } 284 285 /** 286 * Maps to si checkpoint 287 */ 288 @Override 289 protected TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 290 throws ScmException 291 { 292 IntegrityTagCommand command = new IntegrityTagCommand(); 293 command.setLogger( getLogger() ); 294 return (TagScmResult) command.execute( repository, fileSet, params ); 295 } 296 297 /** 298 * Maps to si revert 299 */ 300 @Override 301 protected UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 302 throws ScmException 303 { 304 IntegrityUnEditCommand command = new IntegrityUnEditCommand(); 305 command.setLogger( getLogger() ); 306 return (UnEditScmResult) command.execute( repository, fileSet, params ); 307 } 308 309 /** 310 * Maps to si resync 311 */ 312 @Override 313 protected UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 314 throws ScmException 315 { 316 IntegrityUpdateCommand command = new IntegrityUpdateCommand(); 317 command.setLogger( getLogger() ); 318 return (UpdateScmResult) command.execute( repository, fileSet, params ); 319 } 320 321 /** 322 * Maps to si annotate 323 */ 324 @Override 325 protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 326 throws ScmException 327 { 328 IntegrityBlameCommand command = new IntegrityBlameCommand(); 329 command.setLogger( getLogger() ); 330 return (BlameScmResult) command.execute( repository, fileSet, params ); 331 } 332 333 /** 334 * Maps to si viewproject 335 */ 336 @Override 337 protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 338 throws ScmException 339 { 340 IntegrityListCommand command = new IntegrityListCommand(); 341 command.setLogger( getLogger() ); 342 return (ListScmResult) command.execute( repository, fileSet, params ); 343 } 344 345 /** 346 * Maps to si projectco (no sandbox is used) 347 */ 348 @Override 349 protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 350 throws ScmException 351 { 352 IntegrityExportCommand command = new IntegrityExportCommand(); 353 command.setLogger( getLogger() ); 354 return (ExportScmResult) command.execute( repository, fileSet, params ); 355 } 356 357 /** 358 * Maps to si createdevpath 359 */ 360 @Override 361 protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 362 throws ScmException 363 { 364 IntegrityBranchCommand command = new IntegrityBranchCommand(); 365 command.setLogger( getLogger() ); 366 return (BranchScmResult) command.execute( repository, fileSet, params ); 367 } 368 369 /** 370 * Maps to si createsubproject 371 */ 372 @Override 373 protected MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 374 throws ScmException 375 { 376 IntegrityMkdirCommand command = new IntegrityMkdirCommand(); 377 command.setLogger( getLogger() ); 378 return (MkdirScmResult) command.execute( repository, fileSet, params ); 379 } 380 381 /** 382 * Maps to si memberinfo 383 */ 384 protected ScmResult fileinfo( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 385 throws ScmException 386 { 387 IntegrityFileInfoCommand command = new IntegrityFileInfoCommand(); 388 command.setLogger( getLogger() ); 389 return command.execute( repository, fileSet, params ); 390 } 391 392 /** 393 * Maps to si lock 394 */ 395 protected ScmResult lock( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 396 throws ScmException 397 { 398 IntegrityLockCommand command = new IntegrityLockCommand(); 399 command.setLogger( getLogger() ); 400 return command.execute( repository, fileSet, params ); 401 } 402 403 /** 404 * Maps to si unlock 405 */ 406 protected ScmResult unlock( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params ) 407 throws ScmException 408 { 409 IntegrityUnlockCommand command = new IntegrityUnlockCommand( params.getString( CommandParameter.FILE ) ); 410 command.setLogger( getLogger() ); 411 return command.execute( repository, fileSet, params ); 412 } 413}