Coverage Report - org.owasp.dependencycheck.maven.BaseDependencyCheckMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseDependencyCheckMojo
0%
0/350
0%
0/174
4.667
 
 1  
 /*
 2  
  * This file is part of dependency-check-maven.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2014 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.maven;
 19  
 
 20  
 import java.io.BufferedOutputStream;
 21  
 import java.io.File;
 22  
 import java.io.FileInputStream;
 23  
 import java.io.FileNotFoundException;
 24  
 import java.io.FileOutputStream;
 25  
 import java.io.IOException;
 26  
 import java.io.InputStream;
 27  
 import java.io.ObjectOutputStream;
 28  
 import java.util.List;
 29  
 import java.util.Locale;
 30  
 import org.eclipse.aether.artifact.Artifact;
 31  
 import org.apache.maven.doxia.sink.Sink;
 32  
 import org.apache.maven.plugin.AbstractMojo;
 33  
 import org.apache.maven.plugin.MojoExecutionException;
 34  
 import org.apache.maven.plugin.MojoFailureException;
 35  
 import org.apache.maven.plugins.annotations.Component;
 36  
 import org.apache.maven.plugins.annotations.Parameter;
 37  
 import org.apache.maven.project.MavenProject;
 38  
 import org.apache.maven.reporting.MavenReport;
 39  
 import org.apache.maven.reporting.MavenReportException;
 40  
 import org.apache.maven.settings.Proxy;
 41  
 import org.apache.maven.settings.Server;
 42  
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
 43  
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
 44  
 import org.apache.maven.shared.dependency.graph.DependencyNode;
 45  
 import org.eclipse.aether.RepositorySystem;
 46  
 import org.eclipse.aether.RepositorySystemSession;
 47  
 import org.eclipse.aether.artifact.DefaultArtifact;
 48  
 import org.eclipse.aether.repository.RemoteRepository;
 49  
 import org.eclipse.aether.resolution.ArtifactRequest;
 50  
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 51  
 import org.eclipse.aether.resolution.ArtifactResult;
 52  
 import org.owasp.dependencycheck.data.nexus.MavenArtifact;
 53  
 import org.owasp.dependencycheck.data.nvdcve.CveDB;
 54  
 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
 55  
 import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
 56  
 import org.owasp.dependencycheck.dependency.Confidence;
 57  
 import org.owasp.dependencycheck.dependency.Dependency;
 58  
 import org.owasp.dependencycheck.dependency.Identifier;
 59  
 import org.owasp.dependencycheck.dependency.Vulnerability;
 60  
 import org.owasp.dependencycheck.exception.ExceptionCollection;
 61  
 import org.owasp.dependencycheck.exception.ReportException;
 62  
 import org.owasp.dependencycheck.reporting.ReportGenerator;
 63  
 import org.owasp.dependencycheck.utils.ExpectedOjectInputStream;
 64  
 import org.owasp.dependencycheck.utils.Settings;
 65  
 import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
 66  
 import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
 67  
 import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
 68  
 
 69  
 /**
 70  
  *
 71  
  * @author Jeremy Long
 72  
  */
 73  0
 public abstract class BaseDependencyCheckMojo extends AbstractMojo implements MavenReport {
 74  
 
 75  
     //<editor-fold defaultstate="collapsed" desc="Private fields">
 76  
     /**
 77  
      * The properties file location.
 78  
      */
 79  
     private static final String PROPERTIES_FILE = "mojo.properties";
 80  
     /**
 81  
      * System specific new line character.
 82  
      */
 83  0
     private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern();
 84  
     //</editor-fold>
 85  
     // <editor-fold defaultstate="collapsed" desc="Maven bound parameters and components">
 86  
     /**
 87  
      * Sets whether or not the external report format should be used.
 88  
      */
 89  
     @Parameter(property = "metaFileName", defaultValue = "dependency-check.ser", required = true)
 90  
     private String dataFileName;
 91  
     /**
 92  
      * Sets whether or not the external report format should be used.
 93  
      */
 94  
     @Parameter(property = "failOnError", defaultValue = "true", required = true)
 95  
     private boolean failOnError;
 96  
 
 97  
     /**
 98  
      * Returns if the mojo should fail the build if an exception occurs.
 99  
      *
 100  
      * @return whether or not the mojo should fail the build
 101  
      */
 102  
     protected boolean isFailOnError() {
 103  0
         return failOnError;
 104  
     }
 105  
 
 106  
     /**
 107  
      * The Maven Project Object.
 108  
      */
 109  
     @Parameter(property = "project", required = true, readonly = true)
 110  
     private MavenProject project;
 111  
     /**
 112  
      * List of Maven project of the current build
 113  
      */
 114  
     @Parameter(readonly = true, required = true, property = "reactorProjects")
 115  
     private List<MavenProject> reactorProjects;
 116  
     /**
 117  
      * The entry point to Aether, i.e. the component doing all the work.
 118  
      */
 119  
     @Component
 120  
     private RepositorySystem repoSystem;
 121  
 
 122  
     /**
 123  
      * The current repository/network configuration of Maven.
 124  
      */
 125  
     @Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
 126  
     private RepositorySystemSession repoSession;
 127  
 
 128  
     /**
 129  
      * The project's remote repositories to use for the resolution of plug-ins
 130  
      * and their dependencies.
 131  
      */
 132  
     @Parameter(defaultValue = "${project.remotePluginRepositories}", readonly = true)
 133  
     private List<RemoteRepository> remoteRepos;
 134  
 
 135  
     /**
 136  
      * Component within Maven to build the dependency graph.
 137  
      */
 138  
     @Component
 139  
     private DependencyGraphBuilder dependencyGraphBuilder;
 140  
 
 141  
     /**
 142  
      * The output directory. This generally maps to "target".
 143  
      */
 144  
     @Parameter(defaultValue = "${project.build.directory}", required = true)
 145  
     private File outputDirectory;
 146  
     /**
 147  
      * Specifies the destination directory for the generated Dependency-Check
 148  
      * report. This generally maps to "target/site".
 149  
      */
 150  
     @Parameter(property = "project.reporting.outputDirectory", required = true)
 151  
     private File reportOutputDirectory;
 152  
     /**
 153  
      * Specifies if the build should be failed if a CVSS score above a specified
 154  
      * level is identified. The default is 11 which means since the CVSS scores
 155  
      * are 0-10, by default the build will never fail.
 156  
      */
 157  0
     @SuppressWarnings("CanBeFinal")
 158  
     @Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true)
 159  
     private float failBuildOnCVSS = 11;
 160  
     /**
 161  
      * Sets whether auto-updating of the NVD CVE/CPE data is enabled. It is not
 162  
      * recommended that this be turned to false. Default is true.
 163  
      */
 164  
     @Parameter(property = "autoUpdate")
 165  
     private Boolean autoUpdate;
 166  
     /**
 167  
      * Sets whether Experimental analyzers are enabled. Default is false.
 168  
      */
 169  
     @Parameter(property = "enableExperimental")
 170  
     private Boolean enableExperimental;
 171  
     /**
 172  
      * Generate aggregate reports in multi-module projects.
 173  
      *
 174  
      * @deprecated use the aggregate goal instead
 175  
      */
 176  
     @Parameter(property = "aggregate")
 177  
     @Deprecated
 178  
     private Boolean aggregate;
 179  
     /**
 180  
      * The report format to be generated (HTML, XML, VULN, ALL). This
 181  
      * configuration option has no affect if using this within the Site plug-in
 182  
      * unless the externalReport is set to true. Default is HTML.
 183  
      */
 184  0
     @SuppressWarnings("CanBeFinal")
 185  
     @Parameter(property = "format", defaultValue = "HTML", required = true)
 186  
     private String format = "HTML";
 187  
     /**
 188  
      * The Maven settings.
 189  
      */
 190  
     @Parameter(property = "mavenSettings", defaultValue = "${settings}", required = false)
 191  
     private org.apache.maven.settings.Settings mavenSettings;
 192  
 
 193  
     /**
 194  
      * The maven settings proxy id.
 195  
      */
 196  
     @Parameter(property = "mavenSettingsProxyId", required = false)
 197  
     private String mavenSettingsProxyId;
 198  
 
 199  
     /**
 200  
      * The Connection Timeout.
 201  
      */
 202  
     @Parameter(property = "connectionTimeout", defaultValue = "", required = false)
 203  
     private String connectionTimeout;
 204  
     /**
 205  
      * The path to the suppression file.
 206  
      */
 207  
     @Parameter(property = "suppressionFile", defaultValue = "", required = false)
 208  
     private String suppressionFile;
 209  
 
 210  
     /**
 211  
      * The path to the hints file.
 212  
      */
 213  
     @Parameter(property = "hintsFile", defaultValue = "", required = false)
 214  
     private String hintsFile;
 215  
 
 216  
     /**
 217  
      * Flag indicating whether or not to show a summary in the output.
 218  
      */
 219  0
     @SuppressWarnings("CanBeFinal")
 220  
     @Parameter(property = "showSummary", defaultValue = "true", required = false)
 221  
     private boolean showSummary = true;
 222  
 
 223  
     /**
 224  
      * Whether or not the Jar Analyzer is enabled.
 225  
      */
 226  
     @Parameter(property = "jarAnalyzerEnabled", required = false)
 227  
     private Boolean jarAnalyzerEnabled;
 228  
 
 229  
     /**
 230  
      * Whether or not the Archive Analyzer is enabled.
 231  
      */
 232  
     @Parameter(property = "archiveAnalyzerEnabled", required = false)
 233  
     private Boolean archiveAnalyzerEnabled;
 234  
 
 235  
     /**
 236  
      * Sets whether the Python Distribution Analyzer will be used.
 237  
      */
 238  
     @Parameter(property = "pyDistributionAnalyzerEnabled", required = false)
 239  
     private Boolean pyDistributionAnalyzerEnabled;
 240  
     /**
 241  
      * Sets whether the Python Package Analyzer will be used.
 242  
      */
 243  
     @Parameter(property = "pyPackageAnalyzerEnabled", required = false)
 244  
     private Boolean pyPackageAnalyzerEnabled;
 245  
     /**
 246  
      * Sets whether the Ruby Gemspec Analyzer will be used.
 247  
      */
 248  
     @Parameter(property = "rubygemsAnalyzerEnabled", required = false)
 249  
     private Boolean rubygemsAnalyzerEnabled;
 250  
     /**
 251  
      * Sets whether or not the openssl Analyzer should be used.
 252  
      */
 253  
     @Parameter(property = "opensslAnalyzerEnabled", required = false)
 254  
     private Boolean opensslAnalyzerEnabled;
 255  
     /**
 256  
      * Sets whether or not the CMake Analyzer should be used.
 257  
      */
 258  
     @Parameter(property = "cmakeAnalyzerEnabled", required = false)
 259  
     private Boolean cmakeAnalyzerEnabled;
 260  
     /**
 261  
      * Sets whether or not the autoconf Analyzer should be used.
 262  
      */
 263  
     @Parameter(property = "autoconfAnalyzerEnabled", required = false)
 264  
     private Boolean autoconfAnalyzerEnabled;
 265  
     /**
 266  
      * Sets whether or not the PHP Composer Lock File Analyzer should be used.
 267  
      */
 268  
     @Parameter(property = "composerAnalyzerEnabled", required = false)
 269  
     private Boolean composerAnalyzerEnabled;
 270  
     /**
 271  
      * Sets whether or not the Node.js Analyzer should be used.
 272  
      */
 273  
     @Parameter(property = "nodeAnalyzerEnabled", required = false)
 274  
     private Boolean nodeAnalyzerEnabled;
 275  
 
 276  
     /**
 277  
      * Whether or not the .NET Assembly Analyzer is enabled.
 278  
      */
 279  
     @Parameter(property = "assemblyAnalyzerEnabled", required = false)
 280  
     private Boolean assemblyAnalyzerEnabled;
 281  
 
 282  
     /**
 283  
      * Whether or not the .NET Nuspec Analyzer is enabled.
 284  
      */
 285  
     @Parameter(property = "nuspecAnalyzerEnabled", required = false)
 286  
     private Boolean nuspecAnalyzerEnabled;
 287  
 
 288  
     /**
 289  
      * Whether or not the Central Analyzer is enabled.
 290  
      */
 291  
     @Parameter(property = "centralAnalyzerEnabled", required = false)
 292  
     private Boolean centralAnalyzerEnabled;
 293  
 
 294  
     /**
 295  
      * Whether or not the Nexus Analyzer is enabled.
 296  
      */
 297  
     @Parameter(property = "nexusAnalyzerEnabled", required = false)
 298  
     private Boolean nexusAnalyzerEnabled;
 299  
 
 300  
     /**
 301  
      * The URL of a Nexus server's REST API end point
 302  
      * (http://domain/nexus/service/local).
 303  
      */
 304  
     @Parameter(property = "nexusUrl", required = false)
 305  
     private String nexusUrl;
 306  
     /**
 307  
      * Whether or not the configured proxy is used to connect to Nexus.
 308  
      */
 309  
     @Parameter(property = "nexusUsesProxy", required = false)
 310  
     private Boolean nexusUsesProxy;
 311  
     /**
 312  
      * The database connection string.
 313  
      */
 314  
     @Parameter(property = "connectionString", defaultValue = "", required = false)
 315  
     private String connectionString;
 316  
 
 317  
     /**
 318  
      * Returns the connection string.
 319  
      *
 320  
      * @return the connection string
 321  
      */
 322  
     protected String getConnectionString() {
 323  0
         return connectionString;
 324  
     }
 325  
     /**
 326  
      * The database driver name. An example would be org.h2.Driver.
 327  
      */
 328  
     @Parameter(property = "databaseDriverName", defaultValue = "", required = false)
 329  
     private String databaseDriverName;
 330  
     /**
 331  
      * The path to the database driver if it is not on the class path.
 332  
      */
 333  
     @Parameter(property = "databaseDriverPath", defaultValue = "", required = false)
 334  
     private String databaseDriverPath;
 335  
     /**
 336  
      * The server id in the settings.xml; used to retrieve encrypted passwords
 337  
      * from the settings.xml.
 338  
      */
 339  
     @Parameter(property = "serverId", defaultValue = "", required = false)
 340  
     private String serverId;
 341  
     /**
 342  
      * A reference to the settings.xml settings.
 343  
      */
 344  
     @Parameter(defaultValue = "${settings}", readonly = true, required = true)
 345  
     private org.apache.maven.settings.Settings settingsXml;
 346  
     /**
 347  
      * The security dispatcher that can decrypt passwords in the settings.xml.
 348  
      */
 349  
     @Component(role = SecDispatcher.class, hint = "default")
 350  
     private SecDispatcher securityDispatcher;
 351  
     /**
 352  
      * The database user name.
 353  
      */
 354  
     @Parameter(property = "databaseUser", defaultValue = "", required = false)
 355  
     private String databaseUser;
 356  
     /**
 357  
      * The password to use when connecting to the database.
 358  
      */
 359  
     @Parameter(property = "databasePassword", defaultValue = "", required = false)
 360  
     private String databasePassword;
 361  
     /**
 362  
      * A comma-separated list of file extensions to add to analysis next to jar,
 363  
      * zip, ....
 364  
      */
 365  
     @Parameter(property = "zipExtensions", required = false)
 366  
     private String zipExtensions;
 367  
     /**
 368  
      * Skip Dependency Check altogether.
 369  
      */
 370  0
     @SuppressWarnings("CanBeFinal")
 371  
     @Parameter(property = "dependency-check.skip", defaultValue = "false", required = false)
 372  
     private boolean skip = false;
 373  
     /**
 374  
      * Skip Analysis for Test Scope Dependencies.
 375  
      */
 376  0
     @SuppressWarnings("CanBeFinal")
 377  
     @Parameter(property = "skipTestScope", defaultValue = "true", required = false)
 378  
     private boolean skipTestScope = true;
 379  
     /**
 380  
      * Skip Analysis for Runtime Scope Dependencies.
 381  
      */
 382  0
     @SuppressWarnings("CanBeFinal")
 383  
     @Parameter(property = "skipRuntimeScope", defaultValue = "false", required = false)
 384  
     private boolean skipRuntimeScope = false;
 385  
     /**
 386  
      * Skip Analysis for Provided Scope Dependencies.
 387  
      */
 388  0
     @SuppressWarnings("CanBeFinal")
 389  
     @Parameter(property = "skipProvidedScope", defaultValue = "false", required = false)
 390  
     private boolean skipProvidedScope = false;
 391  
     /**
 392  
      * The data directory, hold DC SQL DB.
 393  
      */
 394  
     @Parameter(property = "dataDirectory", defaultValue = "", required = false)
 395  
     private String dataDirectory;
 396  
     /**
 397  
      * Data Mirror URL for CVE 1.2.
 398  
      */
 399  
     @Parameter(property = "cveUrl12Modified", defaultValue = "", required = false)
 400  
     private String cveUrl12Modified;
 401  
     /**
 402  
      * Data Mirror URL for CVE 2.0.
 403  
      */
 404  
     @Parameter(property = "cveUrl20Modified", defaultValue = "", required = false)
 405  
     private String cveUrl20Modified;
 406  
     /**
 407  
      * Base Data Mirror URL for CVE 1.2.
 408  
      */
 409  
     @Parameter(property = "cveUrl12Base", defaultValue = "", required = false)
 410  
     private String cveUrl12Base;
 411  
     /**
 412  
      * Data Mirror URL for CVE 2.0.
 413  
      */
 414  
     @Parameter(property = "cveUrl20Base", defaultValue = "", required = false)
 415  
     private String cveUrl20Base;
 416  
     /**
 417  
      * Optionally skip excessive CVE update checks for a designated duration in
 418  
      * hours.
 419  
      */
 420  
     @Parameter(property = "cveValidForHours", defaultValue = "", required = false)
 421  
     private Integer cveValidForHours;
 422  
 
 423  
     /**
 424  
      * The path to mono for .NET Assembly analysis on non-windows systems.
 425  
      */
 426  
     @Parameter(property = "pathToMono", defaultValue = "", required = false)
 427  
     private String pathToMono;
 428  
 
 429  
     /**
 430  
      * The Proxy URL.
 431  
      *
 432  
      * @deprecated Please use mavenSettings instead
 433  
      */
 434  0
     @SuppressWarnings("CanBeFinal")
 435  
     @Parameter(property = "proxyUrl", defaultValue = "", required = false)
 436  
     @Deprecated
 437  
     private String proxyUrl = null;
 438  
     /**
 439  
      * Sets whether or not the external report format should be used.
 440  
      *
 441  
      * @deprecated the internal report is no longer supported
 442  
      */
 443  0
     @SuppressWarnings("CanBeFinal")
 444  
     @Parameter(property = "externalReport")
 445  
     @Deprecated
 446  
     private String externalReport = null;
 447  
     // </editor-fold>
 448  
     //<editor-fold defaultstate="collapsed" desc="Base Maven implementation">
 449  
 
 450  
     /**
 451  
      * Executes dependency-check.
 452  
      *
 453  
      * @throws MojoExecutionException thrown if there is an exception executing
 454  
      * the mojo
 455  
      * @throws MojoFailureException thrown if dependency-check failed the build
 456  
      */
 457  
     @Override
 458  
     public void execute() throws MojoExecutionException, MojoFailureException {
 459  0
         generatingSite = false;
 460  0
         if (skip) {
 461  0
             getLog().info("Skipping " + getName(Locale.US));
 462  
         } else {
 463  0
             validateAggregate();
 464  0
             project.setContextValue(getOutputDirectoryContextKey(), this.outputDirectory);
 465  0
             runCheck();
 466  
         }
 467  0
     }
 468  
 
 469  
     /**
 470  
      * Checks if the aggregate configuration parameter has been set to true. If
 471  
      * it has a MojoExecutionException is thrown because the aggregate
 472  
      * configuration parameter is no longer supported.
 473  
      *
 474  
      * @throws MojoExecutionException thrown if aggregate is set to true
 475  
      */
 476  
     private void validateAggregate() throws MojoExecutionException {
 477  0
         if (aggregate != null && aggregate) {
 478  0
             final String msg = "Aggregate configuration detected - as of dependency-check 1.2.8 this no longer supported. "
 479  
                     + "Please use the aggregate goal instead.";
 480  0
             throw new MojoExecutionException(msg);
 481  
         }
 482  0
     }
 483  
 
 484  
     /**
 485  
      * Generates the Dependency-Check Site Report.
 486  
      *
 487  
      * @param sink the sink to write the report to
 488  
      * @param locale the locale to use when generating the report
 489  
      * @throws MavenReportException if a maven report exception occurs
 490  
      * @deprecated use
 491  
      * {@link #generate(org.apache.maven.doxia.sink.Sink, java.util.Locale)}
 492  
      * instead.
 493  
      */
 494  
     @Override
 495  
     @Deprecated
 496  
     public final void generate(@SuppressWarnings("deprecation") org.codehaus.doxia.sink.Sink sink, Locale locale) throws MavenReportException {
 497  0
         generate((Sink) sink, locale);
 498  0
     }
 499  
 
 500  
     /**
 501  
      * A flag indicating whether or not the maven site is being generated.
 502  
      */
 503  0
     private boolean generatingSite = false;
 504  
 
 505  
     /**
 506  
      * Returns true if the Maven site is being generated.
 507  
      *
 508  
      * @return true if the Maven site is being generated
 509  
      */
 510  
     protected boolean isGeneratingSite() {
 511  0
         return generatingSite;
 512  
     }
 513  
 
 514  
     /**
 515  
      * Generates the Dependency-Check Site Report.
 516  
      *
 517  
      * @param sink the sink to write the report to
 518  
      * @param locale the locale to use when generating the report
 519  
      * @throws MavenReportException if a maven report exception occurs
 520  
      */
 521  
     public void generate(Sink sink, Locale locale) throws MavenReportException {
 522  0
         generatingSite = true;
 523  
         try {
 524  0
             validateAggregate();
 525  0
         } catch (MojoExecutionException ex) {
 526  0
             throw new MavenReportException(ex.getMessage());
 527  0
         }
 528  0
         project.setContextValue(getOutputDirectoryContextKey(), getReportOutputDirectory());
 529  
         try {
 530  0
             runCheck();
 531  0
         } catch (MojoExecutionException ex) {
 532  0
             throw new MavenReportException(ex.getMessage(), ex);
 533  0
         } catch (MojoFailureException ex) {
 534  0
             getLog().warn("Vulnerabilities were identifies that exceed the CVSS threshold for failing the build");
 535  0
         }
 536  0
     }
 537  
 
 538  
     /**
 539  
      * Returns the correct output directory depending on if a site is being
 540  
      * executed or not.
 541  
      *
 542  
      * @return the directory to write the report(s)
 543  
      * @throws MojoExecutionException thrown if there is an error loading the
 544  
      * file path
 545  
      */
 546  
     protected File getCorrectOutputDirectory() throws MojoExecutionException {
 547  0
         return getCorrectOutputDirectory(this.project);
 548  
     }
 549  
 
 550  
     /**
 551  
      * Returns the correct output directory depending on if a site is being
 552  
      * executed or not.
 553  
      *
 554  
      * @param current the Maven project to get the output directory from
 555  
      * @return the directory to write the report(s)
 556  
      */
 557  
     protected File getCorrectOutputDirectory(MavenProject current) {
 558  0
         final Object obj = current.getContextValue(getOutputDirectoryContextKey());
 559  0
         if (obj != null && obj instanceof File) {
 560  0
             return (File) obj;
 561  
         }
 562  0
         File target = new File(current.getBuild().getDirectory());
 563  0
         if (target.getParentFile() != null && "target".equals(target.getParentFile().getName())) {
 564  0
             target = target.getParentFile();
 565  
         }
 566  0
         return target;
 567  
     }
 568  
 
 569  
     /**
 570  
      * Returns the correct output directory depending on if a site is being
 571  
      * executed or not.
 572  
      *
 573  
      * @param current the Maven project to get the output directory from
 574  
      * @return the directory to write the report(s)
 575  
      */
 576  
     protected File getDataFile(MavenProject current) {
 577  0
         if (getLog().isDebugEnabled()) {
 578  0
             getLog().debug(String.format("Getting data filefor %s using key '%s'", current.getName(), getDataFileContextKey()));
 579  
         }
 580  0
         final Object obj = current.getContextValue(getDataFileContextKey());
 581  0
         if (obj != null) {
 582  0
             if (obj instanceof String) {
 583  0
                 final File f = new File((String) obj);
 584  0
                 return f;
 585  
             }
 586  0
         } else if (getLog().isDebugEnabled()) {
 587  0
             getLog().debug("Context value not found");
 588  
         }
 589  0
         return null;
 590  
     }
 591  
 
 592  
     /**
 593  
      * Scans the project's artifacts and adds them to the engine's dependency
 594  
      * list.
 595  
      *
 596  
      * @param project the project to scan the dependencies of
 597  
      * @param engine the engine to use to scan the dependencies
 598  
      * @return a collection of exceptions that may have occurred while resolving
 599  
      * and scanning the dependencies
 600  
      */
 601  
     protected ExceptionCollection scanArtifacts(MavenProject project, MavenEngine engine) {
 602  
         // <editor-fold defaultstate="collapsed" desc="old implementation">
 603  
         /*
 604  
             for (Artifact a : project.getArtifacts()) {
 605  
             if (excludeFromScan(a)) {
 606  
             continue;
 607  
             }
 608  
             final List<Dependency> deps = engine.scan(a.getFile().getAbsoluteFile());
 609  
             if (deps != null) {
 610  
             if (deps.size() == 1) {
 611  
             final Dependency d = deps.get(0);
 612  
             if (d != null) {
 613  
             final MavenArtifact ma = new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion());
 614  
             d.addAsEvidence("pom", ma, Confidence.HIGHEST);
 615  
             d.addProjectReference(project.getName());
 616  
             if (getLog().isDebugEnabled()) {
 617  
             getLog().debug(String.format("Adding project reference %s on dependency %s", project.getName(),
 618  
             d.getDisplayFileName()));
 619  
             }
 620  
             }
 621  
             } else if (getLog().isDebugEnabled()) {
 622  
             final String msg = String.format("More then 1 dependency was identified in first pass scan of '%s:%s:%s'",
 623  
             a.getGroupId(), a.getArtifactId(), a.getVersion());
 624  
             getLog().debug(msg);
 625  
             }
 626  
             }
 627  
             }
 628  
          */
 629  
         // </editor-fold>
 630  
         try {
 631  0
             final DependencyNode dn = dependencyGraphBuilder.buildDependencyGraph(project, null, reactorProjects);
 632  0
             return collectDependencies(engine, project, dn.getChildren());
 633  0
         } catch (DependencyGraphBuilderException ex) {
 634  0
             final String msg = String.format("Unable to build dependency graph on project %s", project.getName());
 635  0
             getLog().debug(msg, ex);
 636  0
             return new ExceptionCollection(msg, ex);
 637  
         }
 638  
     }
 639  
 
 640  
     /**
 641  
      * Resolves the projects artifacts using Aether and scans the resulting
 642  
      * dependencies.
 643  
      *
 644  
      * @param engine the core dependency-check engine
 645  
      * @param project the project being scanned
 646  
      * @param nodes the list of dependency nodes, generally obtained via the
 647  
      * DependencyGraphBuilder
 648  
      * @return a collection of exceptions that may have occurred while resolving
 649  
      * and scanning the dependencies
 650  
      */
 651  
     private ExceptionCollection collectDependencies(MavenEngine engine, MavenProject project, List<DependencyNode> nodes) {
 652  0
         ExceptionCollection exCol = null;
 653  0
         for (DependencyNode dependencyNode : nodes) {
 654  0
             exCol = collectDependencies(engine, project, dependencyNode.getChildren());
 655  0
             if (excludeFromScan(dependencyNode.getArtifact().getScope())) {
 656  0
                 continue;
 657  
             }
 658  0
             final ArtifactRequest request = new ArtifactRequest();
 659  0
             request.setArtifact(new DefaultArtifact(dependencyNode.getArtifact().getId()));
 660  0
             request.setRepositories(remoteRepos);
 661  
             try {
 662  0
                 final ArtifactResult result = repoSystem.resolveArtifact(repoSession, request);
 663  0
                 if (result.isResolved() && result.getArtifact() != null && result.getArtifact().getFile() != null) {
 664  0
                     final List<Dependency> deps = engine.scan(result.getArtifact().getFile().getAbsoluteFile(),
 665  0
                             project.getName() + ":" + dependencyNode.getArtifact().getScope());
 666  0
                     if (deps != null) {
 667  0
                         if (deps.size() == 1) {
 668  0
                             final Dependency d = deps.get(0);
 669  0
                             if (d != null) {
 670  0
                                 final Artifact a = result.getArtifact();
 671  0
                                 final MavenArtifact ma = new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion());
 672  0
                                 d.addAsEvidence("pom", ma, Confidence.HIGHEST);
 673  0
                                 if (getLog().isDebugEnabled()) {
 674  0
                                     getLog().debug(String.format("Adding project reference %s on dependency %s",
 675  0
                                             project.getName(), d.getDisplayFileName()));
 676  
                                 }
 677  
                             }
 678  0
                         } else if (getLog().isDebugEnabled()) {
 679  0
                             final String msg = String.format("More then 1 dependency was identified in first pass scan of '%s' in project %s",
 680  0
                                     dependencyNode.getArtifact().getId(), project.getName());
 681  0
                             getLog().debug(msg);
 682  0
                         }
 683  
                     } else {
 684  0
                         final String msg = String.format("Error resolving '%s' in project %s",
 685  0
                                 dependencyNode.getArtifact().getId(), project.getName());
 686  0
                         if (exCol == null) {
 687  0
                             exCol = new ExceptionCollection();
 688  
                         }
 689  0
                         getLog().error(msg);
 690  0
                         for (Exception ex : result.getExceptions()) {
 691  0
                             exCol.addException(ex);
 692  0
                         }
 693  
                     }
 694  0
                 } else {
 695  0
                     final String msg = String.format("Unable to resolve '%s' in project %s",
 696  0
                             dependencyNode.getArtifact().getId(), project.getName());
 697  0
                     getLog().debug(msg);
 698  0
                     if (exCol == null) {
 699  0
                         exCol = new ExceptionCollection();
 700  
                     }
 701  0
                     for (Exception ex : result.getExceptions()) {
 702  0
                         exCol.addException(ex);
 703  0
                     }
 704  
                 }
 705  0
             } catch (ArtifactResolutionException ex) {
 706  0
                 if (exCol == null) {
 707  0
                     exCol = new ExceptionCollection();
 708  
                 }
 709  0
                 exCol.addException(ex);
 710  0
             }
 711  0
         }
 712  0
         return exCol;
 713  
     }
 714  
 
 715  
     /**
 716  
      * Executes the dependency-check scan and generates the necassary report.
 717  
      *
 718  
      * @throws MojoExecutionException thrown if there is an exception running
 719  
      * the scan
 720  
      * @throws MojoFailureException thrown if dependency-check is configured to
 721  
      * fail the build
 722  
      */
 723  
     public abstract void runCheck() throws MojoExecutionException, MojoFailureException;
 724  
 
 725  
     /**
 726  
      * Sets the Reporting output directory.
 727  
      *
 728  
      * @param directory the output directory
 729  
      */
 730  
     @Override
 731  
     public void setReportOutputDirectory(File directory) {
 732  0
         reportOutputDirectory = directory;
 733  0
     }
 734  
 
 735  
     /**
 736  
      * Returns the report output directory.
 737  
      *
 738  
      * @return the report output directory
 739  
      */
 740  
     @Override
 741  
     public File getReportOutputDirectory() {
 742  0
         return reportOutputDirectory;
 743  
     }
 744  
 
 745  
     /**
 746  
      * Returns the output directory.
 747  
      *
 748  
      * @return the output directory
 749  
      */
 750  
     public File getOutputDirectory() {
 751  0
         return outputDirectory;
 752  
     }
 753  
 
 754  
     /**
 755  
      * Returns whether this is an external report. This method always returns
 756  
      * true.
 757  
      *
 758  
      * @return <code>true</code>
 759  
      */
 760  
     @Override
 761  
     public final boolean isExternalReport() {
 762  0
         return true;
 763  
     }
 764  
 
 765  
     /**
 766  
      * Returns the output name.
 767  
      *
 768  
      * @return the output name
 769  
      */
 770  
     @Override
 771  
     public String getOutputName() {
 772  0
         if ("HTML".equalsIgnoreCase(this.format) || "ALL".equalsIgnoreCase(this.format)) {
 773  0
             return "dependency-check-report";
 774  0
         } else if ("XML".equalsIgnoreCase(this.format)) {
 775  0
             return "dependency-check-report.xml#";
 776  0
         } else if ("VULN".equalsIgnoreCase(this.format)) {
 777  0
             return "dependency-check-vulnerability";
 778  
         } else {
 779  0
             getLog().warn("Unknown report format used during site generation.");
 780  0
             return "dependency-check-report";
 781  
         }
 782  
     }
 783  
 
 784  
     /**
 785  
      * Returns the category name.
 786  
      *
 787  
      * @return the category name
 788  
      */
 789  
     @Override
 790  
     public String getCategoryName() {
 791  0
         return MavenReport.CATEGORY_PROJECT_REPORTS;
 792  
     }
 793  
     //</editor-fold>
 794  
 
 795  
     /**
 796  
      * Initializes a new <code>MavenEngine</code> that can be used for scanning.
 797  
      *
 798  
      * @return a newly instantiated <code>MavenEngine</code>
 799  
      * @throws DatabaseException thrown if there is a database exception
 800  
      */
 801  
     protected MavenEngine initializeEngine() throws DatabaseException {
 802  0
         populateSettings();
 803  0
         return new MavenEngine(this.project, this.reactorProjects);
 804  
     }
 805  
 
 806  
     /**
 807  
      * Takes the properties supplied and updates the dependency-check settings.
 808  
      * Additionally, this sets the system properties required to change the
 809  
      * proxy url, port, and connection timeout.
 810  
      */
 811  
     protected void populateSettings() {
 812  0
         Settings.initialize();
 813  0
         InputStream mojoProperties = null;
 814  
         try {
 815  0
             mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
 816  0
             Settings.mergeProperties(mojoProperties);
 817  0
         } catch (IOException ex) {
 818  0
             getLog().warn("Unable to load the dependency-check ant task.properties file.");
 819  0
             if (getLog().isDebugEnabled()) {
 820  0
                 getLog().debug("", ex);
 821  
             }
 822  
         } finally {
 823  0
             if (mojoProperties != null) {
 824  
                 try {
 825  0
                     mojoProperties.close();
 826  0
                 } catch (IOException ex) {
 827  0
                     if (getLog().isDebugEnabled()) {
 828  0
                         getLog().debug("", ex);
 829  
                     }
 830  0
                 }
 831  
             }
 832  
         }
 833  0
         Settings.setBooleanIfNotNull(Settings.KEYS.AUTO_UPDATE, autoUpdate);
 834  
 
 835  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, enableExperimental);
 836  
 
 837  0
         if (externalReport != null) {
 838  0
             getLog().warn("The 'externalReport' option was set; this configuration option has been removed. "
 839  
                     + "Please update the dependency-check-maven plugin's configuration");
 840  
         }
 841  
 
 842  0
         if (proxyUrl != null && !proxyUrl.isEmpty()) {
 843  0
             getLog().warn("Deprecated configuration detected, proxyUrl will be ignored; use the maven settings " + "to configure the proxy instead");
 844  
         }
 845  0
         final Proxy proxy = getMavenProxy();
 846  0
         if (proxy != null) {
 847  0
             Settings.setString(Settings.KEYS.PROXY_SERVER, proxy.getHost());
 848  0
             Settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort()));
 849  0
             final String userName = proxy.getUsername();
 850  0
             final String password = proxy.getPassword();
 851  0
             Settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName);
 852  0
             Settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password);
 853  0
             Settings.setStringIfNotNull(Settings.KEYS.PROXY_NON_PROXY_HOSTS, proxy.getNonProxyHosts());
 854  
         }
 855  
 
 856  0
         Settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
 857  0
         Settings.setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE, suppressionFile);
 858  0
         Settings.setStringIfNotEmpty(Settings.KEYS.HINTS_FILE, hintsFile);
 859  
 
 860  
         //File Type Analyzer Settings
 861  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled);
 862  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled);
 863  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled);
 864  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled);
 865  0
         Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
 866  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY, nexusUsesProxy);
 867  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled);
 868  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled);
 869  0
         Settings.setStringIfNotEmpty(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions);
 870  0
         Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono);
 871  
 
 872  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_DISTRIBUTION_ENABLED, pyDistributionAnalyzerEnabled);
 873  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_PACKAGE_ENABLED, pyPackageAnalyzerEnabled);
 874  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RUBY_GEMSPEC_ENABLED, rubygemsAnalyzerEnabled);
 875  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OPENSSL_ENABLED, opensslAnalyzerEnabled);
 876  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CMAKE_ENABLED, cmakeAnalyzerEnabled);
 877  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_AUTOCONF_ENABLED, autoconfAnalyzerEnabled);
 878  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_ENABLED, composerAnalyzerEnabled);
 879  0
         Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED, nodeAnalyzerEnabled);
 880  
 
 881  
         //Database configuration
 882  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName);
 883  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath);
 884  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
 885  
 
 886  0
         if (databaseUser == null && databasePassword == null && serverId != null) {
 887  0
             final Server server = settingsXml.getServer(serverId);
 888  0
             if (server != null) {
 889  0
                 databaseUser = server.getUsername();
 890  
                 try {
 891  
                     //The following fix was copied from:
 892  
                     //   https://github.com/bsorrentino/maven-confluence-plugin/blob/master/maven-confluence-reporting-plugin/src/main/java/org/bsc/maven/confluence/plugin/AbstractBaseConfluenceMojo.java
 893  
                     //
 894  
                     // FIX to resolve
 895  
                     // org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException:
 896  
                     // java.io.FileNotFoundException: ~/.settings-security.xml (No such file or directory)
 897  
                     //
 898  0
                     if (securityDispatcher instanceof DefaultSecDispatcher) {
 899  0
                         ((DefaultSecDispatcher) securityDispatcher).setConfigurationFile("~/.m2/settings-security.xml");
 900  
                     }
 901  
 
 902  0
                     databasePassword = securityDispatcher.decrypt(server.getPassword());
 903  0
                 } catch (SecDispatcherException ex) {
 904  0
                     if (ex.getCause() instanceof FileNotFoundException
 905  0
                             || (ex.getCause() != null && ex.getCause().getCause() instanceof FileNotFoundException)) {
 906  
                         //maybe its not encrypted?
 907  0
                         final String tmp = server.getPassword();
 908  0
                         if (tmp.startsWith("{") && tmp.endsWith("}")) {
 909  0
                             getLog().error(String.format(
 910  
                                     "Unable to decrypt the server password for server id '%s' in settings.xml%n\tCause: %s",
 911  0
                                     serverId, ex.getMessage()));
 912  
                         } else {
 913  0
                             databasePassword = tmp;
 914  
                         }
 915  0
                     } else {
 916  0
                         getLog().error(String.format(
 917  
                                 "Unable to decrypt the server password for server id '%s' in settings.xml%n\tCause: %s",
 918  0
                                 serverId, ex.getMessage()));
 919  
                     }
 920  0
                 }
 921  
             } else {
 922  0
                 getLog().error(String.format("Server '%s' not found in the settings.xml file", serverId));
 923  
             }
 924  
         }
 925  
 
 926  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DB_USER, databaseUser);
 927  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DB_PASSWORD, databasePassword);
 928  0
         Settings.setStringIfNotEmpty(Settings.KEYS.DATA_DIRECTORY, dataDirectory);
 929  
 
 930  0
         Settings.setStringIfNotEmpty(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified);
 931  0
         Settings.setStringIfNotEmpty(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified);
 932  0
         Settings.setStringIfNotEmpty(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base);
 933  0
         Settings.setStringIfNotEmpty(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base);
 934  0
         Settings.setIntIfNotNull(Settings.KEYS.CVE_CHECK_VALID_FOR_HOURS, cveValidForHours);
 935  
 
 936  0
     }
 937  
 
 938  
     /**
 939  
      * Returns the maven proxy.
 940  
      *
 941  
      * @return the maven proxy
 942  
      */
 943  
     private Proxy getMavenProxy() {
 944  0
         if (mavenSettings != null) {
 945  0
             final List<Proxy> proxies = mavenSettings.getProxies();
 946  0
             if (proxies != null && !proxies.isEmpty()) {
 947  0
                 if (mavenSettingsProxyId != null) {
 948  0
                     for (Proxy proxy : proxies) {
 949  0
                         if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) {
 950  0
                             return proxy;
 951  
                         }
 952  0
                     }
 953  0
                 } else if (proxies.size() == 1) {
 954  0
                     return proxies.get(0);
 955  
                 } else {
 956  0
                     getLog().warn("Multiple proxy definitions exist in the Maven settings. In the dependency-check "
 957  
                             + "configuration set the mavenSettingsProxyId so that the correct proxy will be used.");
 958  0
                     throw new IllegalStateException("Ambiguous proxy definition");
 959  
                 }
 960  
             }
 961  
         }
 962  0
         return null;
 963  
     }
 964  
 
 965  
     /**
 966  
      * Tests is the artifact should be included in the scan (i.e. is the
 967  
      * dependency in a scope that is being scanned).
 968  
      *
 969  
      * @param scope the scope of the artifact to test
 970  
      * @return <code>true</code> if the artifact is in an excluded scope;
 971  
      * otherwise <code>false</code>
 972  
      */
 973  
     protected boolean excludeFromScan(String scope) {
 974  0
         if (skipTestScope && org.apache.maven.artifact.Artifact.SCOPE_TEST.equals(scope)) {
 975  0
             return true;
 976  
         }
 977  0
         if (skipProvidedScope && org.apache.maven.artifact.Artifact.SCOPE_PROVIDED.equals(scope)) {
 978  0
             return true;
 979  
         }
 980  0
         if (skipRuntimeScope && !org.apache.maven.artifact.Artifact.SCOPE_RUNTIME.equals(scope)) {
 981  0
             return true;
 982  
         }
 983  0
         return false;
 984  
     }
 985  
 
 986  
     /**
 987  
      * Returns a reference to the current project. This method is used instead
 988  
      * of auto-binding the project via component annotation in concrete
 989  
      * implementations of this. If the child has a
 990  
      * <code>@Component MavenProject project;</code> defined then the abstract
 991  
      * class (i.e. this class) will not have access to the current project (just
 992  
      * the way Maven works with the binding).
 993  
      *
 994  
      * @return returns a reference to the current project
 995  
      */
 996  
     protected MavenProject getProject() {
 997  0
         return project;
 998  
     }
 999  
 
 1000  
     /**
 1001  
      * Returns the list of Maven Projects in this build.
 1002  
      *
 1003  
      * @return the list of Maven Projects in this build
 1004  
      */
 1005  
     protected List<MavenProject> getReactorProjects() {
 1006  0
         return reactorProjects;
 1007  
     }
 1008  
 
 1009  
     /**
 1010  
      * Returns the report format.
 1011  
      *
 1012  
      * @return the report format
 1013  
      */
 1014  
     protected String getFormat() {
 1015  0
         return format;
 1016  
     }
 1017  
 
 1018  
     /**
 1019  
      * Generates the reports for a given dependency-check engine.
 1020  
      *
 1021  
      * @param engine a dependency-check engine
 1022  
      * @param p the Maven project
 1023  
      * @param outputDir the directory path to write the report(s)
 1024  
      * @throws ReportException thrown if there is an error writing the report
 1025  
      */
 1026  
     protected void writeReports(MavenEngine engine, MavenProject p, File outputDir) throws ReportException {
 1027  0
         DatabaseProperties prop = null;
 1028  0
         CveDB cve = null;
 1029  
         try {
 1030  0
             cve = new CveDB();
 1031  0
             cve.open();
 1032  0
             prop = cve.getDatabaseProperties();
 1033  0
         } catch (DatabaseException ex) {
 1034  0
             if (getLog().isDebugEnabled()) {
 1035  0
                 getLog().debug("Unable to retrieve DB Properties", ex);
 1036  
             }
 1037  
         } finally {
 1038  0
             if (cve != null) {
 1039  0
                 cve.close();
 1040  
             }
 1041  
         }
 1042  0
         final ReportGenerator r = new ReportGenerator(p.getName(), engine.getDependencies(), engine.getAnalyzers(), prop);
 1043  
         try {
 1044  0
             r.generateReports(outputDir.getAbsolutePath(), format);
 1045  0
         } catch (ReportException ex) {
 1046  0
             final String msg = String.format("Error generating the report for %s", p.getName());
 1047  0
             throw new ReportException(msg, ex);
 1048  0
         }
 1049  
 
 1050  0
     }
 1051  
 
 1052  
     //<editor-fold defaultstate="collapsed" desc="Methods to fail build or show summary">
 1053  
     /**
 1054  
      * Checks to see if a vulnerability has been identified with a CVSS score
 1055  
      * that is above the threshold set in the configuration.
 1056  
      *
 1057  
      * @param dependencies the list of dependency objects
 1058  
      * @throws MojoFailureException thrown if a CVSS score is found that is
 1059  
      * higher then the threshold set
 1060  
      */
 1061  
     protected void checkForFailure(List<Dependency> dependencies) throws MojoFailureException {
 1062  0
         if (failBuildOnCVSS <= 10) {
 1063  0
             final StringBuilder ids = new StringBuilder();
 1064  0
             for (Dependency d : dependencies) {
 1065  0
                 boolean addName = true;
 1066  0
                 for (Vulnerability v : d.getVulnerabilities()) {
 1067  0
                     if (v.getCvssScore() >= failBuildOnCVSS) {
 1068  0
                         if (addName) {
 1069  0
                             addName = false;
 1070  0
                             ids.append(NEW_LINE).append(d.getFileName()).append(": ");
 1071  0
                             ids.append(v.getName());
 1072  
                         } else {
 1073  0
                             ids.append(", ").append(v.getName());
 1074  
                         }
 1075  
                     }
 1076  0
                 }
 1077  0
             }
 1078  0
             if (ids.length() > 0) {
 1079  0
                 final String msg = String.format("%n%nDependency-Check Failure:%n"
 1080  
                         + "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n"
 1081  0
                         + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString());
 1082  0
                 throw new MojoFailureException(msg);
 1083  
             }
 1084  
         }
 1085  0
     }
 1086  
 
 1087  
     /**
 1088  
      * Generates a warning message listing a summary of dependencies and their
 1089  
      * associated CPE and CVE entries.
 1090  
      *
 1091  
      * @param mp the Maven project for which the summary is shown
 1092  
      * @param dependencies a list of dependency objects
 1093  
      */
 1094  
     protected void showSummary(MavenProject mp, List<Dependency> dependencies) {
 1095  0
         if (showSummary) {
 1096  0
             final StringBuilder summary = new StringBuilder();
 1097  0
             for (Dependency d : dependencies) {
 1098  0
                 boolean firstEntry = true;
 1099  0
                 final StringBuilder ids = new StringBuilder();
 1100  0
                 for (Vulnerability v : d.getVulnerabilities()) {
 1101  0
                     if (firstEntry) {
 1102  0
                         firstEntry = false;
 1103  
                     } else {
 1104  0
                         ids.append(", ");
 1105  
                     }
 1106  0
                     ids.append(v.getName());
 1107  0
                 }
 1108  0
                 if (ids.length() > 0) {
 1109  0
                     summary.append(d.getFileName()).append(" (");
 1110  0
                     firstEntry = true;
 1111  0
                     for (Identifier id : d.getIdentifiers()) {
 1112  0
                         if (firstEntry) {
 1113  0
                             firstEntry = false;
 1114  
                         } else {
 1115  0
                             summary.append(", ");
 1116  
                         }
 1117  0
                         summary.append(id.getValue());
 1118  0
                     }
 1119  0
                     summary.append(") : ").append(ids).append(NEW_LINE);
 1120  
                 }
 1121  0
             }
 1122  0
             if (summary.length() > 0) {
 1123  0
                 final String msg = String.format("%n%n" + "One or more dependencies were identified with known vulnerabilities in %s:%n%n%s"
 1124  0
                         + "%n%nSee the dependency-check report for more details.%n%n", mp.getName(), summary.toString());
 1125  0
                 getLog().warn(msg);
 1126  
             }
 1127  
         }
 1128  0
     }
 1129  
 
 1130  
     //</editor-fold>
 1131  
     //<editor-fold defaultstate="collapsed" desc="Methods to read/write the serialized data file">
 1132  
     /**
 1133  
      * Returns the key used to store the path to the data file that is saved by
 1134  
      * <code>writeDataFile()</code>. This key is used in the
 1135  
      * <code>MavenProject.(set|get)ContextValue</code>.
 1136  
      *
 1137  
      * @return the key used to store the path to the data file
 1138  
      */
 1139  
     protected String getDataFileContextKey() {
 1140  0
         return "dependency-check-path-" + dataFileName;
 1141  
     }
 1142  
 
 1143  
     /**
 1144  
      * Returns the key used to store the path to the output directory. When
 1145  
      * generating the report in the <code>executeAggregateReport()</code> the
 1146  
      * output directory should be obtained by using this key.
 1147  
      *
 1148  
      * @return the key used to store the path to the output directory
 1149  
      */
 1150  
     protected String getOutputDirectoryContextKey() {
 1151  0
         return "dependency-output-dir-" + dataFileName;
 1152  
     }
 1153  
 
 1154  
     /**
 1155  
      * Writes the scan data to disk. This is used to serialize the scan data
 1156  
      * between the "check" and "aggregate" phase.
 1157  
      *
 1158  
      * @param mp the mMven project for which the data file was created
 1159  
      * @param writeTo the directory to write the data file
 1160  
      * @param dependencies the list of dependencies to serialize
 1161  
      */
 1162  
     protected void writeDataFile(MavenProject mp, File writeTo, List<Dependency> dependencies) {
 1163  
         File file;
 1164  
         //check to see if this was already written out
 1165  0
         if (mp.getContextValue(this.getDataFileContextKey()) == null) {
 1166  0
             if (writeTo == null) {
 1167  0
                 file = new File(mp.getBuild().getDirectory());
 1168  0
                 file = new File(file, dataFileName);
 1169  
             } else {
 1170  0
                 file = new File(writeTo, dataFileName);
 1171  
             }
 1172  0
             final File parent = file.getParentFile();
 1173  0
             if (!parent.isDirectory() && !parent.mkdirs()) {
 1174  0
                 getLog().error(String.format("Directory '%s' does not exist and cannot be created; unable to write data file.",
 1175  0
                         parent.getAbsolutePath()));
 1176  
             }
 1177  
 
 1178  0
             ObjectOutputStream out = null;
 1179  
             try {
 1180  0
                 if (dependencies != null) {
 1181  0
                     out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
 1182  0
                     out.writeObject(dependencies);
 1183  
                 }
 1184  0
                 if (getLog().isDebugEnabled()) {
 1185  0
                     getLog().debug(String.format("Serialized data file written to '%s' for %s, referenced by key %s",
 1186  0
                             file.getAbsolutePath(), mp.getName(), this.getDataFileContextKey()));
 1187  
                 }
 1188  0
                 mp.setContextValue(this.getDataFileContextKey(), file.getAbsolutePath());
 1189  0
             } catch (IOException ex) {
 1190  0
                 getLog().warn("Unable to create data file used for report aggregation; "
 1191  
                         + "if report aggregation is being used the results may be incomplete.");
 1192  0
                 if (getLog().isDebugEnabled()) {
 1193  0
                     getLog().debug(ex.getMessage(), ex);
 1194  
                 }
 1195  
             } finally {
 1196  0
                 if (out != null) {
 1197  
                     try {
 1198  0
                         out.close();
 1199  0
                     } catch (IOException ex) {
 1200  0
                         if (getLog().isDebugEnabled()) {
 1201  0
                             getLog().debug("ignore", ex);
 1202  
                         }
 1203  0
                     }
 1204  
                 }
 1205  
             }
 1206  
         }
 1207  0
     }
 1208  
 
 1209  
     /**
 1210  
      * Reads the serialized scan data from disk. This is used to serialize the
 1211  
      * scan data between the "check" and "aggregate" phase.
 1212  
      *
 1213  
      * @param project the Maven project to read the data file from
 1214  
      * @return a <code>MavenEngine</code> object populated with dependencies if
 1215  
      * the serialized data file exists; otherwise <code>null</code> is returned
 1216  
      */
 1217  
     protected List<Dependency> readDataFile(MavenProject project) {
 1218  0
         final Object oPath = project.getContextValue(this.getDataFileContextKey());
 1219  0
         if (oPath == null) {
 1220  0
             return null;
 1221  
         }
 1222  0
         List<Dependency> ret = null;
 1223  0
         final String path = (String) oPath;
 1224  
         //ObjectInputStream ois = null;
 1225  0
         ExpectedOjectInputStream ois = null;
 1226  
         try {
 1227  
             //ois = new ObjectInputStream(new FileInputStream(path));
 1228  0
             ois = new ExpectedOjectInputStream(new FileInputStream(path),
 1229  
                     "java.util.ArrayList",
 1230  
                     "java.util.HashSet",
 1231  
                     "java.util.TreeSet",
 1232  
                     "java.lang.AbstractSet",
 1233  
                     "java.lang.AbstractCollection",
 1234  
                     "java.lang.Enum",
 1235  
                     "org.owasp.dependencycheck.dependency.Confidence",
 1236  
                     "org.owasp.dependencycheck.dependency.Dependency",
 1237  
                     "org.owasp.dependencycheck.dependency.Evidence",
 1238  
                     "org.owasp.dependencycheck.dependency.EvidenceCollection",
 1239  
                     "org.owasp.dependencycheck.dependency.Identifier",
 1240  
                     "org.owasp.dependencycheck.dependency.Reference",
 1241  
                     "org.owasp.dependencycheck.dependency.Vulnerability",
 1242  
                     "org.owasp.dependencycheck.dependency.VulnerabilityComparator",
 1243  
                     "org.owasp.dependencycheck.dependency.VulnerableSoftware",
 1244  
                     "org.owasp.dependencycheck.data.cpe.IndexEntry");
 1245  
             @SuppressWarnings("unchecked")
 1246  0
             final List<Dependency> depList = (List<Dependency>) ois.readObject();
 1247  0
             ret = depList;
 1248  0
         } catch (FileNotFoundException ex) {
 1249  
             //TODO fix logging
 1250  0
             getLog().error("", ex);
 1251  0
         } catch (IOException ex) {
 1252  0
             getLog().error("", ex);
 1253  0
         } catch (ClassNotFoundException ex) {
 1254  0
             getLog().error("", ex);
 1255  
         } finally {
 1256  0
             if (ois != null) {
 1257  
                 try {
 1258  0
                     ois.close();
 1259  0
                 } catch (IOException ex) {
 1260  0
                     getLog().error("", ex);
 1261  0
                 }
 1262  
             }
 1263  
         }
 1264  0
         return ret;
 1265  
     }
 1266  
     //</editor-fold>
 1267  
 
 1268  
 }