Skip to content

Commit cd0f6d3

Browse files
committed
[MGPG-78] gpg version parsing failure on Windows
1 parent 1169a69 commit cd0f6d3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public static GpgVersion parse( String rawVersion )
4747
@Override
4848
public int compareTo( GpgVersion other )
4949
{
50-
Pattern p = Pattern.compile( "([.\\d]+)$" );
50+
Pattern p = Pattern.compile( "(\\d+\\.)+(\\d+)" );
5151

5252
String[] thisSegments;
5353
Matcher m = p.matcher( rawVersion );
5454
if ( m.find() )
5555
{
56-
thisSegments = m.group( 1 ).split( "\\." );
56+
thisSegments = m.group( 0 ).split( "\\." );
5757
}
5858
else
5959
{
@@ -64,7 +64,7 @@ public int compareTo( GpgVersion other )
6464
m = p.matcher( other.rawVersion );
6565
if ( m.find() )
6666
{
67-
otherSegments = m.group( 1 ).split( "\\." );
67+
otherSegments = m.group( 0 ).split( "\\." );
6868
}
6969
else
7070
{

src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
* under the License.
2020
*/
2121

22-
import static org.junit.Assert.assertTrue;
23-
24-
import org.apache.maven.plugins.gpg.GpgVersion;
2522
import org.junit.Test;
2623

24+
import static org.junit.Assert.assertTrue;
25+
26+
/**
27+
* Tests for {@link GpgVersion}.
28+
*/
2729
public class GpgVersionTest
2830
{
2931
@Test
@@ -32,6 +34,8 @@ public void test()
3234
assertTrue( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).isAtLeast( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ) ) );
3335
assertTrue( GpgVersion.parse( "gpg (GnuPG) 2.2.1" ).isAtLeast( GpgVersion.parse( "2.1" ) ) );
3436
assertTrue( GpgVersion.parse( "gpg (GnuPG/MacGPG2) 2.2.10" ).isAtLeast( GpgVersion.parse( "2.2.10" ) ) );
37+
assertTrue( GpgVersion.parse( "gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)" )
38+
.isAtLeast( GpgVersion.parse( "2.0.26" ) ) );
3539
}
3640

3741
}

0 commit comments

Comments
 (0)