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