1 package org.apache.maven.plugin.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.project.MavenProject;
27
28
29
30
31
32
33
34
35 public class AntCleanMojo
36 extends AbstractMojo
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 private MavenProject project;
54
55
56
57
58
59
60
61 private boolean deleteCustomFiles;
62
63
64 public void execute()
65 throws MojoExecutionException
66 {
67 File buildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_BUILD_FILENAME );
68 if ( buildXml.exists() )
69 {
70 if ( deleteCustomFiles )
71 {
72 if ( !buildXml.delete() )
73 {
74 throw new MojoExecutionException( "Cannot delete " + buildXml.getAbsolutePath() );
75 }
76 }
77 else if ( getLog().isInfoEnabled() )
78 {
79 getLog().info(
80 "Not deleting custom " + buildXml.getName()
81 + ", use -DdeleteCustomFiles=true to force its deletion" );
82 }
83 }
84
85 File mavenBuildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_BUILD_FILENAME );
86 if ( mavenBuildXml.exists() && !mavenBuildXml.delete() )
87 {
88 throw new MojoExecutionException( "Cannot delete " + mavenBuildXml.getAbsolutePath() );
89 }
90
91 File mavenBuildProperties =
92 new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_PROPERTIES_FILENAME );
93 if ( mavenBuildProperties.exists() && !mavenBuildProperties.delete() )
94 {
95 throw new MojoExecutionException( "Cannot delete " + mavenBuildProperties.getAbsolutePath() );
96 }
97
98 getLog().info(
99 "Deleted Ant build files for project " + project.getArtifactId() + " in "
100 + project.getBasedir().getAbsolutePath() );
101 }
102
103 }