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.ResolutionScope;
27 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
28 import org.owasp.dependencycheck.utils.Settings;
29
30
31
32
33
34
35 @Mojo(
36 name = "check",
37 defaultPhase = LifecyclePhase.COMPILE,
38 threadSafe = true,
39 requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
40 requiresOnline = true
41 )
42 public class CheckMojo extends BaseDependencyCheckMojo {
43
44
45
46
47
48
49 @Override
50 public boolean canGenerateReport() {
51 boolean isCapable = false;
52 for (Artifact a : getProject().getArtifacts()) {
53 if (!excludeFromScan(a)) {
54 isCapable = true;
55 break;
56 }
57 }
58 return isCapable;
59 }
60
61
62
63
64
65
66
67 @Override
68 public void runCheck() throws MojoExecutionException, MojoFailureException {
69 final Engine engine;
70 try {
71 engine = initializeEngine();
72 } catch (DatabaseException ex) {
73 if (getLog().isDebugEnabled()) {
74 getLog().debug("Database connection error", ex);
75 }
76 throw new MojoExecutionException("An exception occured connecting to the local database. Please see the log file for more details.", ex);
77 }
78 scanArtifacts(getProject(), engine);
79 if (engine.getDependencies().isEmpty()) {
80 getLog().info("No dependencies were identified that could be analyzed by dependency-check");
81 } else {
82 engine.analyzeDependencies();
83 writeReports(engine, getProject(), getCorrectOutputDirectory());
84 writeDataFile(getProject(), null, engine.getDependencies());
85 showSummary(getProject(), engine.getDependencies());
86 checkForFailure(engine.getDependencies());
87 }
88 engine.cleanup();
89 Settings.cleanup();
90 }
91
92
93
94
95
96
97
98 public String getName(Locale locale) {
99 return "dependency-check";
100 }
101
102
103
104
105
106
107
108 public String getDescription(Locale locale) {
109 return "Generates a report providing details on any published vulnerabilities within project dependencies. "
110 + "This report is a best effort and may contain false positives and false negatives.";
111 }
112
113 }