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.artifact.Artifact;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.apache.maven.plugins.annotations.LifecyclePhase;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.plugins.annotations.ResolutionScope;
28 import org.owasp.dependencycheck.Engine;
29 import org.owasp.dependencycheck.exception.ExceptionCollection;
30 import org.owasp.dependencycheck.utils.scarf.TelemetryCollector;
31
32
33
34
35
36
37
38 @Mojo(
39 name = "check",
40 defaultPhase = LifecyclePhase.VERIFY,
41 threadSafe = true,
42 requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
43 requiresOnline = true
44 )
45 public class CheckMojo extends BaseDependencyCheckMojo {
46
47
48
49
50 @SuppressWarnings("CanBeFinal")
51 @Parameter(property = "name", defaultValue = "dependency-check", required = true)
52 private String name = "dependency-check";
53
54
55
56
57
58
59
60 @Override
61 public boolean canGenerateReport() {
62 try {
63 populateSettings();
64 } catch (MojoFailureException | MojoExecutionException e) {
65 return false;
66 }
67 boolean isCapable = false;
68 for (Artifact a : getProject().getArtifacts()) {
69 if (!getArtifactScopeExcluded().passes(a.getScope())) {
70 isCapable = true;
71 break;
72 }
73 }
74 return isCapable;
75 }
76
77
78
79
80
81
82
83 @Override
84 public String getName(Locale locale) {
85 return name;
86 }
87
88
89
90
91
92
93
94
95 @Override
96 public String getDescription(Locale locale) {
97 return "Generates a report providing details on any published vulnerabilities within project dependencies. "
98 + "This report is a best effort and may contain false positives and false negatives.";
99 }
100
101
102
103
104
105
106
107
108 @Override
109 protected ExceptionCollection scanDependencies(final Engine engine) throws MojoExecutionException {
110 TelemetryCollector.send(getSettings());
111 return scanArtifacts(getProject(), engine);
112 }
113
114
115
116
117
118
119
120
121
122
123 @Override
124 protected ExceptionCollection scanPlugins(final Engine engine, final ExceptionCollection exCollection) throws MojoExecutionException {
125 final ExceptionCollection exCol = scanPlugins(getProject(), engine, exCollection);
126 return exCol;
127 }
128
129 }