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.Engine;
27 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
28 import org.owasp.dependencycheck.data.update.exception.UpdateException;
29 import org.owasp.dependencycheck.utils.Settings;
30
31
32
33
34
35
36
37 @Mojo(
38 name = "update-only",
39 defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
40 threadSafe = false,
41 requiresDependencyResolution = ResolutionScope.NONE,
42 requiresOnline = true,
43 aggregator = true
44 )
45 public class UpdateMojo extends BaseDependencyCheckMojo {
46
47
48
49
50
51
52 @Override
53 public boolean canGenerateReport() {
54 return false;
55 }
56
57
58
59
60
61
62
63
64
65
66 @Override
67 public void runCheck() throws MojoExecutionException, MojoFailureException {
68 Engine engine = null;
69 try {
70 engine = initializeEngine();
71 engine.doUpdates();
72 } catch (DatabaseException ex) {
73 if (getLog().isDebugEnabled()) {
74 getLog().debug("Database connection error", ex);
75 }
76 final String msg = "An exception occurred connecting to the local database. Please see the log file for more details.";
77 if (this.isFailOnError()) {
78 throw new MojoExecutionException(msg, ex);
79 }
80 getLog().error(msg);
81 } catch (UpdateException ex) {
82 final String msg = "An exception occurred while downloading updates. Please see the log file for more details.";
83 if (this.isFailOnError()) {
84 throw new MojoExecutionException(msg, ex);
85 }
86 getLog().error(msg);
87 }
88 if (engine != null) {
89 engine.cleanup();
90 }
91 Settings.cleanup();
92 }
93
94
95
96
97
98
99
100 @Override
101 public String getName(Locale locale) {
102 return "dependency-check-update";
103 }
104
105
106
107
108
109
110
111
112 @Override
113 public String getDescription(Locale locale) {
114 return "Updates the local cache of the NVD data from NIST.";
115 }
116 }