1
- package org .apache .maven .plugins .gpg ;
2
-
3
1
/*
4
2
* Licensed to the Apache Software Foundation (ASF) under one
5
3
* or more contributor license agreements. See the NOTICE file
9
7
* "License"); you may not use this file except in compliance
10
8
* with the License. You may obtain a copy of the License at
11
9
*
12
- * http://www.apache.org/licenses/LICENSE-2.0
10
+ * http://www.apache.org/licenses/LICENSE-2.0
13
11
*
14
12
* Unless required by applicable law or agreed to in writing,
15
13
* software distributed under the License is distributed on an
18
16
* specific language governing permissions and limitations
19
17
* under the License.
20
18
*/
19
+ package org .apache .maven .plugins .gpg ;
21
20
22
21
import java .io .File ;
23
22
import java .io .IOException ;
38
37
/**
39
38
* @author Benjamin Bentmann
40
39
*/
41
- public abstract class AbstractGpgMojo
42
- extends AbstractMojo
43
- {
40
+ public abstract class AbstractGpgMojo extends AbstractMojo {
44
41
45
42
/**
46
43
* The directory from which gpg will load keyrings. If not specified, gpg will use the value configured for its
47
44
* installation, e.g. <code>~/.gnupg</code> or <code>%APPDATA%/gnupg</code>.
48
45
*
49
46
* @since 1.0
50
47
*/
51
- @ Parameter ( property = "gpg.homedir" )
48
+ @ Parameter (property = "gpg.homedir" )
52
49
private File homedir ;
53
50
54
51
/**
55
52
* The passphrase to use when signing. If not given, look up the value under Maven
56
53
* settings using server id at 'passphraseServerKey' configuration.
57
54
**/
58
- @ Parameter ( property = "gpg.passphrase" )
55
+ @ Parameter (property = "gpg.passphrase" )
59
56
private String passphrase ;
60
57
61
58
/**
62
59
* Server id to lookup the passphrase under Maven settings.
63
60
* @since 1.6
64
61
*/
65
- @ Parameter ( property = "gpg.passphraseServerId" , defaultValue = "gpg.passphrase" )
62
+ @ Parameter (property = "gpg.passphraseServerId" , defaultValue = "gpg.passphrase" )
66
63
private String passphraseServerId ;
67
64
68
65
/**
69
66
* The "name" of the key to sign with. Passed to gpg as <code>--local-user</code>.
70
67
*/
71
- @ Parameter ( property = "gpg.keyname" )
68
+ @ Parameter (property = "gpg.keyname" )
72
69
private String keyname ;
73
70
74
71
/**
75
72
* Passes <code>--use-agent</code> or <code>--no-use-agent</code> to gpg. If using an agent, the passphrase is
76
73
* optional as the agent will provide it. For gpg2, specify true as --no-use-agent was removed in gpg2 and doesn't
77
74
* ask for a passphrase anymore.
78
75
*/
79
- @ Parameter ( property = "gpg.useagent" , defaultValue = "true" )
76
+ @ Parameter (property = "gpg.useagent" , defaultValue = "true" )
80
77
private boolean useAgent ;
81
78
82
79
/**
83
80
*/
84
- @ Parameter ( defaultValue = "${settings.interactiveMode}" , readonly = true )
81
+ @ Parameter (defaultValue = "${settings.interactiveMode}" , readonly = true )
85
82
private boolean interactive ;
86
83
87
84
/**
@@ -90,15 +87,15 @@ public abstract class AbstractGpgMojo
90
87
*
91
88
* @since 1.1
92
89
*/
93
- @ Parameter ( property = "gpg.executable" )
90
+ @ Parameter (property = "gpg.executable" )
94
91
private String executable ;
95
92
96
93
/**
97
94
* Whether to add the default keyrings from gpg's home directory to the list of used keyrings.
98
95
*
99
96
* @since 1.2
100
97
*/
101
- @ Parameter ( property = "gpg.defaultKeyring" , defaultValue = "true" )
98
+ @ Parameter (property = "gpg.defaultKeyring" , defaultValue = "true" )
102
99
private boolean defaultKeyring ;
103
100
104
101
/**
@@ -111,7 +108,7 @@ public abstract class AbstractGpgMojo
111
108
*
112
109
* @since 1.2
113
110
*/
114
- @ Parameter ( property = "gpg.secretKeyring" )
111
+ @ Parameter (property = "gpg.secretKeyring" )
115
112
private String secretKeyring ;
116
113
117
114
/**
@@ -121,7 +118,7 @@ public abstract class AbstractGpgMojo
121
118
*
122
119
* @since 1.2
123
120
*/
124
- @ Parameter ( property = "gpg.publicKeyring" )
121
+ @ Parameter (property = "gpg.publicKeyring" )
125
122
private String publicKeyring ;
126
123
127
124
/**
@@ -133,7 +130,7 @@ public abstract class AbstractGpgMojo
133
130
* --lock-options</a>
134
131
* @since 1.5
135
132
*/
136
- @ Parameter ( property = "gpg.lockMode" )
133
+ @ Parameter (property = "gpg.lockMode" )
137
134
private String lockMode ;
138
135
139
136
/**
@@ -156,49 +153,42 @@ public abstract class AbstractGpgMojo
156
153
*
157
154
* @since 1.6
158
155
*/
159
- @ Parameter ( defaultValue = "${settings}" , readonly = true )
156
+ @ Parameter (defaultValue = "${settings}" , readonly = true )
160
157
private Settings settings ;
161
158
162
159
/**
163
160
* Maven Security Dispatcher
164
161
*
165
162
* @since 1.6
166
163
*/
167
- @ Component ( hint = "mng-4384" )
164
+ @ Component (hint = "mng-4384" )
168
165
private SecDispatcher securityDispatcher ;
169
166
170
- AbstractGpgSigner newSigner ( MavenProject project )
171
- throws MojoExecutionException , MojoFailureException
172
- {
173
- AbstractGpgSigner signer = new GpgSigner ( executable );
174
-
175
- signer .setLog ( getLog () );
176
- signer .setInteractive ( interactive );
177
- signer .setKeyName ( keyname );
178
- signer .setUseAgent ( useAgent );
179
- signer .setHomeDirectory ( homedir );
180
- signer .setDefaultKeyring ( defaultKeyring );
181
- signer .setSecretKeyring ( secretKeyring );
182
- signer .setPublicKeyring ( publicKeyring );
183
- signer .setLockMode ( lockMode );
184
- signer .setArgs ( gpgArguments );
167
+ AbstractGpgSigner newSigner (MavenProject project ) throws MojoExecutionException , MojoFailureException {
168
+ AbstractGpgSigner signer = new GpgSigner (executable );
169
+
170
+ signer .setLog (getLog ());
171
+ signer .setInteractive (interactive );
172
+ signer .setKeyName (keyname );
173
+ signer .setUseAgent (useAgent );
174
+ signer .setHomeDirectory (homedir );
175
+ signer .setDefaultKeyring (defaultKeyring );
176
+ signer .setSecretKeyring (secretKeyring );
177
+ signer .setPublicKeyring (publicKeyring );
178
+ signer .setLockMode (lockMode );
179
+ signer .setArgs (gpgArguments );
185
180
186
181
loadGpgPassphrase ();
187
182
188
- signer .setPassPhrase ( passphrase );
189
- if ( null == passphrase && !useAgent )
190
- {
191
- if ( !interactive )
192
- {
193
- throw new MojoFailureException ( "Cannot obtain passphrase in batch mode" );
194
- }
195
- try
196
- {
197
- signer .setPassPhrase ( signer .getPassphrase ( project ) );
183
+ signer .setPassPhrase (passphrase );
184
+ if (null == passphrase && !useAgent ) {
185
+ if (!interactive ) {
186
+ throw new MojoFailureException ("Cannot obtain passphrase in batch mode" );
198
187
}
199
- catch ( IOException e )
200
- {
201
- throw new MojoExecutionException ( "Exception reading passphrase" , e );
188
+ try {
189
+ signer .setPassPhrase (signer .getPassphrase (project ));
190
+ } catch (IOException e ) {
191
+ throw new MojoExecutionException ("Exception reading passphrase" , e );
202
192
}
203
193
}
204
194
@@ -210,24 +200,16 @@ AbstractGpgSigner newSigner( MavenProject project )
210
200
*
211
201
* @throws MojoFailureException
212
202
*/
213
- private void loadGpgPassphrase ()
214
- throws MojoFailureException
215
- {
216
- if ( StringUtils .isEmpty ( this .passphrase ) )
217
- {
218
- Server server = this .settings .getServer ( passphraseServerId );
219
-
220
- if ( server != null )
221
- {
222
- if ( server .getPassphrase () != null )
223
- {
224
- try
225
- {
226
- this .passphrase = securityDispatcher .decrypt ( server .getPassphrase () );
227
- }
228
- catch ( SecDispatcherException e )
229
- {
230
- throw new MojoFailureException ( "Unable to decrypt gpg passphrase" , e );
203
+ private void loadGpgPassphrase () throws MojoFailureException {
204
+ if (StringUtils .isEmpty (this .passphrase )) {
205
+ Server server = this .settings .getServer (passphraseServerId );
206
+
207
+ if (server != null ) {
208
+ if (server .getPassphrase () != null ) {
209
+ try {
210
+ this .passphrase = securityDispatcher .decrypt (server .getPassphrase ());
211
+ } catch (SecDispatcherException e ) {
212
+ throw new MojoFailureException ("Unable to decrypt gpg passphrase" , e );
231
213
}
232
214
}
233
215
}
0 commit comments