Coverage Report - org.owasp.dependencycheck.maven.UpdateMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
UpdateMojo
0%
0/24
0%
0/8
3
 
 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) 2013 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.maven;
 19  
 
 20  
 import java.util.Locale;
 21  
 import org.apache.maven.plugin.MojoExecutionException;
 22  
 import org.apache.maven.plugin.MojoFailureException;
 23  
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 24  
 import org.apache.maven.plugins.annotations.Mojo;
 25  
 import org.apache.maven.plugins.annotations.ResolutionScope;
 26  
 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
 27  
 import org.owasp.dependencycheck.data.update.exception.UpdateException;
 28  
 import org.owasp.dependencycheck.utils.Settings;
 29  
 
 30  
 /**
 31  
  * Maven Plugin that checks the project dependencies to see if they have any
 32  
  * known published vulnerabilities.
 33  
  *
 34  
  * @author Jeremy Long
 35  
  */
 36  
 @Mojo(
 37  
         name = "update-only",
 38  
         defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
 39  
         threadSafe = false,
 40  
         requiresDependencyResolution = ResolutionScope.NONE,
 41  
         requiresOnline = true
 42  
 )
 43  0
 public class UpdateMojo extends BaseDependencyCheckMojo {
 44  
 
 45  
     /**
 46  
      * Returns false; this mojo cannot generate a report.
 47  
      *
 48  
      * @return <code>false</code>
 49  
      */
 50  
     @Override
 51  
     public boolean canGenerateReport() {
 52  0
         return false;
 53  
     }
 54  
 
 55  
     /**
 56  
      * Executes the dependency-check engine on the project's dependencies and
 57  
      * generates the report.
 58  
      *
 59  
      * @throws MojoExecutionException thrown if there is an exception executing
 60  
      * the goal
 61  
      * @throws MojoFailureException thrown if dependency-check is configured to
 62  
      * fail the build
 63  
      */
 64  
     @Override
 65  
     public void runCheck() throws MojoExecutionException, MojoFailureException {
 66  0
         MavenEngine engine = null;
 67  
         try {
 68  0
             engine = initializeEngine();
 69  0
             engine.update();
 70  0
         } catch (DatabaseException ex) {
 71  0
             if (getLog().isDebugEnabled()) {
 72  0
                 getLog().debug("Database connection error", ex);
 73  
             }
 74  0
             final String msg = "An exception occurred connecting to the local database. Please see the log file for more details.";
 75  0
             if (this.isFailOnError()) {
 76  0
                 throw new MojoExecutionException(msg, ex);
 77  
             }
 78  0
             getLog().error(msg);
 79  0
         } catch (UpdateException ex) {
 80  0
             final String msg = "An exception occurred while downloading updates. Please see the log file for more details.";
 81  0
             if (this.isFailOnError()) {
 82  0
                 throw new MojoExecutionException(msg, ex);
 83  
             }
 84  0
             getLog().error(msg);
 85  0
         }
 86  0
         if (engine != null) {
 87  0
             engine.cleanup();
 88  
         }
 89  0
         Settings.cleanup();
 90  0
     }
 91  
 
 92  
     /**
 93  
      * Returns the report name.
 94  
      *
 95  
      * @param locale the location
 96  
      * @return the report name
 97  
      */
 98  
     @Override
 99  
     public String getName(Locale locale) {
 100  0
         return "dependency-check-update";
 101  
     }
 102  
 
 103  
     /**
 104  
      * Gets the description of the Dependency-Check report to be displayed in
 105  
      * the Maven Generated Reports page.
 106  
      *
 107  
      * @param locale The Locale to get the description for
 108  
      * @return the description
 109  
      */
 110  
     @Override
 111  
     public String getDescription(Locale locale) {
 112  0
         return "Updates the local cache of the NVD data from NIST.";
 113  
     }
 114  
 }