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
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.ide.IdeUtils;
25 import org.apache.maven.plugin.ide.JeeUtils;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.util.FileUtils;
28
29
30
31
32
33
34
35 public class RadCleanMojo
36 extends EclipseCleanMojo
37 {
38
39
40
41
42
43
44
45 private MavenProject project;
46
47 protected void cleanExtras()
48 throws MojoExecutionException
49 {
50 delete( new File( getBasedir(), ".j2ee" ) );
51 delete( new File( getBasedir(), ".websettings" ) );
52 delete( new File( getBasedir(), ".website-config" ) );
53
54 handleLibs();
55 }
56
57
58
59
60
61
62 public MavenProject getProject()
63 {
64 return this.project;
65 }
66
67
68
69
70
71
72 public void setProject( MavenProject project )
73 {
74 this.project = project;
75 }
76
77
78
79
80
81
82 private void handleEarLibs()
83 throws MojoExecutionException
84 {
85 File targetDir = this.project.getBasedir();
86 deleteJarArtifactsInDirectory( targetDir );
87 }
88
89
90
91
92
93
94 private void handleLibs()
95 throws MojoExecutionException
96 {
97
98 if ( Constants.PROJECT_PACKAGING_EAR.equals( getPackaging() ) )
99 {
100 handleEarLibs();
101 }
102 else if ( Constants.PROJECT_PACKAGING_WAR.equals( getPackaging() ) )
103 {
104 handleWarLibs();
105 }
106 }
107
108
109
110
111
112
113 private void handleWarLibs()
114 throws MojoExecutionException
115 {
116 File basedir = this.project.getBasedir();
117
118 File warSourceDirectory =
119 new File( IdeUtils.getPluginSetting( this.project, JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
120 "warSourceDirectory",
121 "src/main/webapp" ) );
122
123 String webContentDir = IdeUtils.toRelativeAndFixSeparator( basedir, warSourceDirectory, false );
124
125 String srcMainWebappWebInfLibDirname =
126 basedir.getAbsolutePath() + File.separatorChar + webContentDir + File.separatorChar + "WEB-INF" +
127 File.separatorChar + "lib";
128
129 File srcMainWebappWebInfLibDir = new File( srcMainWebappWebInfLibDirname );
130 srcMainWebappWebInfLibDir.mkdirs();
131
132 deleteJarArtifactsInDirectory( srcMainWebappWebInfLibDir );
133 }
134
135
136
137
138
139
140
141 protected void deleteJarArtifactsInDirectory( File directory )
142 throws MojoExecutionException
143 {
144 String[] oldFiles =
145 FileUtils.getFilesFromExtension( directory.getAbsolutePath(),
146 new String[] { Constants.PROJECT_PACKAGING_JAR } );
147 for ( int index = 0; index < oldFiles.length; index++ )
148 {
149 File f = new File( oldFiles[index] );
150
151 delete( f );
152 }
153 }
154 }