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.plugins.annotations.Parameter;
20 import org.apache.maven.shared.utils.cli.Commandline;
21 import org.codehaus.plexus.util.StringUtils;
22
23 import java.io.File;
24 import java.net.MalformedURLException;
25
26
27
28
29
30
31
32
33 public abstract class AbstractKeyToolRequestWithKeyStoreParametersMojo<R extends KeyToolRequestWithKeyStoreParameters>
34 extends AbstractKeyToolRequestMojo<R>
35 {
36
37
38
39
40
41
42 @Parameter
43 private String keystore;
44
45
46
47
48
49
50 @Parameter
51 private String storetype;
52
53
54
55
56
57
58 @Parameter( alias = "storepass" )
59 private String storepass;
60
61
62
63
64
65
66
67
68 @Parameter
69 private String providername;
70
71
72
73
74
75
76
77
78 @Parameter
79 private String providerclass;
80
81
82
83
84
85
86
87
88 @Parameter
89 private String providerarg;
90
91
92
93
94
95
96
97
98 @Parameter
99 private String providerpath;
100
101
102
103
104
105
106 public AbstractKeyToolRequestWithKeyStoreParametersMojo( Class<R> requestType )
107 {
108 super( requestType );
109 }
110
111
112
113
114 @Override
115 protected R createKeytoolRequest()
116 {
117 R request = super.createKeytoolRequest();
118
119 if ( StringUtils.isNotEmpty( keystore ) )
120 {
121
122 File file = getFile( keystore );
123
124
125
126 boolean mkdirs = file.getParentFile().mkdirs();
127 getLog().debug( "mdkirs: " + mkdirs + " " + file.getParentFile() );
128
129
130 request.setKeystore( file.getAbsolutePath() );
131 }
132
133 request.setProviderarg( providerarg );
134 request.setProviderclass( providerclass );
135 request.setProvidername( providername );
136 request.setProviderpath( providerpath );
137 request.setStorepass( storepass );
138 request.setStoretype( storetype );
139 return request;
140 }
141
142
143
144
145 @Override
146 protected String getCommandlineInfo( final Commandline commandLine )
147 {
148 String commandLineInfo = super.getCommandlineInfo( commandLine );
149
150 commandLineInfo = StringUtils.replace( commandLineInfo, this.storepass, "'*****'" );
151
152 return commandLineInfo;
153 }
154
155
156
157
158
159
160 protected final void createParentDirIfNecessary( final String file )
161 {
162 if ( file != null )
163 {
164 final File fileDir = new File( file ).getParentFile();
165
166 if ( fileDir != null )
167 {
168
169 boolean mkdirs = fileDir.mkdirs();
170 getLog().debug( "mdkirs: " + mkdirs + " " + fileDir );
171 }
172 }
173 }
174
175 protected File getFile( String path )
176
177 {
178 try
179 {
180 return new File( new File( path ).toURL().getFile() );
181 }
182 catch ( MalformedURLException e )
183 {
184 throw new IllegalStateException( "Could not obtain directory " + path );
185 }
186 }
187
188 protected File getKeystoreFile()
189 {
190 return getFile(keystore);
191 }
192 }