[MGPG-71] Plugin does not work with GPG on OSX with version string "gpg (GnuPG/MacGPG2) 2.2.10"
diff --git a/src/main/java/org/apache/maven/plugin/gpg/GpgVersion.java b/src/main/java/org/apache/maven/plugin/gpg/GpgVersion.java
index c8367dc..b1da2cf 100644
--- a/src/main/java/org/apache/maven/plugin/gpg/GpgVersion.java
+++ b/src/main/java/org/apache/maven/plugin/gpg/GpgVersion.java
@@ -23,6 +23,9 @@
import java.util.regex.Pattern;
/**
+ * Represents the semver value of GPG.
+ * This is in most cases the first line of <code>gpg --version</code>
+ *
*
* @author Robert Scholte
* @since 3.0.0
diff --git a/src/main/java/org/apache/maven/plugin/gpg/GpgVersionParser.java b/src/main/java/org/apache/maven/plugin/gpg/GpgVersionParser.java
index 378d347..56b3084 100644
--- a/src/main/java/org/apache/maven/plugin/gpg/GpgVersionParser.java
+++ b/src/main/java/org/apache/maven/plugin/gpg/GpgVersionParser.java
@@ -31,7 +31,19 @@
import org.codehaus.plexus.util.cli.StreamConsumer;
/**
- *
+ * Parse the output of <code>gpg --version</code> and exposes these as dedicated objects.
+ *
+ * Supported:
+ * <ul>
+ * <li>gpg version, i.e. gpg (GnuPG) 2.2.15</li>
+ * </ul>
+ * Unsupported:
+ * <ul>
+ * <li>libgcrypt version</li>
+ * <li>Home</li>
+ * <li>Supported algorithms (Pubkey, Cipher, Hash, Compression)</li>
+ * </ul>
+ *
* @author Robert Scholte
* @since 3.0.0
*/
@@ -77,7 +89,7 @@
public GpgVersion getGpgVersion()
{
- return consumer.gpgVersion;
+ return consumer.getGpgVersion();
}
@@ -90,7 +102,7 @@
static class GpgVersionConsumer
implements StreamConsumer
{
- private final Pattern gpgVersionPattern = Pattern.compile( "gpg \\(GnuPG\\) .+" );
+ private final Pattern gpgVersionPattern = Pattern.compile( "gpg \\([^)]+\\) .+" );
private GpgVersion gpgVersion;
@@ -104,6 +116,11 @@
gpgVersion = GpgVersion.parse( m.group() );
}
}
+
+ public GpgVersion getGpgVersion()
+ {
+ return gpgVersion;
+ }
}
}
diff --git a/src/test/java/org/apache/maven/plugin/gpg/GpgVersionConsumerTest.java b/src/test/java/org/apache/maven/plugin/gpg/GpgVersionConsumerTest.java
new file mode 100644
index 0000000..cae0ea1
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/gpg/GpgVersionConsumerTest.java
@@ -0,0 +1,40 @@
+package org.apache.maven.plugin.gpg;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.maven.plugin.gpg.GpgVersionParser.GpgVersionConsumer;
+import org.junit.Test;
+
+public class GpgVersionConsumerTest
+{
+ @Test
+ public void test()
+ throws Exception
+ {
+ GpgVersionConsumer consumer = new GpgVersionConsumer();
+ consumer.consumeLine( "gpg (GnuPG/MacGPG2) 2.2.10" );
+
+ assertThat( consumer.getGpgVersion().toString(), is( "gpg (GnuPG/MacGPG2) 2.2.10" ) );
+ }
+
+}
diff --git a/src/test/java/org/apache/maven/plugin/gpg/GpgVersionTest.java b/src/test/java/org/apache/maven/plugin/gpg/GpgVersionTest.java
index 2204aca..d7d4652 100644
--- a/src/test/java/org/apache/maven/plugin/gpg/GpgVersionTest.java
+++ b/src/test/java/org/apache/maven/plugin/gpg/GpgVersionTest.java
@@ -30,6 +30,7 @@
{
assertTrue( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).isAtLeast( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) ) );
assertTrue( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).isAtLeast( GpgVersion.parse( "2.1" ) ) );
+ assertTrue( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).isAtLeast( GpgVersion.parse( "2.2.10" ) ) );
}
}