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.exception.ExceptionCollection;
30 import org.owasp.dependencycheck.utils.InvalidSettingException;
31 import org.owasp.dependencycheck.utils.Settings;
32
33
34
35
36
37
38 @Mojo(
39 name = "update-only",
40 requiresProject = false,
41 defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
42 threadSafe = true,
43 requiresDependencyResolution = ResolutionScope.NONE,
44 requiresOnline = true,
45 aggregator = true
46 )
47 public class UpdateMojo extends BaseDependencyCheckMojo {
48
49
50
51
52
53
54 @Override
55 public boolean canGenerateReport() {
56 return false;
57 }
58
59
60
61
62
63
64
65
66
67
68 @Override
69 protected void runCheck() throws MojoExecutionException, MojoFailureException {
70 try (Engine engine = initializeEngine()) {
71 try {
72 if (!engine.getSettings().getBoolean(Settings.KEYS.AUTO_UPDATE)) {
73 engine.getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, true);
74 }
75 } catch (InvalidSettingException ex) {
76 engine.getSettings().setBoolean(Settings.KEYS.AUTO_UPDATE, true);
77 }
78 engine.doUpdates();
79 } catch (DatabaseException ex) {
80 if (getLog().isDebugEnabled()) {
81 getLog().debug("Database connection error", ex);
82 }
83 final String msg = "An exception occurred connecting to the local database. Please see the log file for more details.";
84 if (this.isFailOnError()) {
85 throw new MojoExecutionException(msg, ex);
86 }
87 getLog().error(msg);
88 } catch (UpdateException ex) {
89 final String msg = "An exception occurred while downloading updates. Please see the log file for more details.";
90 if (this.isFailOnError()) {
91 throw new MojoExecutionException(msg, ex);
92 }
93 getLog().error(msg);
94 } finally {
95 getSettings().cleanup();
96 }
97 }
98
99
100
101
102
103
104
105 @Override
106 public String getName(Locale locale) {
107 return "dependency-check-update";
108 }
109
110
111
112
113
114
115
116
117 @Override
118 public String getDescription(Locale locale) {
119 return "Updates the local cache of the NVD data from NIST.";
120 }
121
122
123
124
125
126
127
128
129
130 @Override
131 protected ExceptionCollection scanDependencies(Engine engine) throws MojoExecutionException {
132 throw new UnsupportedOperationException("Operation not supported");
133 }
134
135
136
137
138
139
140
141
142
143
144 @Override
145 protected ExceptionCollection scanPlugins(final Engine engine, final ExceptionCollection exCollection) throws MojoExecutionException {
146 throw new UnsupportedOperationException("Operation not supported");
147 }
148 }