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.KeyToolImportCertificateRequest;
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
41 @Mojo(name = "importCertificate", requiresProject = true)
42 public class ImportCertificateMojo
43 extends AbstractKeyToolRequestWithKeyStoreAndAliasParametersMojo<KeyToolImportCertificateRequest>
44 {
45
46
47
48
49
50
51
52
53 @Parameter
54 private String keypass;
55
56
57
58
59
60
61
62
63 @Parameter
64 private String file;
65
66
67
68
69
70
71
72
73 @Parameter
74 private boolean noprompt;
75
76
77
78
79
80
81
82
83 @Parameter
84 private boolean trustcacerts;
85
86
87
88
89
90
91 @Parameter
92 private boolean skipIfExist;
93
94
95
96
97 public ImportCertificateMojo()
98 {
99 super( KeyToolImportCertificateRequest.class );
100 }
101
102 @Override
103 public void execute()
104 throws MojoExecutionException
105 {
106
107 if ( skipIfExist )
108 {
109
110
111 File keystoreFile = getKeystoreFile();
112 boolean keystoreFileExists = keystoreFile.exists();
113
114 if ( keystoreFileExists )
115 {
116 getLog().info( "Skip execution, keystore already exists at " + keystoreFile );
117 setSkip( true );
118 }
119
120 }
121 super.execute();
122 }
123
124
125
126
127 @Override
128 protected KeyToolImportCertificateRequest createKeytoolRequest()
129 {
130 KeyToolImportCertificateRequest request = super.createKeytoolRequest();
131
132 request.setKeypass( this.keypass );
133 request.setFile( this.file );
134 request.setNoprompt( this.noprompt );
135 request.setTrustcacerts( this.trustcacerts );
136 return request;
137 }
138
139
140
141
142 @Override
143 protected String getCommandlineInfo( Commandline commandLine )
144 {
145 String commandLineInfo = super.getCommandlineInfo( commandLine );
146
147 commandLineInfo = StringUtils.replace( commandLineInfo, this.keypass, "'*****'" );
148
149 return commandLineInfo;
150 }
151 }