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.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.project.MavenProject;
29
30
31
32
33
34
35
36 @Mojo( name = "clean" )
37 public class AntCleanMojo
38 extends AbstractMojo
39 {
40
41
42
43
44
45
46
47
48
49
50
51 @Parameter( defaultValue = "${project}", readonly = true, required = true )
52 private MavenProject project;
53
54
55
56
57
58
59 @Parameter( property = "deleteCustomFiles", defaultValue = "false" )
60 private boolean deleteCustomFiles;
61
62
63
64
65 public void execute()
66 throws MojoExecutionException
67 {
68 File buildXml = new File( project.getBasedir(), AntBuildWriter.DEFAULT_BUILD_FILENAME );
69 if ( buildXml.exists() )
70 {
71 if ( deleteCustomFiles )
72 {
73 if ( !buildXml.delete() )
74 {
75 throw new MojoExecutionException( "Cannot delete " + buildXml.getAbsolutePath() );
76 }
77 }
78 else if ( getLog().isInfoEnabled() )
79 {
80 getLog().info( "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 = new File( project.getBasedir(), AntBuildWriter.DEFAULT_MAVEN_PROPERTIES_FILENAME );
92 if ( mavenBuildProperties.exists() && !mavenBuildProperties.delete() )
93 {
94 throw new MojoExecutionException( "Cannot delete " + mavenBuildProperties.getAbsolutePath() );
95 }
96
97 getLog().info( "Deleted Ant build files for project " + project.getArtifactId() + " in "
98 + project.getBasedir().getAbsolutePath() );
99 }
100
101 }