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