1- package org .apache .maven .plugins .gpg ;
2-
31/*
42 * Licensed to the Apache Software Foundation (ASF) under one
53 * or more contributor license agreements. See the NOTICE file
97 * "License"); you may not use this file except in compliance
108 * with the License. You may obtain a copy of the License at
119 *
12- * http://www.apache.org/licenses/LICENSE-2.0
10+ * http://www.apache.org/licenses/LICENSE-2.0
1311 *
1412 * Unless required by applicable law or agreed to in writing,
1513 * software distributed under the License is distributed on an
1816 * specific language governing permissions and limitations
1917 * under the License.
2018 */
19+ package org .apache .maven .plugins .gpg ;
2120
2221import java .io .File ;
2322import java .io .IOException ;
3837/**
3938 * @author Benjamin Bentmann
4039 */
41- public abstract class AbstractGpgMojo
42- extends AbstractMojo
43- {
40+ public abstract class AbstractGpgMojo extends AbstractMojo {
4441
4542 /**
4643 * The directory from which gpg will load keyrings. If not specified, gpg will use the value configured for its
4744 * installation, e.g. <code>~/.gnupg</code> or <code>%APPDATA%/gnupg</code>.
4845 *
4946 * @since 1.0
5047 */
51- @ Parameter ( property = "gpg.homedir" )
48+ @ Parameter (property = "gpg.homedir" )
5249 private File homedir ;
5350
5451 /**
5552 * The passphrase to use when signing. If not given, look up the value under Maven
5653 * settings using server id at 'passphraseServerKey' configuration.
5754 **/
58- @ Parameter ( property = "gpg.passphrase" )
55+ @ Parameter (property = "gpg.passphrase" )
5956 private String passphrase ;
6057
6158 /**
6259 * Server id to lookup the passphrase under Maven settings.
6360 * @since 1.6
6461 */
65- @ Parameter ( property = "gpg.passphraseServerId" , defaultValue = "gpg.passphrase" )
62+ @ Parameter (property = "gpg.passphraseServerId" , defaultValue = "gpg.passphrase" )
6663 private String passphraseServerId ;
6764
6865 /**
6966 * The "name" of the key to sign with. Passed to gpg as <code>--local-user</code>.
7067 */
71- @ Parameter ( property = "gpg.keyname" )
68+ @ Parameter (property = "gpg.keyname" )
7269 private String keyname ;
7370
7471 /**
7572 * Passes <code>--use-agent</code> or <code>--no-use-agent</code> to gpg. If using an agent, the passphrase is
7673 * optional as the agent will provide it. For gpg2, specify true as --no-use-agent was removed in gpg2 and doesn't
7774 * ask for a passphrase anymore.
7875 */
79- @ Parameter ( property = "gpg.useagent" , defaultValue = "true" )
76+ @ Parameter (property = "gpg.useagent" , defaultValue = "true" )
8077 private boolean useAgent ;
8178
8279 /**
8380 */
84- @ Parameter ( defaultValue = "${settings.interactiveMode}" , readonly = true )
81+ @ Parameter (defaultValue = "${settings.interactiveMode}" , readonly = true )
8582 private boolean interactive ;
8683
8784 /**
@@ -90,15 +87,15 @@ public abstract class AbstractGpgMojo
9087 *
9188 * @since 1.1
9289 */
93- @ Parameter ( property = "gpg.executable" )
90+ @ Parameter (property = "gpg.executable" )
9491 private String executable ;
9592
9693 /**
9794 * Whether to add the default keyrings from gpg's home directory to the list of used keyrings.
9895 *
9996 * @since 1.2
10097 */
101- @ Parameter ( property = "gpg.defaultKeyring" , defaultValue = "true" )
98+ @ Parameter (property = "gpg.defaultKeyring" , defaultValue = "true" )
10299 private boolean defaultKeyring ;
103100
104101 /**
@@ -111,7 +108,7 @@ public abstract class AbstractGpgMojo
111108 *
112109 * @since 1.2
113110 */
114- @ Parameter ( property = "gpg.secretKeyring" )
111+ @ Parameter (property = "gpg.secretKeyring" )
115112 private String secretKeyring ;
116113
117114 /**
@@ -121,7 +118,7 @@ public abstract class AbstractGpgMojo
121118 *
122119 * @since 1.2
123120 */
124- @ Parameter ( property = "gpg.publicKeyring" )
121+ @ Parameter (property = "gpg.publicKeyring" )
125122 private String publicKeyring ;
126123
127124 /**
@@ -133,7 +130,7 @@ public abstract class AbstractGpgMojo
133130 * --lock-options</a>
134131 * @since 1.5
135132 */
136- @ Parameter ( property = "gpg.lockMode" )
133+ @ Parameter (property = "gpg.lockMode" )
137134 private String lockMode ;
138135
139136 /**
@@ -156,49 +153,42 @@ public abstract class AbstractGpgMojo
156153 *
157154 * @since 1.6
158155 */
159- @ Parameter ( defaultValue = "${settings}" , readonly = true )
156+ @ Parameter (defaultValue = "${settings}" , readonly = true )
160157 private Settings settings ;
161158
162159 /**
163160 * Maven Security Dispatcher
164161 *
165162 * @since 1.6
166163 */
167- @ Component ( hint = "mng-4384" )
164+ @ Component (hint = "mng-4384" )
168165 private SecDispatcher securityDispatcher ;
169166
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 );
185180
186181 loadGpgPassphrase ();
187182
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" );
198187 }
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 );
202192 }
203193 }
204194
@@ -210,24 +200,16 @@ AbstractGpgSigner newSigner( MavenProject project )
210200 *
211201 * @throws MojoFailureException
212202 */
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 );
231213 }
232214 }
233215 }
0 commit comments