Skip to content

Commit

Permalink
[MGPG-94] Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Apr 15, 2023
1 parent e160f43 commit 955ea0e
Show file tree
Hide file tree
Showing 17 changed files with 779 additions and 1,129 deletions.
31 changes: 15 additions & 16 deletions pom.xml
@@ -1,5 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Expand All @@ -18,13 +17,12 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>maven-plugins</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
<version>39</version>
<relativePath />
</parent>
Expand All @@ -43,8 +41,8 @@ under the License.
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-gpg-plugin.git</developerConnection>
<url>https://github.com/apache/maven-gpg-plugin/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
<url>https://github.com/apache/maven-gpg-plugin/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>jira</system>
Expand Down Expand Up @@ -139,7 +137,7 @@ under the License.
<artifactId>plexus-sec-dispatcher</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -163,8 +161,8 @@ under the License.
<build>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources</directory>
<filtering>true</filtering>
<directory>${basedir}/src/test/resources</directory>
<includes>
<include>**/pom.xml</include>
<include>**/settings.xml</include>
Expand Down Expand Up @@ -238,14 +236,6 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<JENKINS_MAVEN_AGENT_DISABLED>true</JENKINS_MAVEN_AGENT_DISABLED>
Expand All @@ -258,6 +248,14 @@ under the License.
<settingsFile>/it/settings.xml</settingsFile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -268,7 +266,8 @@ under the License.
<pomInclude>*</pomInclude>
</pomIncludes>
<pomExcludes>
<pomExclude>alternative-secret-keyring</pomExclude> <!-- not supported with gpg 2.1+ -->
<!-- not supported with gpg 2.1+ -->
<pomExclude>alternative-secret-keyring</pomExclude>
</pomExcludes>
<goals>
<goal>clean</goal>
Expand Down
112 changes: 47 additions & 65 deletions src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java
@@ -1,5 +1,3 @@
package org.apache.maven.plugins.gpg;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -9,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
Expand All @@ -18,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugins.gpg;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,50 +37,48 @@
/**
* @author Benjamin Bentmann
*/
public abstract class AbstractGpgMojo
extends AbstractMojo
{
public abstract class AbstractGpgMojo extends AbstractMojo {

/**
* The directory from which gpg will load keyrings. If not specified, gpg will use the value configured for its
* installation, e.g. <code>~/.gnupg</code> or <code>%APPDATA%/gnupg</code>.
*
* @since 1.0
*/
@Parameter( property = "gpg.homedir" )
@Parameter(property = "gpg.homedir")
private File homedir;

/**
* The passphrase to use when signing. If not given, look up the value under Maven
* settings using server id at 'passphraseServerKey' configuration.
**/
@Parameter( property = "gpg.passphrase" )
@Parameter(property = "gpg.passphrase")
private String passphrase;

/**
* Server id to lookup the passphrase under Maven settings.
* @since 1.6
*/
@Parameter( property = "gpg.passphraseServerId", defaultValue = "gpg.passphrase" )
@Parameter(property = "gpg.passphraseServerId", defaultValue = "gpg.passphrase")
private String passphraseServerId;

/**
* The "name" of the key to sign with. Passed to gpg as <code>--local-user</code>.
*/
@Parameter( property = "gpg.keyname" )
@Parameter(property = "gpg.keyname")
private String keyname;

/**
* Passes <code>--use-agent</code> or <code>--no-use-agent</code> to gpg. If using an agent, the passphrase is
* optional as the agent will provide it. For gpg2, specify true as --no-use-agent was removed in gpg2 and doesn't
* ask for a passphrase anymore.
*/
@Parameter( property = "gpg.useagent", defaultValue = "true" )
@Parameter(property = "gpg.useagent", defaultValue = "true")
private boolean useAgent;

/**
*/
@Parameter( defaultValue = "${settings.interactiveMode}", readonly = true )
@Parameter(defaultValue = "${settings.interactiveMode}", readonly = true)
private boolean interactive;

/**
Expand All @@ -90,15 +87,15 @@ public abstract class AbstractGpgMojo
*
* @since 1.1
*/
@Parameter( property = "gpg.executable" )
@Parameter(property = "gpg.executable")
private String executable;

/**
* Whether to add the default keyrings from gpg's home directory to the list of used keyrings.
*
* @since 1.2
*/
@Parameter( property = "gpg.defaultKeyring", defaultValue = "true" )
@Parameter(property = "gpg.defaultKeyring", defaultValue = "true")
private boolean defaultKeyring;

/**
Expand All @@ -111,7 +108,7 @@ public abstract class AbstractGpgMojo
*
* @since 1.2
*/
@Parameter( property = "gpg.secretKeyring" )
@Parameter(property = "gpg.secretKeyring")
private String secretKeyring;

/**
Expand All @@ -121,7 +118,7 @@ public abstract class AbstractGpgMojo
*
* @since 1.2
*/
@Parameter( property = "gpg.publicKeyring" )
@Parameter(property = "gpg.publicKeyring")
private String publicKeyring;

/**
Expand All @@ -133,7 +130,7 @@ public abstract class AbstractGpgMojo
* --lock-options</a>
* @since 1.5
*/
@Parameter( property = "gpg.lockMode" )
@Parameter(property = "gpg.lockMode")
private String lockMode;

/**
Expand All @@ -156,49 +153,42 @@ public abstract class AbstractGpgMojo
*
* @since 1.6
*/
@Parameter( defaultValue = "${settings}", readonly = true )
@Parameter(defaultValue = "${settings}", readonly = true)
private Settings settings;

/**
* Maven Security Dispatcher
*
* @since 1.6
*/
@Component( hint = "mng-4384" )
@Component(hint = "mng-4384")
private SecDispatcher securityDispatcher;

AbstractGpgSigner newSigner( MavenProject project )
throws MojoExecutionException, MojoFailureException
{
AbstractGpgSigner signer = new GpgSigner( executable );

signer.setLog( getLog() );
signer.setInteractive( interactive );
signer.setKeyName( keyname );
signer.setUseAgent( useAgent );
signer.setHomeDirectory( homedir );
signer.setDefaultKeyring( defaultKeyring );
signer.setSecretKeyring( secretKeyring );
signer.setPublicKeyring( publicKeyring );
signer.setLockMode( lockMode );
signer.setArgs( gpgArguments );
AbstractGpgSigner newSigner(MavenProject project) throws MojoExecutionException, MojoFailureException {
AbstractGpgSigner signer = new GpgSigner(executable);

signer.setLog(getLog());
signer.setInteractive(interactive);
signer.setKeyName(keyname);
signer.setUseAgent(useAgent);
signer.setHomeDirectory(homedir);
signer.setDefaultKeyring(defaultKeyring);
signer.setSecretKeyring(secretKeyring);
signer.setPublicKeyring(publicKeyring);
signer.setLockMode(lockMode);
signer.setArgs(gpgArguments);

loadGpgPassphrase();

signer.setPassPhrase( passphrase );
if ( null == passphrase && !useAgent )
{
if ( !interactive )
{
throw new MojoFailureException( "Cannot obtain passphrase in batch mode" );
}
try
{
signer.setPassPhrase( signer.getPassphrase( project ) );
signer.setPassPhrase(passphrase);
if (null == passphrase && !useAgent) {
if (!interactive) {
throw new MojoFailureException("Cannot obtain passphrase in batch mode");
}
catch ( IOException e )
{
throw new MojoExecutionException( "Exception reading passphrase", e );
try {
signer.setPassPhrase(signer.getPassphrase(project));
} catch (IOException e) {
throw new MojoExecutionException("Exception reading passphrase", e);
}
}

Expand All @@ -210,24 +200,16 @@ AbstractGpgSigner newSigner( MavenProject project )
*
* @throws MojoFailureException
*/
private void loadGpgPassphrase()
throws MojoFailureException
{
if ( StringUtils.isEmpty( this.passphrase ) )
{
Server server = this.settings.getServer( passphraseServerId );

if ( server != null )
{
if ( server.getPassphrase() != null )
{
try
{
this.passphrase = securityDispatcher.decrypt( server.getPassphrase() );
}
catch ( SecDispatcherException e )
{
throw new MojoFailureException( "Unable to decrypt gpg passphrase", e );
private void loadGpgPassphrase() throws MojoFailureException {
if (StringUtils.isEmpty(this.passphrase)) {
Server server = this.settings.getServer(passphraseServerId);

if (server != null) {
if (server.getPassphrase() != null) {
try {
this.passphrase = securityDispatcher.decrypt(server.getPassphrase());
} catch (SecDispatcherException e) {
throw new MojoFailureException("Unable to decrypt gpg passphrase", e);
}
}
}
Expand Down

0 comments on commit 955ea0e

Please sign in to comment.