| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 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 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 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 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
@Override |
| 51 | |
public boolean canGenerateReport() { |
| 52 | 0 | return false; |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 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 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
@Override |
| 99 | |
public String getName(Locale locale) { |
| 100 | 0 | return "dependency-check-update"; |
| 101 | |
} |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public String getDescription(Locale locale) { |
| 112 | 0 | return "Updates the local cache of the NVD data from NIST."; |
| 113 | |
} |
| 114 | |
} |