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