Skip to content

Commit 955ea0e

Browse files
committed
[MGPG-94] Reformat code
1 parent e160f43 commit 955ea0e

17 files changed

+779
-1129
lines changed

pom.xml

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version='1.0' encoding='UTF-8'?>
2-
1+
<?xml version="1.0" encoding="UTF-8"?>
32
<!--
43
Licensed to the Apache Software Foundation (ASF) under one
54
or more contributor license agreements. See the NOTICE file
@@ -18,13 +17,12 @@ KIND, either express or implied. See the License for the
1817
specific language governing permissions and limitations
1918
under the License.
2019
-->
21-
2220
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2321
<modelVersion>4.0.0</modelVersion>
2422

2523
<parent>
26-
<artifactId>maven-plugins</artifactId>
2724
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-plugins</artifactId>
2826
<version>39</version>
2927
<relativePath />
3028
</parent>
@@ -43,8 +41,8 @@ under the License.
4341
<scm>
4442
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git</connection>
4543
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git</developerConnection>
46-
<url>https://github.com/apache/maven-gpg-plugin/tree/${project.scm.tag}</url>
4744
<tag>HEAD</tag>
45+
<url>https://github.com/apache/maven-gpg-plugin/tree/${project.scm.tag}</url>
4846
</scm>
4947
<issueManagement>
5048
<system>jira</system>
@@ -139,7 +137,7 @@ under the License.
139137
<artifactId>plexus-sec-dispatcher</artifactId>
140138
<version>1.4</version>
141139
</dependency>
142-
140+
143141
<dependency>
144142
<groupId>junit</groupId>
145143
<artifactId>junit</artifactId>
@@ -163,8 +161,8 @@ under the License.
163161
<build>
164162
<testResources>
165163
<testResource>
166-
<directory>${basedir}/src/test/resources</directory>
167164
<filtering>true</filtering>
165+
<directory>${basedir}/src/test/resources</directory>
168166
<includes>
169167
<include>**/pom.xml</include>
170168
<include>**/settings.xml</include>
@@ -238,14 +236,6 @@ under the License.
238236
<plugin>
239237
<groupId>org.apache.maven.plugins</groupId>
240238
<artifactId>maven-failsafe-plugin</artifactId>
241-
<executions>
242-
<execution>
243-
<goals>
244-
<goal>integration-test</goal>
245-
<goal>verify</goal>
246-
</goals>
247-
</execution>
248-
</executions>
249239
<configuration>
250240
<environmentVariables>
251241
<JENKINS_MAVEN_AGENT_DISABLED>true</JENKINS_MAVEN_AGENT_DISABLED>
@@ -258,6 +248,14 @@ under the License.
258248
<settingsFile>/it/settings.xml</settingsFile>
259249
</systemPropertyVariables>
260250
</configuration>
251+
<executions>
252+
<execution>
253+
<goals>
254+
<goal>integration-test</goal>
255+
<goal>verify</goal>
256+
</goals>
257+
</execution>
258+
</executions>
261259
</plugin>
262260
<plugin>
263261
<groupId>org.apache.maven.plugins</groupId>
@@ -268,7 +266,8 @@ under the License.
268266
<pomInclude>*</pomInclude>
269267
</pomIncludes>
270268
<pomExcludes>
271-
<pomExclude>alternative-secret-keyring</pomExclude> <!-- not supported with gpg 2.1+ -->
269+
<!-- not supported with gpg 2.1+ -->
270+
<pomExclude>alternative-secret-keyring</pomExclude>
272271
</pomExcludes>
273272
<goals>
274273
<goal>clean</goal>

src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java

+47-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
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
@@ -9,7 +7,7 @@
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
@@ -18,6 +16,7 @@
1816
* specific language governing permissions and limitations
1917
* under the License.
2018
*/
19+
package org.apache.maven.plugins.gpg;
2120

2221
import java.io.File;
2322
import java.io.IOException;
@@ -38,50 +37,48 @@
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

Comments
 (0)