Coverage Report - org.apache.maven.report.projectinfo.ScmReport
 
Classes in this File Line Coverage Branch Coverage Complexity
ScmReport
100 %
7/7
N/A
4,043
ScmReport$ScmRenderer
28 %
75/265
26 %
31/116
4,043
 
 1  
 package org.apache.maven.report.projectinfo;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.commons.lang.SystemUtils;
 23  
 import org.apache.maven.doxia.sink.Sink;
 24  
 import org.apache.maven.model.Model;
 25  
 import org.apache.maven.model.Scm;
 26  
 import org.apache.maven.plugin.logging.Log;
 27  
 import org.apache.maven.plugins.annotations.Component;
 28  
 import org.apache.maven.plugins.annotations.Mojo;
 29  
 import org.apache.maven.plugins.annotations.Parameter;
 30  
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 31  
 import org.apache.maven.scm.manager.ScmManager;
 32  
 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
 33  
 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
 34  
 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
 35  
 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
 36  
 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
 37  
 import org.apache.maven.scm.repository.ScmRepository;
 38  
 import org.apache.maven.scm.repository.ScmRepositoryException;
 39  
 import org.codehaus.plexus.i18n.I18N;
 40  
 import org.codehaus.plexus.util.StringUtils;
 41  
 
 42  
 import java.util.ArrayList;
 43  
 import java.util.List;
 44  
 import java.util.Locale;
 45  
 
 46  
 /**
 47  
  * Generates the Project Source Code Management (SCM) report.
 48  
  *
 49  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
 50  
  * @version $Id: ScmReport.java 1367255 2012-07-30 20:01:21Z hboutemy $
 51  
  * @since 2.0
 52  
  */
 53  
 @Mojo( name = "scm" )
 54  4
 public class ScmReport
 55  
     extends AbstractProjectInfoReport
 56  
 {
 57  
     // ----------------------------------------------------------------------
 58  
     // Mojo parameters
 59  
     // ----------------------------------------------------------------------
 60  
 
 61  
     /**
 62  
      * Maven SCM Manager.
 63  
      */
 64  
     @Component
 65  
     protected ScmManager scmManager;
 66  
 
 67  
     /**
 68  
      * The directory name to checkout right after the SCM URL.
 69  
      */
 70  
     @Parameter( defaultValue = "${project.artifactId}", required = true )
 71  
     private String checkoutDirectoryName;
 72  
 
 73  
     /**
 74  
      * The SCM anonymous connection url respecting the SCM URL Format.
 75  
      *
 76  
      * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
 77  
      * @since 2.1
 78  
      */
 79  
     @Parameter( defaultValue = "${project.scm.connection}" )
 80  
     private String anonymousConnection;
 81  
 
 82  
     /**
 83  
      * The SCM developer connection url respecting the SCM URL Format.
 84  
      *
 85  
      * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
 86  
      * @since 2.1
 87  
      */
 88  
     @Parameter( defaultValue = "${project.scm.developerConnection}" )
 89  
     private String developerConnection;
 90  
 
 91  
     /**
 92  
      * The SCM web access url.
 93  
      *
 94  
      * @since 2.1
 95  
      */
 96  
     @Parameter( defaultValue = "${project.scm.url}" )
 97  
     private String webAccessUrl;
 98  
 
 99  
     // ----------------------------------------------------------------------
 100  
     // Public methods
 101  
     // ----------------------------------------------------------------------
 102  
 
 103  
     @Override
 104  
     public void executeReport( Locale locale )
 105  
     {
 106  4
         ScmRenderer r =
 107  
             new ScmRenderer( getLog(), scmManager, getSink(), getProject().getModel(), getI18N( locale ), locale,
 108  
                              checkoutDirectoryName, webAccessUrl, anonymousConnection, developerConnection );
 109  
 
 110  4
         r.render();
 111  1
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     public String getOutputName()
 115  
     {
 116  5
         return "source-repository";
 117  
     }
 118  
 
 119  
     @Override
 120  
     protected String getI18Nsection()
 121  
     {
 122  4
         return "scm";
 123  
     }
 124  
 
 125  
     // ----------------------------------------------------------------------
 126  
     // Private
 127  
     // ----------------------------------------------------------------------
 128  
 
 129  
     /**
 130  
      * Internal renderer class
 131  
      */
 132  4
     private static class ScmRenderer
 133  
         extends AbstractProjectInfoRenderer
 134  
     {
 135  
         private Log log;
 136  
 
 137  
         private Model model;
 138  
 
 139  
         private ScmManager scmManager;
 140  
 
 141  
         /**
 142  
          * To support more SCM
 143  
          */
 144  
         private String anonymousConnection;
 145  
 
 146  
         private String devConnection;
 147  
 
 148  
         private String checkoutDirectoryName;
 149  
 
 150  
         private String webAccessUrl;
 151  
 
 152  
         ScmRenderer( Log log, ScmManager scmManager, Sink sink, Model model, I18N i18n, Locale locale,
 153  
                      String checkoutDirName, String webAccessUrl, String anonymousConnection, String devConnection )
 154  
         {
 155  4
             super( sink, i18n, locale );
 156  
 
 157  4
             this.log = log;
 158  
 
 159  4
             this.scmManager = scmManager;
 160  
 
 161  4
             this.model = model;
 162  
 
 163  4
             this.checkoutDirectoryName = checkoutDirName;
 164  
 
 165  4
             this.webAccessUrl = webAccessUrl;
 166  
 
 167  4
             this.anonymousConnection = anonymousConnection;
 168  
 
 169  4
             this.devConnection = devConnection;
 170  
 
 171  4
         }
 172  
 
 173  
         @Override
 174  
         protected String getI18Nsection()
 175  
         {
 176  10
             return "scm";
 177  
         }
 178  
 
 179  
         @Override
 180  
         public void renderBody()
 181  
         {
 182  4
             Scm scm = model.getScm();
 183  4
             if ( scm == null )
 184  
             {
 185  0
                 startSection( getTitle() );
 186  
 
 187  0
                 paragraph( getI18nString( "noscm" ) );
 188  
 
 189  0
                 endSection();
 190  
 
 191  0
                 return;
 192  
             }
 193  
 
 194  4
             if ( StringUtils.isEmpty( anonymousConnection ) && StringUtils.isEmpty( devConnection )
 195  
                 && StringUtils.isEmpty( scm.getUrl() ) )
 196  
             {
 197  0
                 startSection( getTitle() );
 198  
 
 199  0
                 paragraph( getI18nString( "noscm" ) );
 200  
 
 201  0
                 endSection();
 202  
 
 203  0
                 return;
 204  
             }
 205  
 
 206  4
             ScmRepository anonymousRepository = getScmRepository( anonymousConnection );
 207  1
             ScmRepository devRepository = getScmRepository( devConnection );
 208  
 
 209  
             // Overview section
 210  1
             renderOverViewSection( anonymousRepository );
 211  
 
 212  
             // Web access section
 213  1
             renderWebAccesSection( webAccessUrl );
 214  
 
 215  
             // Anonymous access section if needed
 216  1
             renderAnonymousAccessSection( anonymousRepository );
 217  
 
 218  
             // Developer access section
 219  1
             renderDeveloperAccessSection( devRepository );
 220  
 
 221  
             // Access from behind a firewall section if needed
 222  1
             renderAccessBehindFirewallSection( devRepository );
 223  
 
 224  
             // Access through a proxy section if needed
 225  1
             renderAccessThroughProxySection( anonymousRepository, devRepository );
 226  1
         }
 227  
 
 228  
         /**
 229  
          * Render the overview section
 230  
          *
 231  
          * @param anonymousRepository the anonymous repository
 232  
          */
 233  
         private void renderOverViewSection( ScmRepository anonymousRepository )
 234  
         {
 235  1
             startSection( getI18nString( "overview.title" ) );
 236  
 
 237  1
             if ( isScmSystem( anonymousRepository, "clearcase" ) )
 238  
             {
 239  0
                 sink.paragraph();
 240  0
                 linkPatternedText( getI18nString( "clearcase.intro" ) );
 241  0
                 sink.paragraph_();
 242  
             }
 243  1
             else if ( isScmSystem( anonymousRepository, "cvs" ) )
 244  
             {
 245  0
                 sink.paragraph();
 246  0
                 linkPatternedText( getI18nString( "cvs.intro" ) );
 247  0
                 sink.paragraph_();
 248  
             }
 249  1
             else if ( isScmSystem( anonymousRepository, "hg" ) )
 250  
             {
 251  0
                 sink.paragraph();
 252  0
                 linkPatternedText( getI18nString( "hg.intro" ) );
 253  0
                 sink.paragraph_();
 254  
             }
 255  1
             else if ( isScmSystem( anonymousRepository, "perforce" ) )
 256  
             {
 257  0
                 sink.paragraph();
 258  0
                 linkPatternedText( getI18nString( "perforce.intro" ) );
 259  0
                 sink.paragraph_();
 260  
             }
 261  1
             else if ( isScmSystem( anonymousRepository, "starteam" ) )
 262  
             {
 263  0
                 sink.paragraph();
 264  0
                 linkPatternedText( getI18nString( "starteam.intro" ) );
 265  0
                 sink.paragraph_();
 266  
             }
 267  1
             else if ( isScmSystem( anonymousRepository, "svn" ) )
 268  
             {
 269  0
                 sink.paragraph();
 270  0
                 linkPatternedText( getI18nString( "svn.intro" ) );
 271  0
                 sink.paragraph_();
 272  
             }
 273  
             else
 274  
             {
 275  1
                 paragraph( getI18nString( "general.intro" ) );
 276  
             }
 277  
 
 278  1
             endSection();
 279  1
         }
 280  
 
 281  
         /**
 282  
          * Render the web access section
 283  
          *
 284  
          * @param scmUrl The URL to the project's browsable repository.
 285  
          */
 286  
         private void renderWebAccesSection( String scmUrl )
 287  
         {
 288  1
             startSection( getI18nString( "webaccess.title" ) );
 289  
 
 290  1
             if ( StringUtils.isEmpty( scmUrl ) )
 291  
             {
 292  1
                 paragraph( getI18nString( "webaccess.nourl" ) );
 293  
             }
 294  
             else
 295  
             {
 296  0
                 paragraph( getI18nString( "webaccess.url" ) );
 297  
 
 298  0
                 verbatimLink( scmUrl, scmUrl );
 299  
             }
 300  
 
 301  1
             endSection();
 302  1
         }
 303  
 
 304  
         /**
 305  
          * Render the anonymous access section depending the repository.
 306  
          * <p>Note: ClearCase, Starteam et Perforce seems to have no anonymous access.</p>
 307  
          *
 308  
          * @param anonymousRepository the anonymous repository
 309  
          */
 310  
         private void renderAnonymousAccessSection( ScmRepository anonymousRepository )
 311  
         {
 312  1
             if ( isScmSystem( anonymousRepository, "clearcase" ) || isScmSystem( anonymousRepository, "perforce" )
 313  
                 || isScmSystem( anonymousRepository, "starteam" ) || StringUtils.isEmpty( anonymousConnection ) )
 314  
             {
 315  1
                 return;
 316  
             }
 317  
 
 318  0
             startSection( getI18nString( "anonymousaccess.title" ) );
 319  
 
 320  0
             if ( anonymousRepository != null && isScmSystem( anonymousRepository, "cvs" ) )
 321  
             {
 322  0
                 CvsScmProviderRepository cvsRepo = (CvsScmProviderRepository) anonymousRepository
 323  
                     .getProviderRepository();
 324  
 
 325  0
                 anonymousAccessCVS( cvsRepo );
 326  
             }
 327  0
             if ( anonymousRepository != null && isScmSystem( anonymousRepository, "hg" ) )
 328  
             {
 329  0
                 HgScmProviderRepository hgRepo = (HgScmProviderRepository) anonymousRepository
 330  
                     .getProviderRepository();
 331  
 
 332  0
                 anonymousAccessMercurial( hgRepo );
 333  0
             }
 334  0
             else if ( anonymousRepository != null && isScmSystem( anonymousRepository, "svn" ) )
 335  
             {
 336  0
                 SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) anonymousRepository
 337  
                     .getProviderRepository();
 338  
 
 339  0
                 anonymousAccessSVN( svnRepo );
 340  0
             }
 341  
             else
 342  
             {
 343  0
                 paragraph( getI18nString( "anonymousaccess.general.intro" ) );
 344  
 
 345  0
                 verbatimText( anonymousConnection.substring( 4 ) );
 346  
             }
 347  
 
 348  0
             endSection();
 349  0
         }
 350  
 
 351  
         /**
 352  
          * Render the developer access section
 353  
          *
 354  
          * @param devRepository the dev repository
 355  
          */
 356  
         private void renderDeveloperAccessSection( ScmRepository devRepository )
 357  
         {
 358  1
             if ( StringUtils.isEmpty( devConnection ) )
 359  
             {
 360  1
                 return;
 361  
             }
 362  
 
 363  0
             startSection( getI18nString( "devaccess.title" ) );
 364  
 
 365  0
             if ( devRepository != null && isScmSystem( devRepository, "clearcase" ) )
 366  
             {
 367  0
                 developerAccessClearCase();
 368  
             }
 369  0
             else if ( devRepository != null && isScmSystem( devRepository, "cvs" ) )
 370  
             {
 371  0
                 CvsScmProviderRepository cvsRepo = (CvsScmProviderRepository) devRepository.getProviderRepository();
 372  
 
 373  0
                 developerAccessCVS( cvsRepo );
 374  0
             }
 375  0
             else if ( devRepository != null && isScmSystem( devRepository, "hg" ) )
 376  
             {
 377  0
                 HgScmProviderRepository hgRepo = (HgScmProviderRepository) devRepository.getProviderRepository();
 378  
 
 379  0
                 developerAccessMercurial( hgRepo );
 380  0
             }
 381  0
             else if ( devRepository != null && isScmSystem( devRepository, "perforce" ) )
 382  
             {
 383  0
                 PerforceScmProviderRepository perforceRepo = (PerforceScmProviderRepository) devRepository
 384  
                     .getProviderRepository();
 385  
 
 386  0
                 developerAccessPerforce( perforceRepo );
 387  0
             }
 388  0
             else if ( devRepository != null && isScmSystem( devRepository, "starteam" ) )
 389  
             {
 390  0
                 StarteamScmProviderRepository starteamRepo = (StarteamScmProviderRepository) devRepository
 391  
                     .getProviderRepository();
 392  
 
 393  0
                 developerAccessStarteam( starteamRepo );
 394  0
             }
 395  0
             else if ( devRepository != null && isScmSystem( devRepository, "svn" ) )
 396  
             {
 397  0
                 SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) devRepository.getProviderRepository();
 398  
 
 399  0
                 developerAccessSVN( svnRepo );
 400  0
             }
 401  
             else
 402  
             {
 403  0
                 paragraph( getI18nString( "devaccess.general.intro" ) );
 404  
 
 405  0
                 verbatimText( devConnection.substring( 4 ) );
 406  
             }
 407  
 
 408  0
             endSection();
 409  0
         }
 410  
 
 411  
         /**
 412  
          * Render the access from behind a firewall section
 413  
          *
 414  
          * @param devRepository the dev repository
 415  
          */
 416  
         private void renderAccessBehindFirewallSection( ScmRepository devRepository )
 417  
         {
 418  1
             startSection( getI18nString( "accessbehindfirewall.title" ) );
 419  
 
 420  1
             if ( devRepository != null && isScmSystem( devRepository, "svn" ) )
 421  
             {
 422  0
                 SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) devRepository.getProviderRepository();
 423  
 
 424  0
                 paragraph( getI18nString( "accessbehindfirewall.svn.intro" ) );
 425  
 
 426  0
                 StringBuffer sb = new StringBuffer();
 427  0
                 sb.append( "$ svn checkout " ).append( svnRepo.getUrl() );
 428  0
                 sb.append( " " ).append( checkoutDirectoryName );
 429  0
                 verbatimText( sb.toString() );
 430  0
             }
 431  1
             else if ( devRepository != null && isScmSystem( devRepository, "cvs" ) )
 432  
             {
 433  0
                 linkPatternedText( getI18nString( "accessbehindfirewall.cvs.intro" ) );
 434  
             }
 435  
             else
 436  
             {
 437  1
                 paragraph( getI18nString( "accessbehindfirewall.general.intro" ) );
 438  
             }
 439  
 
 440  1
             endSection();
 441  1
         }
 442  
 
 443  
         /**
 444  
          * Render the access from behind a firewall section
 445  
          *
 446  
          * @param anonymousRepository the anonymous repository
 447  
          * @param devRepository the dev repository
 448  
          */
 449  
         private void renderAccessThroughProxySection( ScmRepository anonymousRepository, ScmRepository devRepository )
 450  
         {
 451  1
             if ( isScmSystem( anonymousRepository, "svn" ) || isScmSystem( devRepository, "svn" ) )
 452  
             {
 453  0
                 startSection( getI18nString( "accessthroughtproxy.title" ) );
 454  
 
 455  0
                 paragraph( getI18nString( "accessthroughtproxy.svn.intro1" ) );
 456  0
                 paragraph( getI18nString( "accessthroughtproxy.svn.intro2" ) );
 457  0
                 paragraph( getI18nString( "accessthroughtproxy.svn.intro3" ) );
 458  
 
 459  0
                 StringBuffer sb = new StringBuffer();
 460  0
                 sb.append( "[global]" );
 461  0
                 sb.append( SystemUtils.LINE_SEPARATOR );
 462  0
                 sb.append( "http-proxy-host = your.proxy.name" ).append( SystemUtils.LINE_SEPARATOR );
 463  0
                 sb.append( "http-proxy-port = 3128" ).append( SystemUtils.LINE_SEPARATOR );
 464  0
                 verbatimText( sb.toString() );
 465  
 
 466  0
                 endSection();
 467  
             }
 468  1
         }
 469  
 
 470  
         // Clearcase
 471  
 
 472  
         /**
 473  
          * Create the documentation to provide an developer access with a <code>Clearcase</code> SCM.
 474  
          * For example, generate the following command line:
 475  
          * <p>cleartool checkout module</p>
 476  
          */
 477  
         private void developerAccessClearCase()
 478  
         {
 479  0
             paragraph( getI18nString( "devaccess.clearcase.intro" ) );
 480  
 
 481  0
             StringBuffer command = new StringBuffer();
 482  0
             command.append( "$ cleartool checkout " );
 483  
 
 484  0
             verbatimText( command.toString() );
 485  0
         }
 486  
 
 487  
         // CVS
 488  
 
 489  
         /**
 490  
          * Create the documentation to provide an anonymous access with a <code>CVS</code> SCM.
 491  
          * For example, generate the following command line:
 492  
          * <p>cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login</p>
 493  
          * <p>cvs -z3 -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic co maven-plugins/dist</p>
 494  
          *
 495  
          * @param cvsRepo
 496  
          * @see <a href="https://www.cvshome.org/docs/manual/cvs-1.12.12/cvs_16.html#SEC115">https://www.cvshome.org/docs/manual/cvs-1.12.12/cvs_16.html#SEC115</a>
 497  
          */
 498  
         private void anonymousAccessCVS( CvsScmProviderRepository cvsRepo )
 499  
         {
 500  0
             paragraph( getI18nString( "anonymousaccess.cvs.intro" ) );
 501  
 
 502  0
             StringBuffer command = new StringBuffer();
 503  0
             command.append( "$ cvs -d " ).append( cvsRepo.getCvsRoot() ).append( " login" );
 504  0
             command.append( SystemUtils.LINE_SEPARATOR );
 505  0
             command.append( "$ cvs -z3 -d " ).append( cvsRepo.getCvsRoot() );
 506  0
             command.append( " co " ).append( cvsRepo.getModule() );
 507  
 
 508  0
             verbatimText( command.toString() );
 509  0
         }
 510  
 
 511  
         // Mercurial
 512  
 
 513  
         /**
 514  
          * Create the documentation to provide an anonymous access with a <code>Mercurial</code> SCM.
 515  
          * For example, generate the following command line:
 516  
          * <p>hg clone uri</p>
 517  
          *
 518  
          * @param hgRepo
 519  
          */
 520  
         private void anonymousAccessMercurial( HgScmProviderRepository hgRepo )
 521  
         {
 522  0
             sink.paragraph();
 523  0
             linkPatternedText( getI18nString( "anonymousaccess.hg.intro" ) );
 524  0
             sink.paragraph_();
 525  
 
 526  0
             StringBuffer command = new StringBuffer();
 527  0
             command.append( "$ hg clone " ).append( hgRepo.getURI() );
 528  
 
 529  0
             verbatimText( command.toString() );
 530  0
         }
 531  
 
 532  
         /**
 533  
          * Create the documentation to provide an developer access with a <code>CVS</code> SCM.
 534  
          * For example, generate the following command line:
 535  
          * <p>cvs -d :pserver:username@cvs.apache.org:/home/cvs login</p>
 536  
          * <p>cvs -z3 -d :ext:username@cvs.apache.org:/home/cvs co maven-plugins/dist</p>
 537  
          *
 538  
          * @param cvsRepo
 539  
          * @see <a href="https://www.cvshome.org/docs/manual/cvs-1.12.12/cvs_16.html#SEC115">https://www.cvshome.org/docs/manual/cvs-1.12.12/cvs_16.html#SEC115</a>
 540  
          */
 541  
         private void developerAccessCVS( CvsScmProviderRepository cvsRepo )
 542  
         {
 543  0
             paragraph( getI18nString( "devaccess.cvs.intro" ) );
 544  
 
 545  
             // Safety: remove the username if present
 546  0
             String cvsRoot = StringUtils.replace( cvsRepo.getCvsRoot(), cvsRepo.getUser(), "username" );
 547  
 
 548  0
             StringBuffer command = new StringBuffer();
 549  0
             command.append( "$ cvs -d " ).append( cvsRoot ).append( " login" );
 550  0
             command.append( SystemUtils.LINE_SEPARATOR );
 551  0
             command.append( "$ cvs -z3 -d " ).append( cvsRoot ).append( " co " ).append( cvsRepo.getModule() );
 552  
 
 553  0
             verbatimText( command.toString() );
 554  0
         }
 555  
 
 556  
         // Mercurial
 557  
 
 558  
         /**
 559  
          * Create the documentation to provide an developer access with a <code>Mercurial</code> SCM.
 560  
          * For example, generate the following command line:
 561  
          * <p>hg clone repo </p>
 562  
          *
 563  
          * @param hgRepo
 564  
          */
 565  
         private void developerAccessMercurial( HgScmProviderRepository hgRepo )
 566  
         {
 567  0
             sink.paragraph();
 568  0
             linkPatternedText( getI18nString( "devaccess.hg.intro" ) );
 569  0
             sink.paragraph_();
 570  
 
 571  0
             StringBuffer command = new StringBuffer();
 572  0
             command.append( "$ hg clone " );
 573  0
             command.append( hgRepo.getURI() );
 574  
 
 575  0
             verbatimText( command.toString() );
 576  0
         }
 577  
 
 578  
         // Perforce
 579  
 
 580  
         /**
 581  
          * Create the documentation to provide an developer access with a <code>Perforce</code> SCM.
 582  
          * For example, generate the following command line:
 583  
          * <p>p4 -H hostname -p port -u username -P password path</p>
 584  
          * <p>p4 -H hostname -p port -u username -P password path submit -c changement</p>
 585  
          *
 586  
          * @param perforceRepo
 587  
          * @see <a href="http://www.perforce.com/perforce/doc.051/manuals/cmdref/index.html">http://www.perforce.com/perforce/doc.051/manuals/cmdref/index.html</>
 588  
          */
 589  
         private void developerAccessPerforce( PerforceScmProviderRepository perforceRepo )
 590  
         {
 591  0
             paragraph( getI18nString( "devaccess.perforce.intro" ) );
 592  
 
 593  0
             StringBuffer command = new StringBuffer();
 594  0
             command.append( "$ p4" );
 595  0
             if ( !StringUtils.isEmpty( perforceRepo.getHost() ) )
 596  
             {
 597  0
                 command.append( " -H " ).append( perforceRepo.getHost() );
 598  
             }
 599  0
             if ( perforceRepo.getPort() > 0 )
 600  
             {
 601  0
                 command.append( " -p " ).append( perforceRepo.getPort() );
 602  
             }
 603  0
             command.append( " -u username" );
 604  0
             command.append( " -P password" );
 605  0
             command.append( " " );
 606  0
             command.append( perforceRepo.getPath() );
 607  0
             command.append( SystemUtils.LINE_SEPARATOR );
 608  0
             command.append( "$ p4 submit -c \"A comment\"" );
 609  
 
 610  0
             verbatimText( command.toString() );
 611  0
         }
 612  
 
 613  
         // Starteam
 614  
 
 615  
         /**
 616  
          * Create the documentation to provide an developer access with a <code>Starteam</code> SCM.
 617  
          * For example, generate the following command line:
 618  
          * <p>stcmd co -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl -is</p>
 619  
          * <p>stcmd ci -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl -f NCI -is</p>
 620  
          *
 621  
          * @param starteamRepo
 622  
          */
 623  
         private void developerAccessStarteam( StarteamScmProviderRepository starteamRepo )
 624  
         {
 625  0
             paragraph( getI18nString( "devaccess.starteam.intro" ) );
 626  
 
 627  0
             StringBuffer command = new StringBuffer();
 628  
 
 629  
             // Safety: remove the username/password if present
 630  0
             String fullUrl = StringUtils.replace( starteamRepo.getFullUrl(), starteamRepo.getUser(), "username" );
 631  0
             fullUrl = StringUtils.replace( fullUrl, starteamRepo.getPassword(), "password" );
 632  
 
 633  0
             command.append( "$ stcmd co -x -nologo -stop -p " );
 634  0
             command.append( fullUrl );
 635  0
             command.append( " -is" );
 636  0
             command.append( SystemUtils.LINE_SEPARATOR );
 637  0
             command.append( "$ stcmd ci -x -nologo -stop -p " );
 638  0
             command.append( fullUrl );
 639  0
             command.append( " -f NCI -is" );
 640  
 
 641  0
             verbatimText( command.toString() );
 642  0
         }
 643  
 
 644  
         // SVN
 645  
 
 646  
         /**
 647  
          * Create the documentation to provide an anonymous access with a <code>SVN</code> SCM.
 648  
          * For example, generate the following command line:
 649  
          * <p>svn checkout http://svn.apache.org/repos/asf/maven/components/trunk maven</p>
 650  
          *
 651  
          * @param svnRepo
 652  
          * @see <a href="http://svnbook.red-bean.com/">http://svnbook.red-bean.com/</a>
 653  
          */
 654  
         private void anonymousAccessSVN( SvnScmProviderRepository svnRepo )
 655  
         {
 656  0
             paragraph( getI18nString( "anonymousaccess.svn.intro" ) );
 657  
 
 658  0
             StringBuffer sb = new StringBuffer();
 659  0
             sb.append( "$ svn checkout " ).append( svnRepo.getUrl() ).append( " " ).append( checkoutDirectoryName );
 660  
 
 661  0
             verbatimText( sb.toString() );
 662  0
         }
 663  
 
 664  
         /**
 665  
          * Create the documentation to provide an developer access with a <code>SVN</code> SCM.
 666  
          * For example, generate the following command line:
 667  
          * <p>svn checkout https://svn.apache.org/repos/asf/maven/components/trunk maven</p>
 668  
          * <p>svn commit --username your-username -m "A message"</p>
 669  
          *
 670  
          * @param svnRepo
 671  
          * @see <a href="http://svnbook.red-bean.com/">http://svnbook.red-bean.com/</a>
 672  
          */
 673  
         private void developerAccessSVN( SvnScmProviderRepository svnRepo )
 674  
         {
 675  0
             if ( svnRepo.getUrl() != null )
 676  
             {
 677  0
                 if ( svnRepo.getUrl().startsWith( "https://" ) )
 678  
                 {
 679  0
                     paragraph( getI18nString( "devaccess.svn.intro1.https" ) );
 680  
                 }
 681  0
                 else if ( svnRepo.getUrl().startsWith( "svn://" ) )
 682  
                 {
 683  0
                     paragraph( getI18nString( "devaccess.svn.intro1.svn" ) );
 684  
                 }
 685  0
                 else if ( svnRepo.getUrl().startsWith( "svn+ssh://" ) )
 686  
                 {
 687  0
                     paragraph( getI18nString( "devaccess.svn.intro1.svnssh" ) );
 688  
                 }
 689  
                 else
 690  
                 {
 691  0
                     paragraph( getI18nString( "devaccess.svn.intro1.other" ) );
 692  
                 }
 693  
             }
 694  
 
 695  0
             StringBuffer sb = new StringBuffer();
 696  
 
 697  0
             sb.append( "$ svn checkout " ).append( svnRepo.getUrl() ).append( " " ).append( checkoutDirectoryName );
 698  
 
 699  0
             verbatimText( sb.toString() );
 700  
 
 701  0
             paragraph( getI18nString( "devaccess.svn.intro2" ) );
 702  
 
 703  0
             sb = new StringBuffer();
 704  0
             sb.append( "$ svn commit --username your-username -m \"A message\"" );
 705  
 
 706  0
             verbatimText( sb.toString() );
 707  0
         }
 708  
 
 709  
         /**
 710  
          * Return a <code>SCM repository</code> defined by a given url
 711  
          *
 712  
          * @param scmUrl an SCM URL
 713  
          * @return a valid SCM repository or null
 714  
          */
 715  
         @SuppressWarnings( "unchecked" )
 716  
         public ScmRepository getScmRepository( String scmUrl )
 717  
         {
 718  5
             if ( StringUtils.isEmpty( scmUrl ) )
 719  
             {
 720  2
                 return null;
 721  
             }
 722  
 
 723  3
             ScmRepository repo = null;
 724  3
             List<String> messages = new ArrayList<String>();
 725  
             try
 726  
             {
 727  3
                 messages.addAll( scmManager.validateScmRepository( scmUrl ) );
 728  
             }
 729  2
             catch ( Exception e )
 730  
             {
 731  2
                 messages.add( e.getMessage() );
 732  1
             }
 733  
 
 734  3
             if ( messages.size() > 0 )
 735  
             {
 736  3
                 StringBuffer sb = new StringBuffer();
 737  3
                 boolean isIntroAdded = false;
 738  3
                 for ( String msg : messages )
 739  
                 {
 740  
                     // Ignore NoSuchScmProviderException msg
 741  
                     // See impl of AbstractScmManager#validateScmRepository()
 742  3
                     if ( msg.startsWith( "No such provider" ) )
 743  
                     {
 744  0
                         continue;
 745  
                     }
 746  
 
 747  3
                     if ( !isIntroAdded )
 748  
                     {
 749  3
                         sb.append( "This SCM url '" + scmUrl + "' is invalid due to the following errors:" );
 750  3
                         sb.append( SystemUtils.LINE_SEPARATOR );
 751  3
                         isIntroAdded = true;
 752  
                     }
 753  3
                     sb.append( " * " );
 754  3
                     sb.append( msg );
 755  3
                     sb.append( SystemUtils.LINE_SEPARATOR );
 756  
                 }
 757  
 
 758  3
                 if ( StringUtils.isNotEmpty( sb.toString() ) )
 759  
                 {
 760  3
                     sb.append( "For more information about SCM URL Format, please refer to: "
 761  
                         + "http://maven.apache.org/scm/scm-url-format.html" );
 762  
 
 763  3
                     throw new IllegalArgumentException( sb.toString() );
 764  
                 }
 765  
             }
 766  
 
 767  
             try
 768  
             {
 769  0
                 repo = scmManager.makeScmRepository( scmUrl );
 770  
             }
 771  0
             catch ( NoSuchScmProviderException e )
 772  
             {
 773  0
                 if ( log.isDebugEnabled() )
 774  
                 {
 775  0
                     log.debug( e.getMessage(), e );
 776  
                 }
 777  
             }
 778  0
             catch ( ScmRepositoryException e )
 779  
             {
 780  0
                 if ( log.isDebugEnabled() )
 781  
                 {
 782  0
                     log.debug( e.getMessage(), e );
 783  
                 }
 784  
             }
 785  0
             catch ( Exception e )
 786  
             {
 787  
                 // Should be already catched
 788  0
                 if ( log.isDebugEnabled() )
 789  
                 {
 790  0
                     log.debug( e.getMessage(), e );
 791  
                 }
 792  0
             }
 793  
 
 794  0
             return repo;
 795  
         }
 796  
 
 797  
         /**
 798  
          * Convenience method that return true is the defined <code>SCM repository</code> is a known provider.
 799  
          * <p>
 800  
          * Actually, we fully support Clearcase, CVS, Perforce, Starteam, SVN by the maven-scm-providers component.
 801  
          * </p>
 802  
          *
 803  
          * @param scmRepository a SCM repository
 804  
          * @param scmProvider a SCM provider name
 805  
          * @return true if the provider of the given SCM repository is equal to the given scm provider.
 806  
          * @see <a href="http://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-providers/">maven-scm-providers</a>
 807  
          */
 808  
         private static boolean isScmSystem( ScmRepository scmRepository, String scmProvider )
 809  
         {
 810  11
             if ( StringUtils.isEmpty( scmProvider ) )
 811  
             {
 812  0
                 return false;
 813  
             }
 814  
 
 815  11
             if ( scmRepository != null && scmProvider.equalsIgnoreCase( scmRepository.getProvider() ) )
 816  
             {
 817  0
                 return true;
 818  
             }
 819  
 
 820  11
             return false;
 821  
         }
 822  
     }
 823  
 }