Coverage Report - org.apache.maven.plugins.linkcheck.LinkcheckReport
 
Classes in this File Line Coverage Branch Coverage Complexity
LinkcheckReport
0%
0/538
0%
0/152
4,385
 
 1  
 package org.apache.maven.plugins.linkcheck;
 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 java.io.File;
 23  
 import java.io.FileNotFoundException;
 24  
 import java.io.FileOutputStream;
 25  
 import java.io.IOException;
 26  
 import java.io.OutputStream;
 27  
 import java.io.PrintStream;
 28  
 import java.io.Reader;
 29  
 import java.io.UnsupportedEncodingException;
 30  
 import java.io.Writer;
 31  
 import java.util.ArrayList;
 32  
 import java.util.Arrays;
 33  
 import java.util.Collections;
 34  
 import java.util.Iterator;
 35  
 import java.util.List;
 36  
 import java.util.Locale;
 37  
 import java.util.Properties;
 38  
 
 39  
 import org.apache.commons.io.FilenameUtils;
 40  
 import org.apache.commons.lang.SystemUtils;
 41  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 42  
 import org.apache.maven.doxia.linkcheck.HttpBean;
 43  
 import org.apache.maven.doxia.linkcheck.LinkCheck;
 44  
 import org.apache.maven.doxia.linkcheck.LinkCheckException;
 45  
 import org.apache.maven.doxia.linkcheck.model.LinkcheckFile;
 46  
 import org.apache.maven.doxia.linkcheck.model.LinkcheckFileResult;
 47  
 import org.apache.maven.doxia.linkcheck.model.LinkcheckModel;
 48  
 import org.apache.maven.doxia.siterenderer.Renderer;
 49  
 import org.apache.maven.plugin.MojoExecutionException;
 50  
 import org.apache.maven.project.MavenProject;
 51  
 import org.apache.maven.reporting.AbstractMavenReport;
 52  
 import org.apache.maven.reporting.MavenReportException;
 53  
 import org.apache.maven.settings.Proxy;
 54  
 import org.apache.maven.settings.Settings;
 55  
 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
 56  
 import org.apache.maven.shared.invoker.DefaultInvoker;
 57  
 import org.apache.maven.shared.invoker.InvocationOutputHandler;
 58  
 import org.apache.maven.shared.invoker.InvocationRequest;
 59  
 import org.apache.maven.shared.invoker.InvocationResult;
 60  
 import org.apache.maven.shared.invoker.Invoker;
 61  
 import org.apache.maven.shared.invoker.MavenInvocationException;
 62  
 import org.apache.maven.shared.invoker.PrintStreamHandler;
 63  
 import org.codehaus.plexus.i18n.I18N;
 64  
 import org.codehaus.plexus.util.FileUtils;
 65  
 import org.codehaus.plexus.util.IOUtil;
 66  
 import org.codehaus.plexus.util.ReaderFactory;
 67  
 import org.codehaus.plexus.util.StringUtils;
 68  
 import org.codehaus.plexus.util.WriterFactory;
 69  
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 70  
 
 71  
 /**
 72  
  * Generates a <code>Linkcheck</code> report.
 73  
  *
 74  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 75  
  * @version $Id: LinkcheckReport.java 981302 2010-08-01 20:00:29Z dennisl $
 76  
  * @since 1.0
 77  
  * @goal linkcheck
 78  
  */
 79  0
 public class LinkcheckReport
 80  
     extends AbstractMavenReport
 81  
 {
 82  
     // ----------------------------------------------------------------------
 83  
     // Report Components
 84  
     // ----------------------------------------------------------------------
 85  
 
 86  
     /**
 87  
      * Internationalization.
 88  
      *
 89  
      * @component
 90  
      */
 91  
     private I18N i18n;
 92  
 
 93  
     /**
 94  
      * Doxia Site Renderer.
 95  
      *
 96  
      * @component
 97  
      */
 98  
     private Renderer siteRenderer;
 99  
 
 100  
     /**
 101  
      * LinkCheck component.
 102  
      *
 103  
      * @component
 104  
      */
 105  
     private LinkCheck linkCheck;
 106  
 
 107  
     // ----------------------------------------------------------------------
 108  
     // Report Parameters
 109  
     // ----------------------------------------------------------------------
 110  
 
 111  
     /**
 112  
      * The Maven Project.
 113  
      *
 114  
      * @parameter expression="${project}"
 115  
      * @required
 116  
      * @readonly
 117  
      */
 118  
     private MavenProject project;
 119  
 
 120  
     /**
 121  
      * Local Repository.
 122  
      *
 123  
      * @parameter expression="${localRepository}"
 124  
      * @required
 125  
      * @readonly
 126  
      */
 127  
     private ArtifactRepository localRepository;
 128  
 
 129  
     /**
 130  
      * Report output directory.
 131  
      *
 132  
      * @parameter expression="${project.reporting.outputDirectory}"
 133  
      * @required
 134  
      */
 135  
     private File outputDirectory;
 136  
 
 137  
     /**
 138  
      * The Maven Settings.
 139  
      *
 140  
      * @parameter default-value="${settings}"
 141  
      * @required
 142  
      * @readonly
 143  
      */
 144  
     private Settings settings;
 145  
 
 146  
     // ----------------------------------------------------------------------
 147  
     // Linkcheck parameters
 148  
     // ----------------------------------------------------------------------
 149  
 
 150  
     /**
 151  
      * Whether we are offline or not.
 152  
      *
 153  
      * @parameter default-value="${settings.offline}" expression="${linkcheck.offline}"
 154  
      * @required
 155  
      */
 156  
     private boolean offline;
 157  
 
 158  
     /**
 159  
      * If online, the HTTP method should automatically follow HTTP redirects,
 160  
      * <tt>false</tt> otherwise.
 161  
      *
 162  
      * @parameter default-value="true"
 163  
      */
 164  
     private boolean httpFollowRedirect;
 165  
 
 166  
     /**
 167  
      * The location of the Linkcheck cache file.
 168  
      *
 169  
      * @parameter default-value="${project.build.directory}/linkcheck/linkcheck.cache"
 170  
      * @required
 171  
      */
 172  
     protected File linkcheckCache;
 173  
 
 174  
     /**
 175  
      * The location of the Linkcheck report file.
 176  
      *
 177  
      * @parameter default-value="${project.build.directory}/linkcheck/linkcheck.xml"
 178  
      * @required
 179  
      */
 180  
     protected File linkcheckOutput;
 181  
 
 182  
     /**
 183  
      * The HTTP method to use. Currently supported are "GET" and "HEAD".
 184  
      * <dl>
 185  
      * <dt>HTTP GET</dt>
 186  
      * <dd>
 187  
      * The HTTP GET method is defined in section 9.3 of
 188  
      * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
 189  
      * The GET method means retrieve whatever information (in the form of an
 190  
      * entity) is identified by the Request-URI.
 191  
      * </dd>
 192  
      * <dt>HTTP HEAD</dt>
 193  
      * <dd>
 194  
      * The HTTP HEAD method is defined in section 9.4 of
 195  
      * <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>:
 196  
      * The HEAD method is identical to GET except that the server MUST NOT
 197  
      * return a message-body in the response.
 198  
      * </dd>
 199  
      * </dl>
 200  
      *
 201  
      * @parameter default-value="head"
 202  
      * @required
 203  
      */
 204  
     private String httpMethod;
 205  
 
 206  
     /**
 207  
      * The list of HTTP errors to ignored, like <code>404</code>.
 208  
      *
 209  
      * @parameter
 210  
      * @see {@link org.apache.commons.httpclient.HttpStatus} for all defined values.
 211  
      */
 212  
     private int[] excludedHttpStatusErrors;
 213  
 
 214  
     /**
 215  
      * The list of HTTP warnings to ignored, like <code>301</code>.
 216  
      *
 217  
      * @parameter
 218  
      * @see {@link org.apache.commons.httpclient.HttpStatus} for all defined values.
 219  
      */
 220  
     private int[] excludedHttpStatusWarnings;
 221  
 
 222  
     /**
 223  
      * The list of site pages to exclude. By default, this report, i.e. <code>linkcheck.html</code>, will be excluded.
 224  
      * <br/>
 225  
      * <b>Note</b>: No pattern is allowed for excludedPage, only specific file names.
 226  
      *
 227  
      * @parameter
 228  
      */
 229  
     private String[] excludedPages;
 230  
 
 231  
     /**
 232  
      * The list of links to exclude.
 233  
      * <br/>
 234  
      * <b>Note</b>: Patterns like <code>&#42;&#42;/dummy/&#42;</code> are allowed for excludedLink.
 235  
      *
 236  
      * @parameter
 237  
      */
 238  
     private String[] excludedLinks;
 239  
 
 240  
     /**
 241  
      * The file encoding to use when Linkcheck reads the source files. If the property
 242  
      * <code>project.build.sourceEncoding</code> is not set, the platform default encoding is used.
 243  
      *
 244  
      * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
 245  
      */
 246  
     private String encoding;
 247  
 
 248  
     /**
 249  
      * The extra HttpClient parameters to be used when fetching links. For instance:
 250  
      * <pre>
 251  
      * &lt;httpClientParameters&gt;
 252  
      * &nbsp;&lt;property&gt;
 253  
      * &nbsp;&nbsp;&lt;name&gt;http.protocol.max-redirects&lt;/name&gt;
 254  
      * &nbsp;&nbsp;&lt;value&gt;10&lt;/value&gt;
 255  
      * &nbsp;&lt;/property&gt;
 256  
      * &lt;/httpClientParameters&gt;
 257  
      * </pre>
 258  
      * See <a href="http://hc.apache.org/httpclient-3.x/preference-api.html">HttpClient preference page</a>
 259  
      *
 260  
      * @parameter expression="${httpClientParameters}"
 261  
      */
 262  
     private Properties httpClientParameters;
 263  
 
 264  
     /**
 265  
      * Set the timeout to be used when fetching links. A value of zero means the timeout is not used.
 266  
      *
 267  
      * @parameter expression="${timeout}" default-value="2000"
 268  
      */
 269  
     private int timeout;
 270  
 
 271  
     /**
 272  
      * <code>true</code> to skip the report execution, <code>false</code> otherwise.
 273  
      * The purpose is to prevent infinite call when {@link #forceSite} is enable.
 274  
      *
 275  
      * @parameter expression="${linkcheck.skip}" default-value="false"
 276  
      */
 277  
     private boolean skip;
 278  
 
 279  
     /**
 280  
      * <code>true</code> to force the site generation, <code>false</code> otherwise.
 281  
      * Using this parameter ensures that all documents have been correctly generated.
 282  
      *
 283  
      * @parameter expression="${linkcheck.forceSite}" default-value="true"
 284  
      */
 285  
     private boolean forceSite;
 286  
 
 287  
     /**
 288  
      * The base URL to use for absolute links (eg <code>/index.html</code>) in the site.
 289  
      *
 290  
      * @parameter expression="${linkcheck.baseURL}" default-value="${project.url}"
 291  
      */
 292  
     private String baseURL;
 293  
 
 294  
     // ----------------------------------------------------------------------
 295  
     // Instance fields
 296  
     // ----------------------------------------------------------------------
 297  
 
 298  
     /** Result of the linkcheck in {@link #execute()} */
 299  
     private LinkcheckModel result;
 300  
 
 301  
     // ----------------------------------------------------------------------
 302  
     // Public methods
 303  
     // ----------------------------------------------------------------------
 304  
 
 305  
     /** {@inheritDoc} */
 306  
     public String getDescription( Locale locale )
 307  
     {
 308  0
         return i18n.getString( "linkcheck-report", locale, "report.linkcheck.description" );
 309  
     }
 310  
 
 311  
     /** {@inheritDoc} */
 312  
     public String getName( Locale locale )
 313  
     {
 314  0
         return i18n.getString( "linkcheck-report", locale, "report.linkcheck.name" );
 315  
     }
 316  
 
 317  
     /** {@inheritDoc} */
 318  
     public String getOutputName()
 319  
     {
 320  0
         return "linkcheck";
 321  
     }
 322  
 
 323  
     /** {@inheritDoc} */
 324  
     public boolean canGenerateReport()
 325  
     {
 326  0
         if ( skip )
 327  
         {
 328  0
             return false;
 329  
         }
 330  
 
 331  0
         return true;
 332  
     }
 333  
 
 334  
     /** {@inheritDoc} */
 335  
     public void execute()
 336  
         throws MojoExecutionException
 337  
     {
 338  0
         if ( !canGenerateReport() )
 339  
         {
 340  0
             return;
 341  
         }
 342  
 
 343  
         // encoding
 344  0
         if ( StringUtils.isEmpty( encoding ) )
 345  
         {
 346  0
             if ( getLog().isWarnEnabled() )
 347  
             {
 348  0
                 getLog().warn(
 349  
                                "File encoding has not been set, using platform encoding "
 350  
                                    + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
 351  
             }
 352  0
             encoding = ReaderFactory.FILE_ENCODING;
 353  
         }
 354  
 
 355  0
         File tmpReportingOutputDirectory = new File( linkcheckOutput.getParentFile(), "tmpsite" );
 356  0
         tmpReportingOutputDirectory.mkdirs();
 357  
 
 358  
         File basedir;
 359  0
         if ( forceSite )
 360  
         {
 361  0
             basedir = tmpReportingOutputDirectory;
 362  
 
 363  0
             List documents = null;
 364  
             try
 365  
             {
 366  0
                 documents = FileUtils.getFiles( basedir, "**/*.html", null );
 367  
             }
 368  0
             catch ( IOException e )
 369  
             {
 370  0
                 String msg = "IOException: " + e.getMessage();
 371  0
                 if ( getLog().isDebugEnabled() )
 372  
                 {
 373  0
                     getLog().error( msg, e );
 374  
                 }
 375  
                 else
 376  
                 {
 377  0
                     getLog().error( msg );
 378  
                 }
 379  0
             }
 380  
 
 381  
             // if the site was not already generated, invoke it
 382  0
             if ( documents == null || ( documents != null && documents.size() == 0 ) )
 383  
             {
 384  0
                 getLog().info( "Trying to invoke the maven-site-plugin to be sure that all files are generated..." );
 385  
 
 386  
                 try
 387  
                 {
 388  0
                     invokeSite( tmpReportingOutputDirectory );
 389  
                 }
 390  0
                 catch ( IOException e )
 391  
                 {
 392  0
                     throw new MojoExecutionException( "IOException: " + e.getMessage(), e );
 393  0
                 }
 394  
             }
 395  0
         }
 396  
         else
 397  
         {
 398  0
             if ( getLog().isWarnEnabled() )
 399  
             {
 400  0
                 getLog().warn(
 401  
                                "WARRANTY: The number of documents analyzed by Linkcheck could differ with the real "
 402  
                                    + "number of documents!" );
 403  
             }
 404  
 
 405  0
             basedir = outputDirectory;
 406  0
             basedir.mkdirs();
 407  
         }
 408  
 
 409  
         try
 410  
         {
 411  0
             result = executeLinkCheck( basedir );
 412  
         }
 413  0
         catch ( LinkCheckException e )
 414  
         {
 415  0
             throw new MojoExecutionException( "LinkCheckException: " + e.getMessage(), e );
 416  0
         }
 417  0
     }
 418  
 
 419  
     // ----------------------------------------------------------------------
 420  
     // Protected methods
 421  
     // ----------------------------------------------------------------------
 422  
 
 423  
     /** {@inheritDoc} */
 424  
     protected String getOutputDirectory()
 425  
     {
 426  0
         return outputDirectory.getAbsolutePath();
 427  
     }
 428  
 
 429  
     /** {@inheritDoc} */
 430  
     protected MavenProject getProject()
 431  
     {
 432  0
         return project;
 433  
     }
 434  
 
 435  
     /** {@inheritDoc} */
 436  
     protected Renderer getSiteRenderer()
 437  
     {
 438  0
         return siteRenderer;
 439  
     }
 440  
 
 441  
     /** {@inheritDoc} */
 442  
     protected void executeReport( Locale locale )
 443  
         throws MavenReportException
 444  
     {
 445  0
         if ( result == null )
 446  
         {
 447  0
             getLog().debug( "Calling execute()" );
 448  
 
 449  
             try
 450  
             {
 451  0
                 this.execute();
 452  
             }
 453  0
             catch ( MojoExecutionException e )
 454  
             {
 455  0
                 throw new MavenReportException( "MojoExecutionException: " + e.getMessage(), e );
 456  0
             }
 457  
         }
 458  
 
 459  0
         if ( result != null )
 460  
         {
 461  0
             generateReport( locale, result );
 462  
             // free memory
 463  0
             result = null;
 464  
         }
 465  0
     }
 466  
 
 467  
     // ----------------------------------------------------------------------
 468  
     // Private methods
 469  
     // ----------------------------------------------------------------------
 470  
 
 471  
     /**
 472  
      * Execute the <code>Linkcheck</code> tool.
 473  
      *
 474  
      * @param basedir not null
 475  
      * @throws LinkCheckException if any
 476  
      */
 477  
     private LinkcheckModel executeLinkCheck( File basedir )
 478  
         throws LinkCheckException
 479  
     {
 480  
         // Wrap linkcheck
 481  0
         linkCheck.setOnline( !offline );
 482  0
         linkCheck.setBasedir( basedir );
 483  0
         linkCheck.setBaseURL( baseURL );
 484  0
         linkCheck.setReportOutput( linkcheckOutput );
 485  0
         linkCheck.setLinkCheckCache( linkcheckCache );
 486  0
         linkCheck.setExcludedLinks( excludedLinks );
 487  0
         linkCheck.setExcludedPages( getExcludedPages() );
 488  0
         linkCheck.setExcludedHttpStatusErrors( excludedHttpStatusErrors );
 489  0
         linkCheck.setExcludedHttpStatusWarnings( excludedHttpStatusWarnings );
 490  0
         linkCheck.setEncoding( ( StringUtils.isNotEmpty( encoding ) ? encoding : WriterFactory.UTF_8 ) );
 491  
 
 492  0
         HttpBean bean = new HttpBean();
 493  0
         bean.setMethod( httpMethod );
 494  0
         bean.setFollowRedirects( httpFollowRedirect );
 495  0
         bean.setTimeout( timeout );
 496  0
         if ( httpClientParameters != null )
 497  
         {
 498  0
             bean.setHttpClientParameters( httpClientParameters );
 499  
         }
 500  
 
 501  0
         Proxy proxy = settings.getActiveProxy();
 502  0
         if ( proxy != null )
 503  
         {
 504  0
             bean.setProxyHost( proxy.getHost() );
 505  0
             bean.setProxyPort( proxy.getPort() );
 506  0
             bean.setProxyUser( proxy.getUsername() );
 507  0
             bean.setProxyPassword( proxy.getPassword() );
 508  
         }
 509  0
         linkCheck.setHttp( bean );
 510  
 
 511  0
         return linkCheck.execute();
 512  
     }
 513  
 
 514  
     /**
 515  
      * @return the excludedPages defined by the user and also this report.
 516  
      */
 517  
     private String[] getExcludedPages()
 518  
     {
 519  0
         List pagesToExclude =
 520  
             ( excludedPages != null ? new ArrayList( Arrays.asList( excludedPages ) ) : new ArrayList() );
 521  
 
 522  
         // Exclude this report
 523  0
         pagesToExclude.add( getOutputName() + ".html" );
 524  
 
 525  0
         return (String[]) pagesToExclude.toArray( new String[0] );
 526  
     }
 527  
 
 528  
     /**
 529  
      * Invoke Maven for the <code>site</code> phase for a temporary Maven project using <code>tmpReportingOutputDirectory</code>
 530  
      * as <code>${project.reporting.outputDirectory}</code>. This is a workaround to be sure that all site files have been
 531  
      * correctly generated.
 532  
      * <br/>
 533  
      * <b>Note 1</b>: the Maven Home should be defined in the <code>maven.home</code> Java system property or defined in
 534  
      * <code>M2_HOME</code> system env variables.
 535  
      * <b>Note 2</be>: we can't use <code>siteOutputDirectory</code> param from site plugin because some plugins
 536  
      * <code>${project.reporting.outputDirectory}</code> in there conf.
 537  
      *
 538  
      * @param tmpReportingOutputDirectory not null
 539  
      * @throws IOException if any
 540  
      */
 541  
     private void invokeSite( File tmpReportingOutputDirectory )
 542  
         throws IOException
 543  
     {
 544  0
         String mavenHome = getMavenHome();
 545  0
         if ( StringUtils.isEmpty( mavenHome ) )
 546  
         {
 547  0
             if ( getLog().isErrorEnabled() )
 548  
             {
 549  0
                 String msg =
 550  
                     "Could NOT invoke Maven because no Maven Home is defined. You need to have set the M2_HOME "
 551  
                         + "system env variable or a 'maven.home' Java system properties.";
 552  0
                 getLog().error( msg );
 553  
             }
 554  0
             return;
 555  
         }
 556  
 
 557  
         // invoker site parameters
 558  0
         List goals = Collections.singletonList( "site" );
 559  0
         Properties properties = new Properties();
 560  0
         properties.put( "linkcheck.skip", "true" ); // to stop recursion
 561  
 
 562  0
         File invokerLog =
 563  
             FileUtils
 564  
                      .createTempFile( "invoker-site-plugin", ".txt", new File( project.getBuild().getDirectory() ) );
 565  
 
 566  
         // clone project and set a new reporting output dir
 567  
         MavenProject clone;
 568  
         try
 569  
         {
 570  0
             clone = (MavenProject) project.clone();
 571  
         }
 572  0
         catch ( CloneNotSupportedException e )
 573  
         {
 574  0
             IOException ioe = new IOException( "CloneNotSupportedException: " + e.getMessage() );
 575  0
             ioe.setStackTrace( e.getStackTrace() );
 576  0
             throw ioe;
 577  0
         }
 578  0
         clone.getOriginalModel().getReporting().setOutputDirectory( tmpReportingOutputDirectory.getAbsolutePath() );
 579  
 
 580  
         // create the original model as tmp pom file for the invoker
 581  0
         File tmpProjectFile = FileUtils.createTempFile( "pom", ".xml", project.getBasedir() );
 582  0
         Writer writer = null;
 583  
         try
 584  
         {
 585  0
             writer = WriterFactory.newXmlWriter( tmpProjectFile );
 586  0
             clone.writeOriginalModel( writer );
 587  
         }
 588  
         finally
 589  
         {
 590  0
             IOUtil.close( writer );
 591  0
         }
 592  
 
 593  
         // invoke it
 594  
         try
 595  
         {
 596  0
             invoke( tmpProjectFile, invokerLog, mavenHome, goals, properties );
 597  
         }
 598  
         finally
 599  
         {
 600  0
             if ( !getLog().isDebugEnabled() )
 601  
             {
 602  0
                 tmpProjectFile.delete();
 603  
             }
 604  
         }
 605  0
     }
 606  
 
 607  
     /**
 608  
      * @param projectFile not null, should be in the ${project.basedir}
 609  
      * @param invokerLog not null
 610  
      * @param mavenHome not null
 611  
      * @param goals the list of goals
 612  
      * @param properties the properties for the invoker
 613  
      */
 614  
     private void invoke( File projectFile, File invokerLog, String mavenHome, List goals, Properties properties )
 615  
     {
 616  0
         Invoker invoker = new DefaultInvoker();
 617  0
         invoker.setMavenHome( new File( mavenHome ) );
 618  0
         invoker.setLocalRepositoryDirectory( new File( localRepository.getBasedir() ) );
 619  
 
 620  0
         InvocationRequest request = new DefaultInvocationRequest();
 621  0
         request.setBaseDirectory( projectFile.getParentFile() );
 622  0
         request.setPomFile( projectFile );
 623  0
         request.setDebug( getLog().isDebugEnabled() );
 624  0
         request.setGoals( goals );
 625  0
         request.setProperties( properties );
 626  0
         File javaHome = getJavaHome();
 627  0
         if ( javaHome != null )
 628  
         {
 629  0
             request.setJavaHome( javaHome );
 630  
         }
 631  
 
 632  
         InvocationResult result;
 633  
         try
 634  
         {
 635  0
             if ( getLog().isDebugEnabled() )
 636  
             {
 637  0
                 getLog().debug( "Invoking Maven for the goals: " + goals + " with properties=" + properties );
 638  
             }
 639  0
             result = invoke( invoker, request, invokerLog, goals, properties, null );
 640  
         }
 641  0
         catch ( MavenInvocationException e )
 642  
         {
 643  0
             if ( getLog().isDebugEnabled() )
 644  
             {
 645  0
                 getLog().error( "MavenInvocationException: " + e.getMessage(), e );
 646  
             }
 647  0
             getLog().error( "Error when invoking Maven, consult the invoker log." );
 648  0
             return;
 649  0
         }
 650  
 
 651  0
         String invokerLogContent = null;
 652  0
         Reader reader = null;
 653  
         try
 654  
         {
 655  0
             reader = ReaderFactory.newReader( invokerLog, "UTF-8" );
 656  0
             invokerLogContent = IOUtil.toString( reader );
 657  
         }
 658  0
         catch ( IOException e )
 659  
         {
 660  0
             String msg = "IOException: " + e.getMessage();
 661  0
             if ( getLog().isDebugEnabled() )
 662  
             {
 663  0
                 getLog().error( msg, e );
 664  
             }
 665  
             else
 666  
             {
 667  0
                 getLog().error( msg );
 668  
             }
 669  
         }
 670  
         finally
 671  
         {
 672  0
             IOUtil.close( reader );
 673  0
         }
 674  
 
 675  0
         if ( invokerLogContent != null
 676  
             && invokerLogContent.indexOf( "Error occurred during initialization of VM" ) != -1 )
 677  
         {
 678  0
             getLog().info( "Error occurred during initialization of VM, try to use an empty MAVEN_OPTS." );
 679  
 
 680  0
             if ( getLog().isDebugEnabled() )
 681  
             {
 682  0
                 getLog().debug( "Reinvoking Maven for the goals: " + goals + " with an empty MAVEN_OPTS" );
 683  
             }
 684  
 
 685  
             try
 686  
             {
 687  0
                 result = invoke( invoker, request, invokerLog, goals, properties, "" );
 688  
             }
 689  0
             catch ( MavenInvocationException e )
 690  
             {
 691  0
                 if ( getLog().isDebugEnabled() )
 692  
                 {
 693  0
                     getLog().error( "MavenInvocationException: " + e.getMessage(), e );
 694  
                 }
 695  0
                 getLog().error( "Error when reinvoking Maven, consult the invoker log." );
 696  0
                 return;
 697  0
             }
 698  
         }
 699  
 
 700  0
         if ( result.getExitCode() != 0 )
 701  
         {
 702  0
             if ( getLog().isErrorEnabled() )
 703  
             {
 704  0
                 getLog().error(
 705  
                                 "Error when invoking Maven, consult the invoker log file: "
 706  
                                     + invokerLog.getAbsolutePath() );
 707  
             }
 708  
         }
 709  0
     }
 710  
 
 711  
     /**
 712  
      * @param invoker not null
 713  
      * @param request not null
 714  
      * @param invokerLog not null
 715  
      * @param goals the list of goals
 716  
      * @param properties the properties for the invoker
 717  
      * @param mavenOpts could be null
 718  
      * @return the invocation result
 719  
      * @throws MavenInvocationException if any
 720  
      */
 721  
     private InvocationResult invoke( Invoker invoker, InvocationRequest request, File invokerLog, List goals,
 722  
                                      Properties properties, String mavenOpts )
 723  
         throws MavenInvocationException
 724  
     {
 725  
         PrintStream ps;
 726  0
         OutputStream os = null;
 727  0
         if ( invokerLog != null )
 728  
         {
 729  0
             if ( getLog().isDebugEnabled() )
 730  
             {
 731  0
                 getLog().debug( "Using " + invokerLog.getAbsolutePath() + " to log the invoker" );
 732  
             }
 733  
 
 734  
             try
 735  
             {
 736  0
                 if ( !invokerLog.exists() )
 737  
                 {
 738  0
                     invokerLog.getParentFile().mkdirs();
 739  
                 }
 740  0
                 os = new FileOutputStream( invokerLog );
 741  0
                 ps = new PrintStream( os, true, "UTF-8" );
 742  
             }
 743  0
             catch ( FileNotFoundException e )
 744  
             {
 745  0
                 if ( getLog().isErrorEnabled() )
 746  
                 {
 747  0
                     getLog().error(
 748  
                                     "FileNotFoundException: " + e.getMessage()
 749  
                                         + ". Using System.out to log the invoker." );
 750  
                 }
 751  0
                 ps = System.out;
 752  
             }
 753  0
             catch ( UnsupportedEncodingException e )
 754  
             {
 755  0
                 if ( getLog().isErrorEnabled() )
 756  
                 {
 757  0
                     getLog().error(
 758  
                                     "UnsupportedEncodingException: " + e.getMessage()
 759  
                                         + ". Using System.out to log the invoker." );
 760  
                 }
 761  0
                 ps = System.out;
 762  0
             }
 763  
         }
 764  
         else
 765  
         {
 766  0
             getLog().debug( "Using System.out to log the invoker." );
 767  
 
 768  0
             ps = System.out;
 769  
         }
 770  
 
 771  0
         if ( mavenOpts != null )
 772  
         {
 773  0
             request.setMavenOpts( mavenOpts );
 774  
         }
 775  
 
 776  0
         InvocationOutputHandler outputHandler = new PrintStreamHandler( ps, false );
 777  0
         request.setOutputHandler( outputHandler );
 778  
 
 779  0
         outputHandler.consumeLine( "Invoking Maven for the goals: " + goals + " with properties=" + properties );
 780  0
         outputHandler.consumeLine( "" );
 781  0
         outputHandler.consumeLine( "M2_HOME=" + getMavenHome() );
 782  0
         outputHandler.consumeLine( "MAVEN_OPTS=" + getMavenOpts() );
 783  0
         outputHandler.consumeLine( "JAVA_HOME=" + getJavaHome() );
 784  0
         outputHandler.consumeLine( "JAVA_OPTS=" + getJavaOpts() );
 785  0
         outputHandler.consumeLine( "" );
 786  
 
 787  
         try
 788  
         {
 789  0
             return invoker.execute( request );
 790  
         }
 791  
         finally
 792  
         {
 793  0
             IOUtil.close( os );
 794  0
             ps = null;
 795  
         }
 796  
     }
 797  
 
 798  
     /**
 799  
      * @return the Maven home defined in the <code>maven.home</code> system property or defined
 800  
      * in <code>M2_HOME</code> system env variables or null if never setted.
 801  
      * @see #invoke(Invoker, InvocationRequest, File, List, Properties, String)
 802  
      */
 803  
     private String getMavenHome()
 804  
     {
 805  0
         String mavenHome = System.getProperty( "maven.home" );
 806  0
         if ( mavenHome == null )
 807  
         {
 808  
             try
 809  
             {
 810  0
                 mavenHome = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" );
 811  
             }
 812  0
             catch ( IOException e )
 813  
             {
 814  0
                 String msg = "IOException: " + e.getMessage();
 815  0
                 if ( getLog().isDebugEnabled() )
 816  
                 {
 817  0
                     getLog().error( msg, e );
 818  
                 }
 819  
                 else
 820  
                 {
 821  0
                     getLog().error( msg );
 822  
                 }
 823  0
             }
 824  
         }
 825  
 
 826  0
         File m2Home = new File( mavenHome );
 827  0
         if ( !m2Home.exists() )
 828  
         {
 829  0
             if ( getLog().isErrorEnabled() )
 830  
             {
 831  0
                 getLog().error(
 832  
                                 "Cannot find Maven application directory. Either specify \'maven.home\' "
 833  
                                     + "system property, or M2_HOME environment variable." );
 834  
             }
 835  
         }
 836  
 
 837  0
         return mavenHome;
 838  
     }
 839  
 
 840  
     /**
 841  
      * @return the <code>MAVEN_OPTS</code> env variable value or null if not setted.
 842  
      * @see #invoke(Invoker, InvocationRequest, File, List, Properties, String)
 843  
      */
 844  
     private String getMavenOpts()
 845  
     {
 846  0
         String mavenOpts = null;
 847  
         try
 848  
         {
 849  0
             mavenOpts = CommandLineUtils.getSystemEnvVars().getProperty( "MAVEN_OPTS" );
 850  
         }
 851  0
         catch ( IOException e )
 852  
         {
 853  0
             String msg = "IOException: " + e.getMessage();
 854  0
             if ( getLog().isDebugEnabled() )
 855  
             {
 856  0
                 getLog().error( msg, e );
 857  
             }
 858  
             else
 859  
             {
 860  0
                 getLog().error( msg );
 861  
             }
 862  0
         }
 863  
 
 864  0
         return mavenOpts;
 865  
     }
 866  
 
 867  
     /**
 868  
      * @return the <code>JAVA_HOME</code> from System.getProperty( "java.home" )
 869  
      * By default, <code>System.getProperty( "java.home" ) = JRE_HOME</code> and <code>JRE_HOME</code>
 870  
      * should be in the <code>JDK_HOME</code> or null if not setted.
 871  
      * @see #invoke(Invoker, InvocationRequest, File, List, Properties, String)
 872  
      */
 873  
     private File getJavaHome()
 874  
     {
 875  
         File javaHome;
 876  0
         if ( SystemUtils.IS_OS_MAC_OSX )
 877  
         {
 878  0
             javaHome = SystemUtils.getJavaHome();
 879  
         }
 880  
         else
 881  
         {
 882  0
             javaHome = new File( SystemUtils.getJavaHome(), ".." );
 883  
         }
 884  
 
 885  0
         if ( javaHome == null || !javaHome.exists() )
 886  
         {
 887  
             try
 888  
             {
 889  0
                 javaHome = new File( CommandLineUtils.getSystemEnvVars().getProperty( "JAVA_HOME" ) );
 890  
             }
 891  0
             catch ( IOException e )
 892  
             {
 893  0
                 String msg = "IOException: " + e.getMessage();
 894  0
                 if ( getLog().isDebugEnabled() )
 895  
                 {
 896  0
                     getLog().error( msg, e );
 897  
                 }
 898  
                 else
 899  
                 {
 900  0
                     getLog().error( msg );
 901  
                 }
 902  0
             }
 903  
         }
 904  
 
 905  0
         if ( javaHome == null || !javaHome.exists() )
 906  
         {
 907  0
             if ( getLog().isErrorEnabled() )
 908  
             {
 909  0
                 getLog().error(
 910  
                                 "Cannot find Java application directory. Either specify \'java.home\' "
 911  
                                     + "system property, or JAVA_HOME environment variable." );
 912  
             }
 913  
         }
 914  
 
 915  0
         return javaHome;
 916  
     }
 917  
 
 918  
     /**
 919  
      * @return the <code>JAVA_OPTS</code> env variable value or null if not setted.
 920  
      * @see #invoke(Invoker, InvocationRequest, File, List, Properties, String)
 921  
      */
 922  
     private String getJavaOpts()
 923  
     {
 924  0
         String javaOpts = null;
 925  
         try
 926  
         {
 927  0
             javaOpts = CommandLineUtils.getSystemEnvVars().getProperty( "JAVA_OPTS" );
 928  
         }
 929  0
         catch ( IOException e )
 930  
         {
 931  0
             String msg = "IOException: " + e.getMessage();
 932  0
             if ( getLog().isDebugEnabled() )
 933  
             {
 934  0
                 getLog().error( msg, e );
 935  
             }
 936  
             else
 937  
             {
 938  0
                 getLog().error( msg );
 939  
             }
 940  0
         }
 941  
 
 942  0
         return javaOpts;
 943  
     }
 944  
 
 945  
     // ----------------------------------------------------------------------
 946  
     // Linkcheck report
 947  
     // ----------------------------------------------------------------------
 948  
 
 949  
     private void generateReport( Locale locale, LinkcheckModel linkcheckModel )
 950  
     {
 951  0
         getSink().head();
 952  0
         getSink().title();
 953  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.title" ) );
 954  0
         getSink().title_();
 955  0
         getSink().head_();
 956  
 
 957  0
         getSink().body();
 958  
 
 959  0
         if ( linkcheckModel == null )
 960  
         {
 961  0
             getSink().section1();
 962  0
             getSink().sectionTitle1();
 963  0
             getSink().text( getName( locale ) );
 964  0
             getSink().sectionTitle1_();
 965  
 
 966  0
             getSink().paragraph();
 967  0
             getSink().rawText( i18n.getString( "linkcheck-report", locale, "report.linkcheck.empty" ) );
 968  0
             getSink().paragraph_();
 969  
 
 970  0
             getSink().section1_();
 971  
 
 972  0
             getSink().body_();
 973  0
             getSink().flush();
 974  0
             getSink().close();
 975  
 
 976  0
             return;
 977  
         }
 978  
 
 979  
         // Overview
 980  0
         getSink().section1();
 981  0
         getSink().sectionTitle1();
 982  0
         getSink().text( getName( locale ) );
 983  0
         getSink().sectionTitle1_();
 984  
 
 985  0
         getSink().paragraph();
 986  0
         getSink().rawText( i18n.getString( "linkcheck-report", locale, "report.linkcheck.overview" ) );
 987  0
         getSink().paragraph_();
 988  
 
 989  0
         getSink().section1_();
 990  
 
 991  
         // Statistics
 992  0
         generateSummarySection( locale, linkcheckModel );
 993  
 
 994  0
         if ( linkcheckModel.getFiles().size() > 0 )
 995  
         {
 996  
             // Details
 997  0
             generateDetailsSection( locale, linkcheckModel );
 998  
         }
 999  
 
 1000  0
         getSink().body_();
 1001  0
         getSink().flush();
 1002  0
         getSink().close();
 1003  
 
 1004  0
         closeReport();
 1005  0
     }
 1006  
 
 1007  
     private void generateSummarySection( Locale locale, LinkcheckModel linkcheckModel )
 1008  
     {
 1009  
         // Calculus
 1010  0
         List linkcheckFiles = linkcheckModel.getFiles();
 1011  
 
 1012  0
         int totalFiles = linkcheckFiles.size();
 1013  
 
 1014  0
         int totalLinks = 0;
 1015  0
         int totalValidLinks = 0;
 1016  0
         int totalErrorLinks = 0;
 1017  0
         int totalWarningLinks = 0;
 1018  0
         for ( Iterator it = linkcheckFiles.iterator(); it.hasNext(); )
 1019  
         {
 1020  0
             LinkcheckFile linkcheckFile = (LinkcheckFile) it.next();
 1021  
 
 1022  0
             totalLinks += linkcheckFile.getNumberOfLinks();
 1023  0
             totalValidLinks += linkcheckFile.getNumberOfLinks( LinkcheckFileResult.VALID_LEVEL );
 1024  0
             totalErrorLinks += linkcheckFile.getNumberOfLinks( LinkcheckFileResult.ERROR_LEVEL );
 1025  0
             totalWarningLinks += linkcheckFile.getNumberOfLinks( LinkcheckFileResult.WARNING_LEVEL );
 1026  0
         }
 1027  
 
 1028  0
         getSink().section1();
 1029  0
         getSink().sectionTitle1();
 1030  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary" ) );
 1031  0
         getSink().sectionTitle1_();
 1032  
 
 1033  
         // Summary of the analysis parameters
 1034  0
         getSink().paragraph();
 1035  0
         getSink().rawText( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.overview1" ) );
 1036  0
         getSink().paragraph_();
 1037  
 
 1038  0
         getSink().table();
 1039  
 
 1040  0
         getSink().tableRow();
 1041  0
         getSink().tableHeaderCell();
 1042  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.parameter" ) );
 1043  0
         getSink().tableHeaderCell_();
 1044  0
         getSink().tableHeaderCell();
 1045  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.value" ) );
 1046  0
         getSink().tableHeaderCell_();
 1047  0
         getSink().tableRow_();
 1048  
 
 1049  0
         getSink().tableRow();
 1050  0
         getSink().tableCell();
 1051  0
         getSink().rawText(
 1052  
                            i18n.getString( "linkcheck-report", locale,
 1053  
                                            "report.linkcheck.summary.table.httpFollowRedirect" ) );
 1054  0
         getSink().tableCell_();
 1055  0
         getSink().tableCell();
 1056  0
         getSink().text( String.valueOf( httpFollowRedirect ) );
 1057  0
         getSink().tableCell_();
 1058  0
         getSink().tableRow_();
 1059  
 
 1060  0
         getSink().tableRow();
 1061  0
         getSink().tableCell();
 1062  0
         getSink()
 1063  
                  .rawText(
 1064  
                            i18n
 1065  
                                .getString( "linkcheck-report", locale, "report.linkcheck.summary.table.httpMethod" ) );
 1066  0
         getSink().tableCell_();
 1067  0
         getSink().tableCell();
 1068  0
         if ( StringUtils.isEmpty( httpMethod ) )
 1069  
         {
 1070  0
             getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.none" ) );
 1071  
         }
 1072  
         else
 1073  
         {
 1074  0
             getSink().text( httpMethod );
 1075  
         }
 1076  0
         getSink().tableCell_();
 1077  0
         getSink().tableRow_();
 1078  
 
 1079  0
         getSink().tableRow();
 1080  0
         getSink().tableCell();
 1081  0
         getSink().rawText(
 1082  
                            i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.offline" ) );
 1083  0
         getSink().tableCell_();
 1084  0
         getSink().tableCell();
 1085  0
         getSink().text( String.valueOf( offline ) );
 1086  0
         getSink().tableCell_();
 1087  0
         getSink().tableRow_();
 1088  
 
 1089  0
         getSink().tableRow();
 1090  0
         getSink().tableCell();
 1091  0
         getSink().rawText(
 1092  
                            i18n.getString( "linkcheck-report", locale,
 1093  
                                            "report.linkcheck.summary.table.excludedPages" ) );
 1094  0
         getSink().tableCell_();
 1095  0
         getSink().tableCell();
 1096  0
         if ( getExcludedPages() == null || getExcludedPages().length == 0 )
 1097  
         {
 1098  0
             getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.none" ) );
 1099  
         }
 1100  
         else
 1101  
         {
 1102  0
             getSink().text( StringUtils.join( getExcludedPages(), "," ) );
 1103  
         }
 1104  0
         getSink().tableCell_();
 1105  0
         getSink().tableRow_();
 1106  
 
 1107  0
         getSink().tableRow();
 1108  0
         getSink().tableCell();
 1109  0
         getSink().rawText(
 1110  
                            i18n.getString( "linkcheck-report", locale,
 1111  
                                            "report.linkcheck.summary.table.excludedLinks" ) );
 1112  0
         getSink().tableCell_();
 1113  0
         getSink().tableCell();
 1114  0
         if ( excludedLinks == null || excludedLinks.length == 0 )
 1115  
         {
 1116  0
             getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.none" ) );
 1117  
         }
 1118  
         else
 1119  
         {
 1120  0
             getSink().text( StringUtils.join( excludedLinks, "," ) );
 1121  
         }
 1122  0
         getSink().tableCell_();
 1123  0
         getSink().tableRow_();
 1124  
 
 1125  0
         getSink().tableRow();
 1126  0
         getSink().tableCell();
 1127  0
         getSink().rawText(
 1128  
                            i18n.getString( "linkcheck-report", locale,
 1129  
                                            "report.linkcheck.summary.table.excludedHttpStatusErrors" ) );
 1130  0
         getSink().tableCell_();
 1131  0
         getSink().tableCell();
 1132  0
         if ( excludedHttpStatusErrors == null || excludedHttpStatusErrors.length == 0 )
 1133  
         {
 1134  0
             getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.none" ) );
 1135  
         }
 1136  
         else
 1137  
         {
 1138  0
             getSink().text( toString( excludedHttpStatusErrors ) );
 1139  
         }
 1140  0
         getSink().tableCell_();
 1141  0
         getSink().tableRow_();
 1142  
 
 1143  0
         getSink().tableRow();
 1144  0
         getSink().tableCell();
 1145  0
         getSink().rawText(
 1146  
                            i18n.getString( "linkcheck-report", locale,
 1147  
                                            "report.linkcheck.summary.table.excludedHttpStatusWarnings" ) );
 1148  0
         getSink().tableCell_();
 1149  0
         getSink().tableCell();
 1150  0
         if ( excludedHttpStatusWarnings == null || excludedHttpStatusWarnings.length == 0 )
 1151  
         {
 1152  0
             getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.table.none" ) );
 1153  
         }
 1154  
         else
 1155  
         {
 1156  0
             getSink().text( toString( excludedHttpStatusWarnings ) );
 1157  
         }
 1158  0
         getSink().tableCell_();
 1159  0
         getSink().tableRow_();
 1160  
 
 1161  0
         getSink().table_();
 1162  
 
 1163  
         // Summary of the checked files
 1164  0
         getSink().paragraph();
 1165  0
         getSink().rawText( i18n.getString( "linkcheck-report", locale, "report.linkcheck.summary.overview2" ) );
 1166  0
         getSink().paragraph_();
 1167  
 
 1168  0
         getSink().table();
 1169  
 
 1170  
         // Header
 1171  0
         generateTableHeader( locale, false );
 1172  
 
 1173  
         // Content
 1174  0
         getSink().tableRow();
 1175  
 
 1176  0
         getSink().tableCell();
 1177  0
         getSink().bold();
 1178  0
         getSink().text( totalFiles + "" );
 1179  0
         getSink().bold_();
 1180  0
         getSink().tableCell_();
 1181  0
         getSink().tableCell();
 1182  0
         getSink().bold();
 1183  0
         getSink().text( totalLinks + "" );
 1184  0
         getSink().bold_();
 1185  0
         getSink().tableCell_();
 1186  0
         getSink().tableCell();
 1187  0
         getSink().bold();
 1188  0
         getSink().text( String.valueOf( totalValidLinks ) );
 1189  0
         getSink().bold_();
 1190  0
         getSink().tableCell_();
 1191  0
         getSink().tableCell();
 1192  0
         getSink().bold();
 1193  0
         getSink().text( String.valueOf( totalWarningLinks ) );
 1194  0
         getSink().bold_();
 1195  0
         getSink().tableCell_();
 1196  0
         getSink().tableCell();
 1197  0
         getSink().bold();
 1198  0
         getSink().text( String.valueOf( totalErrorLinks ) );
 1199  0
         getSink().bold_();
 1200  0
         getSink().tableCell_();
 1201  
 
 1202  0
         getSink().tableRow_();
 1203  
 
 1204  0
         getSink().table_();
 1205  
 
 1206  0
         getSink().section1_();
 1207  0
     }
 1208  
 
 1209  
     private void generateDetailsSection( Locale locale, LinkcheckModel linkcheckModel )
 1210  
     {
 1211  0
         getSink().section1();
 1212  0
         getSink().sectionTitle1();
 1213  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.detail" ) );
 1214  0
         getSink().sectionTitle1_();
 1215  
 
 1216  0
         getSink().paragraph();
 1217  0
         getSink().rawText( i18n.getString( "linkcheck-report", locale, "report.linkcheck.detail.overview" ) );
 1218  0
         getSink().paragraph_();
 1219  
 
 1220  0
         getSink().table();
 1221  
 
 1222  
         // Header
 1223  0
         generateTableHeader( locale, true );
 1224  
 
 1225  
         // Content
 1226  0
         List linkcheckFiles = linkcheckModel.getFiles();
 1227  0
         for ( Iterator it = linkcheckFiles.iterator(); it.hasNext(); )
 1228  
         {
 1229  0
             LinkcheckFile linkcheckFile = (LinkcheckFile) it.next();
 1230  
 
 1231  0
             getSink().tableRow();
 1232  
 
 1233  0
             getSink().tableCell();
 1234  0
             if ( linkcheckFile.getUnsuccessful() == 0 )
 1235  
             {
 1236  0
                 iconValid( locale );
 1237  
             }
 1238  
             else
 1239  
             {
 1240  0
                 iconError( locale );
 1241  
             }
 1242  0
             getSink().tableCell_();
 1243  
 
 1244  
             // tableCell( createLinkPatternedText( linkcheckFile.getRelativePath(), "./"
 1245  
             // + linkcheckFile.getRelativePath() ) );
 1246  0
             getSink().tableCell();
 1247  0
             getSink().link( linkcheckFile.getRelativePath() );
 1248  0
             getSink().text( linkcheckFile.getRelativePath() );
 1249  0
             getSink().link_();
 1250  0
             getSink().tableCell_();
 1251  0
             getSink().tableCell();
 1252  0
             getSink().text( String.valueOf( linkcheckFile.getNumberOfLinks() ) );
 1253  0
             getSink().tableCell_();
 1254  0
             getSink().tableCell();
 1255  0
             getSink().text( String.valueOf( linkcheckFile.getNumberOfLinks( LinkcheckFileResult.VALID_LEVEL ) ) );
 1256  0
             getSink().tableCell_();
 1257  0
             getSink().tableCell();
 1258  0
             getSink().text( String.valueOf( linkcheckFile.getNumberOfLinks( LinkcheckFileResult.WARNING_LEVEL ) ) );
 1259  0
             getSink().tableCell_();
 1260  0
             getSink().tableCell();
 1261  0
             getSink().text( String.valueOf( linkcheckFile.getNumberOfLinks( LinkcheckFileResult.ERROR_LEVEL ) ) );
 1262  0
             getSink().tableCell_();
 1263  
 
 1264  0
             getSink().tableRow_();
 1265  
 
 1266  
             // Detail error
 1267  0
             if ( linkcheckFile.getUnsuccessful() != 0 )
 1268  
             {
 1269  0
                 getSink().tableRow();
 1270  
 
 1271  0
                 getSink().tableCell();
 1272  0
                 getSink().text( "" );
 1273  0
                 getSink().tableCell_();
 1274  
 
 1275  
                 // TODO it is due to DOXIA-78
 1276  0
                 getSink().rawText( "<td colspan=\"5\">" );
 1277  
 
 1278  0
                 getSink().table();
 1279  
 
 1280  0
                 for ( Iterator it2 = linkcheckFile.getResults().iterator(); it2.hasNext(); )
 1281  
                 {
 1282  0
                     LinkcheckFileResult linkcheckFileResult = (LinkcheckFileResult) it2.next();
 1283  
 
 1284  0
                     if ( linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.VALID_LEVEL )
 1285  
                     {
 1286  0
                         continue;
 1287  
                     }
 1288  
 
 1289  0
                     getSink().tableRow();
 1290  
 
 1291  0
                     getSink().tableCell();
 1292  0
                     if ( linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.WARNING_LEVEL )
 1293  
                     {
 1294  0
                         iconWarning( locale );
 1295  
                     }
 1296  0
                     else if ( linkcheckFileResult.getStatusLevel() == LinkcheckFileResult.ERROR_LEVEL )
 1297  
                     {
 1298  0
                         iconError( locale );
 1299  
                     }
 1300  0
                     getSink().tableCell_();
 1301  
 
 1302  0
                     getSink().tableCell();
 1303  0
                     getSink().italic();
 1304  0
                     if ( linkcheckFileResult.getTarget().startsWith( "#" ) )
 1305  
                     {
 1306  0
                         getSink().link( linkcheckFile.getRelativePath() + linkcheckFileResult.getTarget() );
 1307  
                     }
 1308  0
                     else if ( linkcheckFileResult.getTarget().startsWith( "." ) )
 1309  
                     {
 1310  
                         // We need to calculate a correct absolute path here, because target is a relative path
 1311  0
                         String absolutePath = FilenameUtils.getFullPath( linkcheckFile.getRelativePath() )
 1312  
                             + linkcheckFileResult.getTarget();
 1313  0
                         String normalizedPath = FilenameUtils.normalize( absolutePath );
 1314  0
                         if( normalizedPath == null )
 1315  
                         {
 1316  0
                             normalizedPath = absolutePath;
 1317  
                         }
 1318  0
                         getSink().link( normalizedPath );
 1319  0
                     }
 1320  
                     else
 1321  
                     {
 1322  0
                         getSink().link( linkcheckFileResult.getTarget() );
 1323  
                     }
 1324  
                     // Show the link as it was written to make it easy for
 1325  
                     // the author to find it in the source document
 1326  0
                     getSink().text( linkcheckFileResult.getTarget() );
 1327  0
                     getSink().link_();
 1328  0
                     getSink().text( ": " );
 1329  0
                     getSink().text( linkcheckFileResult.getErrorMessage() );
 1330  0
                     getSink().italic_();
 1331  0
                     getSink().tableCell_();
 1332  
 
 1333  0
                     getSink().tableRow_();
 1334  0
                 }
 1335  
 
 1336  0
                 getSink().table_();
 1337  
 
 1338  0
                 getSink().tableCell_();
 1339  
 
 1340  0
                 getSink().tableRow_();
 1341  
             }
 1342  0
         }
 1343  
 
 1344  0
         getSink().table_();
 1345  
 
 1346  0
         getSink().section1_();
 1347  0
     }
 1348  
 
 1349  
     private void generateTableHeader( Locale locale, boolean detail )
 1350  
     {
 1351  0
         getSink().tableRow();
 1352  0
         if ( detail )
 1353  
         {
 1354  0
             getSink().rawText( "<th rowspan=\"2\">" );
 1355  0
             getSink().text( "" );
 1356  0
             getSink().tableHeaderCell_();
 1357  
         }
 1358  0
         getSink().rawText( "<th rowspan=\"2\">" );
 1359  0
         getSink().text(
 1360  
                         detail ? i18n.getString( "linkcheck-report", locale,
 1361  
                                                  "report.linkcheck.detail.table.documents" )
 1362  
                                         : i18n.getString( "linkcheck-report", locale,
 1363  
                                                           "report.linkcheck.summary.table.documents" ) );
 1364  0
         getSink().tableHeaderCell_();
 1365  
         // TODO it is due to DOXIA-78
 1366  0
         getSink().rawText( "<th colspan=\"4\" align=\"center\">" );
 1367  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.table.links" ) );
 1368  0
         getSink().tableHeaderCell_();
 1369  0
         getSink().tableRow_();
 1370  
 
 1371  0
         getSink().tableRow();
 1372  0
         getSink().tableHeaderCell();
 1373  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.table.totalLinks" ) );
 1374  0
         getSink().tableHeaderCell_();
 1375  0
         getSink().tableHeaderCell();
 1376  0
         iconValid( locale );
 1377  0
         getSink().tableHeaderCell_();
 1378  0
         getSink().tableHeaderCell();
 1379  0
         iconWarning( locale );
 1380  0
         getSink().tableHeaderCell_();
 1381  0
         getSink().tableHeaderCell();
 1382  0
         iconError( locale );
 1383  0
         getSink().tableHeaderCell_();
 1384  0
         getSink().tableRow_();
 1385  0
     }
 1386  
 
 1387  
     private void iconError( Locale locale )
 1388  
     {
 1389  0
         getSink().figure();
 1390  0
         getSink().figureCaption();
 1391  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.icon.error" ) );
 1392  0
         getSink().figureCaption_();
 1393  
         // should be defined in skins
 1394  0
         getSink().figureGraphics( "images/icon_error_sml.gif" );
 1395  0
         getSink().figure_();
 1396  0
     }
 1397  
 
 1398  
     private void iconValid( Locale locale )
 1399  
     {
 1400  0
         getSink().figure();
 1401  0
         getSink().figureCaption();
 1402  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.icon.valid" ) );
 1403  0
         getSink().figureCaption_();
 1404  
         // should be defined in skins
 1405  0
         getSink().figureGraphics( "images/icon_success_sml.gif" );
 1406  0
         getSink().figure_();
 1407  0
     }
 1408  
 
 1409  
     private void iconWarning( Locale locale )
 1410  
     {
 1411  0
         getSink().figure();
 1412  0
         getSink().figureCaption();
 1413  0
         getSink().text( i18n.getString( "linkcheck-report", locale, "report.linkcheck.icon.warning" ) );
 1414  0
         getSink().figureCaption_();
 1415  
         // should be defined in skins
 1416  0
         getSink().figureGraphics( "images/icon_warning_sml.gif" );
 1417  0
         getSink().figure_();
 1418  0
     }
 1419  
 
 1420  
     // ----------------------------------------------------------------------
 1421  
     // static methods
 1422  
     // ----------------------------------------------------------------------
 1423  
 
 1424  
     /**
 1425  
      * Similar to {@link Arrays#toString(int[])} in 1.5.
 1426  
      *
 1427  
      * @param a not null
 1428  
      * @return the array comma separated.
 1429  
      */
 1430  
     private static String toString( int[] a )
 1431  
     {
 1432  0
         if ( a == null || a.length == 0 )
 1433  
         {
 1434  0
             return "";
 1435  
         }
 1436  
 
 1437  0
         StringBuffer buf = new StringBuffer();
 1438  0
         buf.append( a[0] );
 1439  
 
 1440  0
         for ( int i = 1; i < a.length; i++ )
 1441  
         {
 1442  0
             buf.append( ", " );
 1443  0
             buf.append( a[i] );
 1444  
         }
 1445  
 
 1446  0
         return buf.toString();
 1447  
     }
 1448  
 }