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 public class UpdateMojo extends BaseDependencyCheckMojo {
44
45
46
47
48
49
50 @Override
51 public boolean canGenerateReport() {
52 return false;
53 }
54
55
56
57
58
59
60
61
62
63
64 @Override
65 public void runCheck() throws MojoExecutionException, MojoFailureException {
66 MavenEngine engine = null;
67 try {
68 engine = initializeEngine();
69 engine.update();
70 } catch (DatabaseException ex) {
71 if (getLog().isDebugEnabled()) {
72 getLog().debug("Database connection error", ex);
73 }
74 final String msg = "An exception occurred connecting to the local database. Please see the log file for more details.";
75 if (this.isFailOnError()) {
76 throw new MojoExecutionException(msg, ex);
77 }
78 getLog().error(msg);
79 } catch (UpdateException ex) {
80 final String msg = "An exception occurred while downloading updates. Please see the log file for more details.";
81 if (this.isFailOnError()) {
82 throw new MojoExecutionException(msg, ex);
83 }
84 getLog().error(msg);
85 }
86 if (engine != null) {
87 engine.cleanup();
88 }
89 Settings.cleanup();
90 }
91
92
93
94
95
96
97
98 @Override
99 public String getName(Locale locale) {
100 return "dependency-check-update";
101 }
102
103
104
105
106
107
108
109
110 @Override
111 public String getDescription(Locale locale) {
112 return "Updates the local cache of the NVD data from NIST.";
113 }
114 }