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
102
103 private EclipseConfigFile[] additionalConfig;
104
105
106
107
108 public void execute()
109 throws MojoExecutionException
110 {
111 if ( skip )
112 {
113 return;
114 }
115
116 if ( Constants.PROJECT_PACKAGING_POM.equals( this.packaging ) )
117 {
118 return;
119 }
120
121 delete( new File( basedir, FILE_DOT_PROJECT ) );
122 delete( new File( basedir, FILE_DOT_CLASSPATH ) );
123 delete( new File( basedir, FILE_DOT_WTPMODULES ) );
124
125 delete( new File( basedir, FILE_DOT_COMPONENT ) );
126 delete( new File( basedir, FILE_DOT_COMPONENT_15 ) );
127 delete( new File( basedir, FILE_FACET_CORE_XML ) );
128 delete( new File( basedir, FILE_ECLIPSE_JDT_CORE_PREFS ) );
129
130 File settingsDir = new File( basedir, DIR_DOT_SETTINGS );
131 if ( settingsDir.exists() && settingsDir.isDirectory() && settingsDir.list().length == 0 )
132 {
133 delete( settingsDir );
134 }
135
136 if ( additionalConfig != null )
137 {
138 for ( int i = 0; i < additionalConfig.length; i++ )
139 {
140 delete( new File( basedir, additionalConfig[i].getName() ) );
141 }
142 }
143
144 cleanExtras();
145 }
146
147 protected void cleanExtras()
148 throws MojoExecutionException
149 {
150
151 }
152
153
154
155
156
157
158
159 protected void delete( File f )
160 throws MojoExecutionException
161 {
162 if ( f.isDirectory() )
163 {
164 getLog().info( Messages.getString( "EclipseCleanMojo.deletingDirectory", f.getName() ) );
165 }
166 else
167 {
168 getLog().info( Messages.getString( "EclipseCleanMojo.deletingFile", f.getName() ) );
169 }
170
171 if ( f.exists() )
172 {
173 if ( !f.delete() )
174 {
175 try
176 {
177 FileUtils.forceDelete( f );
178 }
179 catch ( IOException e )
180 {
181 throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.failedtodelete",
182 new Object[] { f.getName(),
183 f.getAbsolutePath() } ) );
184 }
185 }
186 }
187 else
188 {
189 getLog().debug( Messages.getString( "EclipseCleanMojo.nofilefound", f.getName() ) );
190 }
191 }
192
193
194
195
196
197
198 public File getBasedir()
199 {
200 return this.basedir;
201 }
202
203
204
205
206
207
208 public void setBasedir( File basedir )
209 {
210 this.basedir = basedir;
211 }
212
213
214
215
216 public String getPackaging()
217 {
218 return this.packaging;
219 }
220
221
222
223
224 public void setPackaging( String packaging )
225 {
226 this.packaging = packaging;
227 }
228
229 }