001package org.apache.maven.scm.provider; 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.NoSuchCommandScmException; 025import org.apache.maven.scm.ScmBranch; 026import org.apache.maven.scm.ScmBranchParameters; 027import org.apache.maven.scm.ScmException; 028import org.apache.maven.scm.ScmFileSet; 029import org.apache.maven.scm.ScmRevision; 030import org.apache.maven.scm.ScmTagParameters; 031import org.apache.maven.scm.ScmVersion; 032import org.apache.maven.scm.command.add.AddScmResult; 033import org.apache.maven.scm.command.blame.BlameScmRequest; 034import org.apache.maven.scm.command.blame.BlameScmResult; 035import org.apache.maven.scm.command.branch.BranchScmResult; 036import org.apache.maven.scm.command.changelog.ChangeLogScmRequest; 037import org.apache.maven.scm.command.changelog.ChangeLogScmResult; 038import org.apache.maven.scm.command.checkin.CheckInScmResult; 039import org.apache.maven.scm.command.checkout.CheckOutScmResult; 040import org.apache.maven.scm.command.diff.DiffScmResult; 041import org.apache.maven.scm.command.edit.EditScmResult; 042import org.apache.maven.scm.command.export.ExportScmResult; 043import org.apache.maven.scm.command.info.InfoScmResult; 044import org.apache.maven.scm.command.list.ListScmResult; 045import org.apache.maven.scm.command.login.LoginScmResult; 046import org.apache.maven.scm.command.mkdir.MkdirScmResult; 047import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult; 048import org.apache.maven.scm.command.remove.RemoveScmResult; 049import org.apache.maven.scm.command.status.StatusScmResult; 050import org.apache.maven.scm.command.tag.TagScmResult; 051import org.apache.maven.scm.command.unedit.UnEditScmResult; 052import org.apache.maven.scm.command.update.UpdateScmResult; 053import org.apache.maven.scm.log.ScmLogDispatcher; 054import org.apache.maven.scm.log.ScmLogger; 055import org.apache.maven.scm.repository.ScmRepository; 056import org.apache.maven.scm.repository.ScmRepositoryException; 057import org.apache.maven.scm.repository.UnknownRepositoryStructure; 058import org.codehaus.plexus.util.StringUtils; 059 060import java.io.File; 061import java.util.ArrayList; 062import java.util.Date; 063import java.util.List; 064 065/** 066 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> 067 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 068 * @author Olivier Lamy 069 * 070 */ 071public abstract class AbstractScmProvider 072 implements ScmProvider 073{ 074 private ScmLogDispatcher logDispatcher = new ScmLogDispatcher(); 075 076 // ---------------------------------------------------------------------- 077 // 078 // ---------------------------------------------------------------------- 079 080 /** 081 * {@inheritDoc} 082 */ 083 public String getScmSpecificFilename() 084 { 085 return null; 086 } 087 088 /** 089 * {@inheritDoc} 090 */ 091 public String sanitizeTagName( String tag ) 092 { 093 /* by default, we assume all tags are valid. */ 094 return tag; 095 } 096 097 /** 098 * {@inheritDoc} 099 */ 100 public boolean validateTagName( String tag ) 101 { 102 /* by default, we assume all tags are valid. */ 103 return true; 104 } 105 106 /** 107 * {@inheritDoc} 108 */ 109 public List<String> validateScmUrl( String scmSpecificUrl, char delimiter ) 110 { 111 List<String> messages = new ArrayList<String>(); 112 113 try 114 { 115 makeProviderScmRepository( scmSpecificUrl, delimiter ); 116 } 117 catch ( ScmRepositoryException e ) 118 { 119 messages.add( e.getMessage() ); 120 } 121 122 return messages; 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 public boolean requiresEditMode() 129 { 130 return false; 131 } 132 133 // ---------------------------------------------------------------------- 134 // Scm Implementation 135 // ---------------------------------------------------------------------- 136 137 /** 138 * {@inheritDoc} 139 */ 140 public AddScmResult add( ScmRepository repository, ScmFileSet fileSet ) 141 throws ScmException 142 { 143 return add( repository, fileSet, (String) null ); 144 } 145 146 /** 147 * {@inheritDoc} 148 */ 149 public AddScmResult add( ScmRepository repository, ScmFileSet fileSet, String message ) 150 throws ScmException 151 { 152 login( repository, fileSet ); 153 154 CommandParameters parameters = new CommandParameters(); 155 156 parameters.setString( CommandParameter.MESSAGE, message == null ? "" : message ); 157 158 // TODO: binary may be dependant on particular files though 159 // TODO: set boolean? 160 parameters.setString( CommandParameter.BINARY, "false" ); 161 162 return add( repository.getProviderRepository(), fileSet, parameters ); 163 } 164 165 public AddScmResult add( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 166 throws ScmException 167 { 168 login( repository, fileSet ); 169 170 if ( parameters.getString( CommandParameter.BINARY , null ) == null ) 171 { 172 // TODO: binary may be dependant on particular files though 173 // TODO: set boolean? 174 parameters.setString( CommandParameter.BINARY, "false" ); 175 } 176 177 return add( repository.getProviderRepository(), fileSet, parameters ); 178 } 179 180 public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 181 throws ScmException 182 { 183 throw new NoSuchCommandScmException( "add" ); 184 } 185 186 /** 187 * {@inheritDoc} 188 */ 189 public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName ) 190 throws ScmException 191 { 192 return branch( repository, fileSet, branchName, new ScmBranchParameters() ); 193 } 194 195 /** 196 * {@inheritDoc} 197 */ 198 public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName, String message ) 199 throws ScmException 200 { 201 ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); 202 203 if ( StringUtils.isNotEmpty( message ) ) 204 { 205 scmBranchParameters.setMessage( message ); 206 } 207 208 return branch( repository, fileSet, branchName, scmBranchParameters ); 209 } 210 211 public BranchScmResult branch( ScmRepository repository, ScmFileSet fileSet, String branchName, 212 ScmBranchParameters scmBranchParameters ) 213 throws ScmException 214 { 215 login( repository, fileSet ); 216 217 CommandParameters parameters = new CommandParameters(); 218 219 parameters.setString( CommandParameter.BRANCH_NAME, branchName ); 220 221 parameters.setScmBranchParameters( CommandParameter.SCM_BRANCH_PARAMETERS, scmBranchParameters ); 222 223 return branch( repository.getProviderRepository(), fileSet, parameters ); 224 } 225 226 protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, 227 CommandParameters parameters ) 228 throws ScmException 229 { 230 throw new NoSuchCommandScmException( "branch" ); 231 } 232 233 /** 234 * {@inheritDoc} 235 * 236 * @deprecated 237 */ 238 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, 239 int numDays, String branch ) 240 throws ScmException 241 { 242 return changeLog( repository, fileSet, startDate, endDate, numDays, branch, null ); 243 } 244 245 /** 246 * {@inheritDoc} 247 * 248 * @deprecated 249 */ 250 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, 251 int numDays, String branch, String datePattern ) 252 throws ScmException 253 { 254 ScmBranch scmBranch = null; 255 256 if ( StringUtils.isNotEmpty( branch ) ) 257 { 258 scmBranch = new ScmBranch( branch ); 259 } 260 return changeLog( repository, fileSet, startDate, endDate, numDays, scmBranch, null ); 261 262 } 263 264 /** 265 * {@inheritDoc} 266 */ 267 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, 268 int numDays, ScmBranch branch ) 269 throws ScmException 270 { 271 return changeLog( repository, fileSet, startDate, endDate, numDays, branch, null ); 272 } 273 274 /** 275 * {@inheritDoc} 276 */ 277 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, 278 int numDays, ScmBranch branch, String datePattern ) 279 throws ScmException 280 { 281 final ChangeLogScmRequest request = new ChangeLogScmRequest( repository, fileSet ); 282 request.setDateRange( startDate, endDate ); 283 request.setNumDays( numDays ); 284 request.setScmBranch( branch ); 285 request.setDatePattern( datePattern ); 286 return changeLog( request ); 287 } 288 289 /** 290 * {@inheritDoc} 291 */ 292 public ChangeLogScmResult changeLog( ChangeLogScmRequest request ) 293 throws ScmException 294 { 295 final ScmRepository scmRepository = request.getScmRepository(); 296 final ScmFileSet scmFileSet = request.getScmFileSet(); 297 login( scmRepository, scmFileSet ); 298 return changelog( scmRepository.getProviderRepository(), scmFileSet, request.getCommandParameters() ); 299 } 300 301 302 /** 303 * {@inheritDoc} 304 * 305 * @deprecated 306 */ 307 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, String startTag, String endTag ) 308 throws ScmException 309 { 310 return changeLog( repository, fileSet, startTag, endTag, null ); 311 } 312 313 /** 314 * {@inheritDoc} 315 * 316 * @deprecated 317 */ 318 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, String startTag, String endTag, 319 String datePattern ) 320 throws ScmException 321 { 322 ScmVersion startRevision = null; 323 ScmVersion endRevision = null; 324 325 if ( StringUtils.isNotEmpty( startTag ) ) 326 { 327 startRevision = new ScmRevision( startTag ); 328 } 329 330 if ( StringUtils.isNotEmpty( endTag ) ) 331 { 332 endRevision = new ScmRevision( endTag ); 333 } 334 335 return changeLog( repository, fileSet, startRevision, endRevision, null ); 336 } 337 338 /** 339 * {@inheritDoc} 340 */ 341 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion, 342 ScmVersion endVersion ) 343 throws ScmException 344 { 345 return changeLog( repository, fileSet, startVersion, endVersion, null ); 346 } 347 348 /** 349 * {@inheritDoc} 350 */ 351 public ChangeLogScmResult changeLog( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion, 352 ScmVersion endVersion, String datePattern ) 353 throws ScmException 354 { 355 login( repository, fileSet ); 356 357 CommandParameters parameters = new CommandParameters(); 358 359 parameters.setScmVersion( CommandParameter.START_SCM_VERSION, startVersion ); 360 361 parameters.setScmVersion( CommandParameter.END_SCM_VERSION, endVersion ); 362 363 parameters.setString( CommandParameter.CHANGELOG_DATE_PATTERN, datePattern ); 364 365 return changelog( repository.getProviderRepository(), fileSet, parameters ); 366 } 367 368 protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet, 369 CommandParameters parameters ) 370 throws ScmException 371 { 372 throw new NoSuchCommandScmException( "changelog" ); 373 } 374 375 376 /** 377 * {@inheritDoc} 378 * 379 * @deprecated 380 */ 381 public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, String tag, String message ) 382 throws ScmException 383 { 384 ScmVersion scmVersion = null; 385 386 if ( StringUtils.isNotEmpty( tag ) ) 387 { 388 scmVersion = new ScmBranch( tag ); 389 } 390 391 return checkIn( repository, fileSet, scmVersion, message ); 392 } 393 394 /** 395 * {@inheritDoc} 396 */ 397 public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, String message ) 398 throws ScmException 399 { 400 return checkIn( repository, fileSet, (ScmVersion) null, message ); 401 } 402 403 /** 404 * {@inheritDoc} 405 */ 406 public CheckInScmResult checkIn( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 407 String message ) 408 throws ScmException 409 { 410 login( repository, fileSet ); 411 412 CommandParameters parameters = new CommandParameters(); 413 414 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 415 416 parameters.setString( CommandParameter.MESSAGE, message ); 417 418 return checkin( repository.getProviderRepository(), fileSet, parameters ); 419 } 420 421 protected CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet, 422 CommandParameters parameters ) 423 throws ScmException 424 { 425 throw new NoSuchCommandScmException( "checkin" ); 426 } 427 428 429 /** 430 * {@inheritDoc} 431 * 432 * @deprecated 433 */ 434 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, String tag ) 435 throws ScmException 436 { 437 return checkOut( repository, fileSet, tag, true ); 438 } 439 440 /** 441 * {@inheritDoc} 442 * 443 * @deprecated 444 */ 445 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, String tag, boolean recursive ) 446 throws ScmException 447 { 448 ScmVersion scmVersion = null; 449 450 if ( StringUtils.isNotEmpty( tag ) ) 451 { 452 scmVersion = new ScmBranch( tag ); 453 } 454 455 return checkOut( repository, fileSet, scmVersion, recursive ); 456 } 457 458 /** 459 * {@inheritDoc} 460 */ 461 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet ) 462 throws ScmException 463 { 464 return checkOut( repository, fileSet, (ScmVersion) null, true ); 465 } 466 467 /** 468 * {@inheritDoc} 469 */ 470 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion ) 471 throws ScmException 472 { 473 return checkOut( repository, fileSet, scmVersion, true ); 474 } 475 476 /** 477 * {@inheritDoc} 478 */ 479 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, boolean recursive ) 480 throws ScmException 481 { 482 return checkOut( repository, fileSet, (ScmVersion) null, recursive ); 483 } 484 485 /** 486 * {@inheritDoc} 487 */ 488 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 489 boolean recursive ) 490 throws ScmException 491 { 492 login( repository, fileSet ); 493 494 CommandParameters parameters = new CommandParameters(); 495 496 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 497 498 parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( recursive ) ); 499 500 return checkout( repository.getProviderRepository(), fileSet, parameters ); 501 } 502 503 @Override 504 public CheckOutScmResult checkOut( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 505 CommandParameters commandParameters ) 506 throws ScmException 507 { 508 login( repository, fileSet ); 509 if ( scmVersion != null && commandParameters.getScmVersion( CommandParameter.SCM_VERSION, null ) == null ) 510 { 511 commandParameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 512 } 513 514 return checkout( repository.getProviderRepository(), fileSet, commandParameters ); 515 } 516 517 protected CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet, 518 CommandParameters parameters ) 519 throws ScmException 520 { 521 throw new NoSuchCommandScmException( "checkout" ); 522 } 523 524 /** 525 * {@inheritDoc} 526 * 527 * @deprecated 528 */ 529 public DiffScmResult diff( ScmRepository repository, ScmFileSet fileSet, String startRevision, String endRevision ) 530 throws ScmException 531 { 532 ScmVersion startVersion = null; 533 ScmVersion endVersion = null; 534 535 if ( StringUtils.isNotEmpty( startRevision ) ) 536 { 537 startVersion = new ScmRevision( startRevision ); 538 } 539 540 if ( StringUtils.isNotEmpty( endRevision ) ) 541 { 542 endVersion = new ScmRevision( endRevision ); 543 } 544 545 return diff( repository, fileSet, startVersion, endVersion ); 546 } 547 548 /** 549 * {@inheritDoc} 550 */ 551 public DiffScmResult diff( ScmRepository repository, ScmFileSet fileSet, ScmVersion startVersion, 552 ScmVersion endVersion ) 553 throws ScmException 554 { 555 login( repository, fileSet ); 556 557 CommandParameters parameters = new CommandParameters(); 558 559 parameters.setScmVersion( CommandParameter.START_SCM_VERSION, startVersion ); 560 561 parameters.setScmVersion( CommandParameter.END_SCM_VERSION, endVersion ); 562 563 return diff( repository.getProviderRepository(), fileSet, parameters ); 564 } 565 566 protected DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 567 throws ScmException 568 { 569 throw new NoSuchCommandScmException( "diff" ); 570 } 571 572 /** 573 * {@inheritDoc} 574 */ 575 public EditScmResult edit( ScmRepository repository, ScmFileSet fileSet ) 576 throws ScmException 577 { 578 login( repository, fileSet ); 579 580 CommandParameters parameters = new CommandParameters(); 581 582 return edit( repository.getProviderRepository(), fileSet, parameters ); 583 } 584 585 protected EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 586 throws ScmException 587 { 588 if ( getLogger().isWarnEnabled() ) 589 { 590 getLogger().warn( "Provider " + this.getScmType() + " does not support edit operation." ); 591 } 592 593 return new EditScmResult( "", null, null, true ); 594 } 595 596 /** 597 * {@inheritDoc} 598 * 599 * @deprecated 600 */ 601 public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, String tag ) 602 throws ScmException 603 { 604 return export( repository, fileSet, tag, null ); 605 } 606 607 /** 608 * {@inheritDoc} 609 * 610 * @deprecated 611 */ 612 public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, String tag, String outputDirectory ) 613 throws ScmException 614 { 615 ScmVersion scmVersion = null; 616 617 if ( StringUtils.isNotEmpty( tag ) ) 618 { 619 scmVersion = new ScmRevision( tag ); 620 } 621 622 return export( repository, fileSet, scmVersion, outputDirectory ); 623 } 624 625 /** 626 * {@inheritDoc} 627 */ 628 public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet ) 629 throws ScmException 630 { 631 return export( repository, fileSet, (ScmVersion) null, null ); 632 } 633 634 /** 635 * {@inheritDoc} 636 */ 637 public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion ) 638 throws ScmException 639 { 640 return export( repository, fileSet, scmVersion, null ); 641 } 642 643 /** 644 * {@inheritDoc} 645 */ 646 public ExportScmResult export( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 647 String outputDirectory ) 648 throws ScmException 649 { 650 login( repository, fileSet ); 651 652 CommandParameters parameters = new CommandParameters(); 653 654 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 655 656 parameters.setString( CommandParameter.OUTPUT_DIRECTORY, outputDirectory ); 657 658 return export( repository.getProviderRepository(), fileSet, parameters ); 659 } 660 661 protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet, 662 CommandParameters parameters ) 663 throws ScmException 664 { 665 throw new NoSuchCommandScmException( "export" ); 666 } 667 668 /** 669 * {@inheritDoc} 670 */ 671 public ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive, String tag ) 672 throws ScmException 673 { 674 ScmVersion scmVersion = null; 675 676 if ( StringUtils.isNotEmpty( tag ) ) 677 { 678 scmVersion = new ScmRevision( tag ); 679 } 680 681 return list( repository, fileSet, recursive, scmVersion ); 682 } 683 684 /** 685 * {@inheritDoc} 686 */ 687 public ListScmResult list( ScmRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion ) 688 throws ScmException 689 { 690 login( repository, fileSet ); 691 692 CommandParameters parameters = new CommandParameters(); 693 694 parameters.setString( CommandParameter.RECURSIVE, Boolean.toString( recursive ) ); 695 696 if ( scmVersion != null ) 697 { 698 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 699 } 700 701 return list( repository.getProviderRepository(), fileSet, parameters ); 702 } 703 704 /** 705 * List each element (files and directories) of <B>fileSet</B> as they exist in the repository. 706 * 707 * @param repository the source control system 708 * @param fileSet the files to list 709 * @param parameters 710 * @return The list of files in the repository 711 * @throws NoSuchCommandScmException unless overriden by subclass 712 * @throws ScmException if any 713 */ 714 protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 715 throws ScmException 716 { 717 throw new NoSuchCommandScmException( "list" ); 718 } 719 720 /** 721 * {@inheritDoc} 722 */ 723 public MkdirScmResult mkdir( ScmRepository repository, ScmFileSet fileSet, String message, boolean createInLocal ) 724 throws ScmException 725 { 726 login( repository, fileSet ); 727 728 CommandParameters parameters = new CommandParameters(); 729 730 if ( message == null ) 731 { 732 message = ""; 733 if ( !createInLocal ) 734 { 735 getLogger().warn( "Commit message is empty!" ); 736 } 737 } 738 739 parameters.setString( CommandParameter.MESSAGE, message ); 740 741 parameters.setString( CommandParameter.SCM_MKDIR_CREATE_IN_LOCAL, Boolean.toString( createInLocal ) ); 742 743 return mkdir( repository.getProviderRepository(), fileSet, parameters ); 744 } 745 746 /** 747 * Create directory/directories in the repository. 748 * 749 * @param repository 750 * @param fileSet 751 * @param parameters 752 * @return 753 * @throws ScmException 754 */ 755 protected MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 756 throws ScmException 757 { 758 throw new NoSuchCommandScmException( "mkdir" ); 759 } 760 761 private void login( ScmRepository repository, ScmFileSet fileSet ) 762 throws ScmException 763 { 764 LoginScmResult result = login( repository.getProviderRepository(), fileSet, new CommandParameters() ); 765 766 if ( !result.isSuccess() ) 767 { 768 throw new ScmException( "Can't login.\n" + result.getCommandOutput() ); 769 } 770 } 771 772 protected LoginScmResult login( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 773 throws ScmException 774 { 775 return new LoginScmResult( null, null, null, true ); 776 } 777 778 /** 779 * {@inheritDoc} 780 */ 781 public RemoveScmResult remove( ScmRepository repository, ScmFileSet fileSet, String message ) 782 throws ScmException 783 { 784 login( repository, fileSet ); 785 786 CommandParameters parameters = new CommandParameters(); 787 788 parameters.setString( CommandParameter.MESSAGE, message == null ? "" : message ); 789 790 return remove( repository.getProviderRepository(), fileSet, parameters ); 791 } 792 793 protected RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, 794 CommandParameters parameters ) 795 throws ScmException 796 { 797 throw new NoSuchCommandScmException( "remove" ); 798 } 799 800 /** 801 * {@inheritDoc} 802 */ 803 public StatusScmResult status( ScmRepository repository, ScmFileSet fileSet ) 804 throws ScmException 805 { 806 login( repository, fileSet ); 807 808 CommandParameters parameters = new CommandParameters(); 809 810 return status( repository.getProviderRepository(), fileSet, parameters ); 811 } 812 813 protected StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, 814 CommandParameters parameters ) 815 throws ScmException 816 { 817 throw new NoSuchCommandScmException( "status" ); 818 } 819 820 /** 821 * {@inheritDoc} 822 */ 823 public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName ) 824 throws ScmException 825 { 826 return tag( repository, fileSet, tagName, new ScmTagParameters() ); 827 } 828 829 /** 830 * {@inheritDoc} 831 */ 832 public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName, String message ) 833 throws ScmException 834 { 835 login( repository, fileSet ); 836 837 CommandParameters parameters = new CommandParameters(); 838 839 parameters.setString( CommandParameter.TAG_NAME, tagName ); 840 841 if ( StringUtils.isNotEmpty( message ) ) 842 { 843 parameters.setString( CommandParameter.MESSAGE, message ); 844 } 845 846 ScmTagParameters scmTagParameters = new ScmTagParameters( message ); 847 848 parameters.setScmTagParameters( CommandParameter.SCM_TAG_PARAMETERS, scmTagParameters ); 849 850 return tag( repository.getProviderRepository(), fileSet, parameters ); 851 } 852 853 /** 854 * {@inheritDoc} 855 */ 856 public TagScmResult tag( ScmRepository repository, ScmFileSet fileSet, String tagName, 857 ScmTagParameters scmTagParameters ) 858 throws ScmException 859 { 860 login( repository, fileSet ); 861 862 CommandParameters parameters = new CommandParameters(); 863 864 parameters.setString( CommandParameter.TAG_NAME, tagName ); 865 866 parameters.setScmTagParameters( CommandParameter.SCM_TAG_PARAMETERS, scmTagParameters ); 867 868 return tag( repository.getProviderRepository(), fileSet, parameters ); 869 } 870 871 protected TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 872 throws ScmException 873 { 874 throw new NoSuchCommandScmException( "tag" ); 875 } 876 877 /** 878 * {@inheritDoc} 879 */ 880 public UnEditScmResult unedit( ScmRepository repository, ScmFileSet fileSet ) 881 throws ScmException 882 { 883 login( repository, fileSet ); 884 885 CommandParameters parameters = new CommandParameters(); 886 887 return unedit( repository.getProviderRepository(), fileSet, parameters ); 888 } 889 890 protected UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet, 891 CommandParameters parameters ) 892 throws ScmException 893 { 894 if ( getLogger().isWarnEnabled() ) 895 { 896 getLogger().warn( "Provider " + this.getScmType() + " does not support unedit operation." ); 897 } 898 899 return new UnEditScmResult( "", null, null, true ); 900 } 901 902 /** 903 * {@inheritDoc} 904 * 905 * @deprecated 906 */ 907 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag ) 908 throws ScmException 909 { 910 return update( repository, fileSet, tag, true ); 911 } 912 913 /** 914 * {@inheritDoc} 915 * 916 * @deprecated 917 */ 918 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag, boolean runChangelog ) 919 throws ScmException 920 { 921 return update( repository, fileSet, tag, "", runChangelog ); 922 } 923 924 /** 925 * {@inheritDoc} 926 */ 927 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet ) 928 throws ScmException 929 { 930 return update( repository, fileSet, (ScmVersion) null, true ); 931 } 932 933 /** 934 * {@inheritDoc} 935 */ 936 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion ) 937 throws ScmException 938 { 939 return update( repository, fileSet, scmVersion, true ); 940 } 941 942 /** 943 * {@inheritDoc} 944 */ 945 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, boolean runChangelog ) 946 throws ScmException 947 { 948 return update( repository, fileSet, (ScmVersion) null, "", runChangelog ); 949 } 950 951 /** 952 * {@inheritDoc} 953 */ 954 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 955 boolean runChangelog ) 956 throws ScmException 957 { 958 return update( repository, fileSet, scmVersion, "", runChangelog ); 959 } 960 961 /** 962 * {@inheritDoc} 963 * 964 * @deprecated 965 */ 966 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag, String datePattern ) 967 throws ScmException 968 { 969 return update( repository, fileSet, tag, datePattern, true ); 970 } 971 972 /** 973 * {@inheritDoc} 974 */ 975 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 976 String datePattern ) 977 throws ScmException 978 { 979 return update( repository, fileSet, scmVersion, datePattern, true ); 980 } 981 982 /** 983 * @deprecated 984 */ 985 private UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag, String datePattern, 986 boolean runChangelog ) 987 throws ScmException 988 { 989 ScmBranch scmBranch = null; 990 991 if ( StringUtils.isNotEmpty( tag ) ) 992 { 993 scmBranch = new ScmBranch( tag ); 994 } 995 996 return update( repository, fileSet, scmBranch, datePattern, runChangelog ); 997 } 998 999 private UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 1000 String datePattern, boolean runChangelog ) 1001 throws ScmException 1002 { 1003 login( repository, fileSet ); 1004 1005 CommandParameters parameters = new CommandParameters(); 1006 1007 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 1008 1009 parameters.setString( CommandParameter.CHANGELOG_DATE_PATTERN, datePattern ); 1010 1011 parameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, String.valueOf( runChangelog ) ); 1012 1013 return update( repository.getProviderRepository(), fileSet, parameters ); 1014 } 1015 1016 /** 1017 * {@inheritDoc} 1018 * 1019 * @deprecated 1020 */ 1021 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag, Date lastUpdate ) 1022 throws ScmException 1023 { 1024 return update( repository, fileSet, tag, lastUpdate, null ); 1025 } 1026 1027 /** 1028 * {@inheritDoc} 1029 */ 1030 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, 1031 Date lastUpdate ) 1032 throws ScmException 1033 { 1034 return update( repository, fileSet, scmVersion, lastUpdate, null ); 1035 } 1036 1037 /** 1038 * {@inheritDoc} 1039 * 1040 * @deprecated 1041 */ 1042 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, String tag, Date lastUpdate, 1043 String datePattern ) 1044 throws ScmException 1045 { 1046 ScmBranch scmBranch = null; 1047 1048 if ( StringUtils.isNotEmpty( tag ) ) 1049 { 1050 scmBranch = new ScmBranch( tag ); 1051 } 1052 1053 return update( repository, fileSet, scmBranch, lastUpdate, datePattern ); 1054 } 1055 1056 /** 1057 * {@inheritDoc} 1058 */ 1059 public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, Date lastUpdate, 1060 String datePattern ) 1061 throws ScmException 1062 { 1063 login( repository, fileSet ); 1064 1065 CommandParameters parameters = new CommandParameters(); 1066 1067 parameters.setScmVersion( CommandParameter.SCM_VERSION, scmVersion ); 1068 1069 if ( lastUpdate != null ) 1070 { 1071 parameters.setDate( CommandParameter.START_DATE, lastUpdate ); 1072 } 1073 1074 parameters.setString( CommandParameter.CHANGELOG_DATE_PATTERN, datePattern ); 1075 1076 parameters.setString( CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true" ); 1077 1078 return update( repository.getProviderRepository(), fileSet, parameters ); 1079 } 1080 1081 protected UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, 1082 CommandParameters parameters ) 1083 throws ScmException 1084 { 1085 throw new NoSuchCommandScmException( "update" ); 1086 } 1087 1088 /** 1089 * {@inheritDoc} 1090 */ 1091 public BlameScmResult blame( ScmRepository repository, ScmFileSet fileSet, String filename ) 1092 throws ScmException 1093 { 1094 login( repository, fileSet ); 1095 1096 CommandParameters parameters = new CommandParameters(); 1097 1098 parameters.setString( CommandParameter.FILE, filename ); 1099 1100 return blame( repository.getProviderRepository(), fileSet, parameters ); 1101 } 1102 1103 protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 1104 throws ScmException 1105 { 1106 throw new NoSuchCommandScmException( "blame" ); 1107 } 1108 1109 public BlameScmResult blame( BlameScmRequest blameScmRequest ) 1110 throws ScmException 1111 { 1112 return blame( blameScmRequest.getScmRepository().getProviderRepository(), blameScmRequest.getScmFileSet(), 1113 blameScmRequest.getCommandParameters() ); 1114 } 1115 1116 public InfoScmResult info( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) 1117 throws ScmException 1118 { 1119 return null; 1120 } 1121 1122 public RemoteInfoScmResult remoteInfo( ScmProviderRepository repository, ScmFileSet fileSet, 1123 CommandParameters parameters ) 1124 throws ScmException 1125 { 1126 return null; 1127 } 1128 1129 // ---------------------------------------------------------------------- 1130 // 1131 // ---------------------------------------------------------------------- 1132 1133 /** 1134 * {@inheritDoc} 1135 */ 1136 public void addListener( ScmLogger logger ) 1137 { 1138 logDispatcher.addListener( logger ); 1139 } 1140 1141 public ScmLogger getLogger() 1142 { 1143 return logDispatcher; 1144 } 1145 1146 /** 1147 * {@inheritDoc} 1148 */ 1149 public ScmProviderRepository makeProviderScmRepository( File path ) 1150 throws ScmRepositoryException, UnknownRepositoryStructure 1151 { 1152 throw new UnknownRepositoryStructure(); 1153 } 1154}