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.exception.ExceptionCollection;
28 import org.owasp.dependencycheck.utils.Downloader;
29 import org.owasp.dependencycheck.utils.InvalidSettingException;
30
31
32
33
34
35
36 @Mojo(
37 name = "purge",
38 defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
39 requiresProject = false,
40 threadSafe = true,
41 requiresDependencyResolution = ResolutionScope.NONE,
42 requiresOnline = true,
43 aggregator = true
44 )
45 public class PurgeMojo extends BaseDependencyCheckMojo {
46
47
48
49
50
51
52 @Override
53 public boolean canGenerateReport() {
54 return false;
55 }
56
57
58
59
60
61
62
63
64
65 @Override
66 protected void runCheck() throws MojoExecutionException, MojoFailureException {
67 populateSettings();
68 try {
69 Downloader.getInstance().configure(getSettings());
70 } catch (InvalidSettingException e) {
71 if (isFailOnError()) {
72 throw new MojoFailureException(e.getMessage(), e);
73 } else {
74 throw new MojoExecutionException(e.getMessage(), e);
75 }
76 }
77 try (Engine engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING, getSettings())) {
78 engine.purge();
79 } finally {
80 getSettings().cleanup();
81 }
82 }
83
84
85
86
87
88
89
90 @Override
91 public String getName(Locale locale) {
92 return "dependency-check-purge";
93 }
94
95
96
97
98
99
100
101
102 @Override
103 public String getDescription(Locale locale) {
104 return "Purges the local cache of the NVD dataT.";
105 }
106
107
108
109
110
111
112
113
114 @Override
115 protected ExceptionCollection scanDependencies(Engine engine) throws MojoExecutionException {
116 throw new UnsupportedOperationException("Operation not supported");
117 }
118
119
120
121
122
123
124
125
126
127
128 @Override
129 protected ExceptionCollection scanPlugins(final Engine engine, final ExceptionCollection exCollection) throws MojoExecutionException {
130 throw new UnsupportedOperationException("Operation not supported");
131 }
132 }