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.io.File;
21 import java.io.IOException;
22 import java.util.Locale;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.ResolutionScope;
28 import org.owasp.dependencycheck.utils.Settings;
29
30
31
32
33
34
35 @Mojo(
36 name = "purge",
37 defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
38 threadSafe = false,
39 requiresDependencyResolution = ResolutionScope.NONE,
40 requiresOnline = true
41 )
42 public class PurgeMojo extends BaseDependencyCheckMojo {
43
44
45
46
47
48
49 @Override
50 public boolean canGenerateReport() {
51 return false;
52 }
53
54
55
56
57
58
59
60 @Override
61 public void runCheck() throws MojoExecutionException, MojoFailureException {
62
63 if (getConnectionString() != null && !getConnectionString().isEmpty()) {
64 getLog().error("Unable to purge the local NVD when using a non-default connection string");
65 } else {
66 populateSettings();
67 File db;
68 try {
69 db = new File(Settings.getDataDirectory(), "dc.h2.db");
70 if (db.exists()) {
71 if (db.delete()) {
72 getLog().info("Database file purged; local copy of the NVD has been removed");
73 } else {
74 getLog().error(String.format("Unable to delete '%s'; please delete the file manually", db.getAbsolutePath()));
75 }
76 } else {
77 getLog().error(String.format("Unable to purge database; the database file does not exists: %s", db.getAbsolutePath()));
78 }
79 } catch (IOException ex) {
80 getLog().error("Unable to delete the database");
81 }
82 Settings.cleanup();
83 }
84 }
85
86
87
88
89
90
91
92 @Override
93 public String getName(Locale locale) {
94 return "dependency-check-purge";
95 }
96
97
98
99
100
101
102
103 @Override
104 public String getDescription(Locale locale) {
105 return "Purges the local cache of the NVD dataT.";
106 }
107
108 }