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