1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.codehaus.plexus.util.FileUtils;
27
28
29
30
31
32
33 public class EclipseCleanMojo
34 extends AbstractMojo
35 {
36
37
38
39
40 private static final String FILE_DOT_WTPMODULES = ".wtpmodules";
41
42
43
44
45 private static final String FILE_DOT_CLASSPATH = ".classpath";
46
47
48
49
50 private static final String FILE_DOT_PROJECT = ".project";
51
52
53
54
55 private static final String DIR_DOT_SETTINGS = ".settings";
56
57
58
59
60 private static final String FILE_DOT_COMPONENT = ".settings/.component";
61
62
63
64
65 private static final String FILE_DOT_COMPONENT_15 = ".settings/org.eclipse.wst.common.component";
66
67
68
69
70 private static final String FILE_FACET_CORE_XML = ".settings/org.eclipse.wst.common.project.facet.core.xml";
71
72
73
74
75 private static final String FILE_ECLIPSE_JDT_CORE_PREFS = ".settings/org.eclipse.jdt.core.prefs";
76
77
78
79
80
81
82 private String packaging;
83
84
85
86
87
88
89 private File basedir;
90
91
92
93
94
95
96 private boolean skip;
97
98
99
100
101 public void execute()
102 throws MojoExecutionException
103 {
104 if ( skip )
105 {
106 return;
107 }
108
109 if ( Constants.PROJECT_PACKAGING_POM.equals( this.packaging ) )
110 {
111 return;
112 }
113
114 delete( new File( basedir, FILE_DOT_PROJECT ) );
115 delete( new File( basedir, FILE_DOT_CLASSPATH ) );
116 delete( new File( basedir, FILE_DOT_WTPMODULES ) );
117
118 delete( new File( basedir, FILE_DOT_COMPONENT ) );
119 delete( new File( basedir, FILE_DOT_COMPONENT_15 ) );
120 delete( new File( basedir, FILE_FACET_CORE_XML ) );
121 delete( new File( basedir, FILE_ECLIPSE_JDT_CORE_PREFS ) );
122
123 File settingsDir = new File( basedir, DIR_DOT_SETTINGS );
124 if ( settingsDir.exists() && settingsDir.isDirectory() && settingsDir.list().length == 0 )
125 {
126 delete( settingsDir );
127 }
128
129 cleanExtras();
130 }
131
132 protected void cleanExtras()
133 throws MojoExecutionException
134 {
135
136 }
137
138
139
140
141
142
143
144 protected void delete( File f )
145 throws MojoExecutionException
146 {
147 if ( f.isDirectory() )
148 {
149 getLog().info( Messages.getString( "EclipseCleanMojo.deletingDirectory", f.getName() ) );
150 }
151 else
152 {
153 getLog().info( Messages.getString( "EclipseCleanMojo.deletingFile", f.getName() ) );
154 }
155
156 if ( f.exists() )
157 {
158 if ( !f.delete() )
159 {
160 try
161 {
162 FileUtils.forceDelete( f );
163 }
164 catch ( IOException e )
165 {
166 throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.failedtodelete",
167 new Object[] { f.getName(),
168 f.getAbsolutePath() } ) );
169 }
170 }
171 }
172 else
173 {
174 getLog().debug( Messages.getString( "EclipseCleanMojo.nofilefound", f.getName() ) );
175 }
176 }
177
178
179
180
181
182
183 public File getBasedir()
184 {
185 return this.basedir;
186 }
187
188
189
190
191
192
193 public void setBasedir( File basedir )
194 {
195 this.basedir = basedir;
196 }
197
198
199
200
201 public String getPackaging()
202 {
203 return this.packaging;
204 }
205
206
207
208
209 public void setPackaging( String packaging )
210 {
211 this.packaging = packaging;
212 }
213
214 }