1 package org.codehaus.mojo.keytool;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.maven.plugin.MojoExecutionException;
20 import org.apache.maven.plugins.annotations.Mojo;
21 import org.apache.maven.plugins.annotations.Parameter;
22 import org.apache.maven.shared.utils.cli.Commandline;
23 import org.codehaus.mojo.keytool.requests.KeyToolImportKeystoreRequest;
24 import org.codehaus.plexus.util.StringUtils;
25
26 import java.io.File;
27
28
29
30
31
32
33
34
35
36
37
38
39
40 @Mojo(name = "importKeystore", requiresProject = true)
41 public class ImportKeystoreMojo
42 extends AbstractKeyToolRequestMojo<KeyToolImportKeystoreRequest>
43 {
44
45
46
47
48
49
50
51
52 @Parameter
53 private String srckeystore;
54
55
56
57
58
59
60
61
62 @Parameter
63 private String destkeystore;
64
65
66
67
68
69
70
71
72 @Parameter
73 private String srcstoretype;
74
75
76
77
78
79
80
81
82 @Parameter
83 private String deststoretype;
84
85
86
87
88
89
90
91
92 @Parameter
93 private String srcstorepass;
94
95
96
97
98
99
100
101
102 @Parameter
103 private String deststorepass;
104
105
106
107
108
109
110
111
112 @Parameter
113 private boolean srcprotected;
114
115
116
117
118
119
120
121
122 @Parameter
123 private String srcprovidername;
124
125
126
127
128
129
130
131
132 @Parameter
133 private String destprovidername;
134
135
136
137
138
139
140
141
142 @Parameter
143 private String srcalias;
144
145
146
147
148
149
150
151
152 @Parameter
153 private String destalias;
154
155
156
157
158
159
160
161
162 @Parameter
163 private String srckeypass;
164
165
166
167
168
169
170
171
172 @Parameter
173 private String destkeypass;
174
175
176
177
178
179
180
181
182 @Parameter
183 private boolean noprompt;
184
185
186
187
188
189
190
191
192 @Parameter
193 private String providerclass;
194
195
196
197
198
199
200
201
202 @Parameter
203 private String providerarg;
204
205
206
207
208
209
210
211
212 @Parameter
213 private String providerpath;
214
215
216
217
218
219
220 @Parameter
221 private boolean skipIfExist;
222
223
224
225
226 public ImportKeystoreMojo()
227 {
228 super( KeyToolImportKeystoreRequest.class );
229 }
230
231 @Override
232 public void execute()
233 throws MojoExecutionException
234 {
235
236 if ( skipIfExist )
237 {
238
239
240 File destinationKeystoreFile = new File( destkeystore );
241 boolean keystoreFileExists = destinationKeystoreFile.exists();
242
243 if ( keystoreFileExists )
244 {
245 getLog().info( "Skip execution, keystore already exists at " + destinationKeystoreFile );
246 setSkip( true );
247 }
248
249 }
250 super.execute();
251 }
252
253
254
255
256
257 @Override
258 protected KeyToolImportKeystoreRequest createKeytoolRequest()
259 {
260 KeyToolImportKeystoreRequest request = super.createKeytoolRequest();
261
262 request.setSrckeystore( this.srckeystore );
263 request.setDestkeystore( this.destkeystore );
264 request.setSrcstoretype( this.srcstoretype );
265 request.setDeststoretype( this.deststoretype );
266 request.setSrcstorepass( this.srcstorepass );
267 request.setDeststorepass( this.deststorepass );
268 request.setSrcprotected( this.srcprotected );
269 request.setSrcprovidername( this.srcprovidername );
270 request.setDestprovidername( this.destprovidername );
271 request.setSrcalias( this.srcalias );
272 request.setDestalias( this.destalias );
273 request.setSrckeypass( this.srckeypass );
274 request.setDestkeypass( this.destkeypass );
275 request.setNoprompt( this.noprompt );
276 request.setProviderclass( this.providerclass );
277 request.setProviderarg( this.providerarg );
278 request.setProviderpath( this.providerpath );
279 return request;
280 }
281
282
283
284
285 @Override
286 protected String getCommandlineInfo( Commandline commandLine )
287 {
288 String commandLineInfo = super.getCommandlineInfo( commandLine );
289
290 commandLineInfo = StringUtils.replace( commandLineInfo, this.srckeypass, "'*****'" );
291 commandLineInfo = StringUtils.replace( commandLineInfo, this.destkeypass, "'*****'" );
292 commandLineInfo = StringUtils.replace( commandLineInfo, this.srcstorepass, "'*****'" );
293 commandLineInfo = StringUtils.replace( commandLineInfo, this.deststorepass, "'*****'" );
294
295 return commandLineInfo;
296 }
297 }