1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.akquinet.innovation.play.maven;
17
18 import org.apache.commons.exec.CommandLine;
19 import org.apache.commons.exec.DefaultExecutor;
20 import org.apache.commons.exec.ExecuteWatchdog;
21 import org.apache.commons.io.FileUtils;
22 import org.apache.maven.plugin.MojoExecutionException;
23
24 import java.io.File;
25 import java.io.IOException;
26
27
28
29
30
31
32
33 public class Play2CleanMojo
34 extends AbstractPlay2Mojo {
35
36
37
38
39
40
41 private File lib;
42
43
44
45
46
47
48 private boolean cleanLibFolder = true;
49
50 public void execute()
51 throws MojoExecutionException {
52
53 String line = getPlay2().getAbsolutePath();
54
55 CommandLine cmdLine = CommandLine.parse(line);
56 cmdLine.addArgument("clean");
57 DefaultExecutor executor = new DefaultExecutor();
58
59 if (timeout > 0) {
60 ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
61 executor.setWatchdog(watchdog);
62 }
63
64 executor.setWorkingDirectory(project.getBasedir());
65 executor.setExitValue(0);
66 try {
67 executor.execute(cmdLine, getEnvironment());
68 } catch (IOException e) {
69 throw new MojoExecutionException("Error during cleanup", e);
70 }
71
72
73 File dist = new File(project.getBasedir(), "dist");
74 if (dist.exists()) {
75 getLog().debug("Deleting " + dist.getAbsolutePath());
76 try {
77 FileUtils.deleteDirectory(dist);
78 } catch (IOException e) {
79 throw new MojoExecutionException("Can't delete the dist folder", e);
80 }
81 } else {
82 getLog().debug("'dist' directory not found");
83 }
84
85
86 File logs = new File(project.getBasedir(), "logs");
87 if (logs.exists()) {
88 getLog().debug("Deleting " + logs.getAbsolutePath());
89 try {
90 FileUtils.deleteDirectory(logs);
91 } catch (IOException e) {
92 throw new MojoExecutionException("Can't delete the logs folder", e);
93 }
94 } else {
95 getLog().debug("'logs' directory not found");
96 }
97
98
99 if (cleanLibFolder) {
100 File lib = new File(project.getBasedir(), "lib");
101 if (lib.exists()) {
102 getLog().debug("Deleting " + lib.getAbsolutePath());
103 try {
104 FileUtils.deleteDirectory(lib);
105 } catch (IOException e) {
106 throw new MojoExecutionException("Can't delete the " + lib + " folder", e);
107 }
108 } else {
109 getLog().debug("'" + lib + "' directory not found");
110 }
111 }
112 }
113 }