GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [MGPG-81] check format in constructor by Syquel · Pull Request #11 · apache/maven-gpg-plugin

Conversation

@Syquel

@Syquel Syquel commented Feb 26, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Provides an refactored implementation of GpgVersion to address MGPG-81.

The parsing logic is being moved from "GpgVersion#compareTo" to "GpgVersion#parse" to throw IllegalArgumentException in a semantically correct way.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo
elharo reviewed Feb 26, 2021
View reviewed changes

@elharo elharo left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you split this into individual PRs for each issue? That makes it much easier to review and track in Jira and release notes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo
elharo reviewed Feb 26, 2021
View reviewed changes
Comment thread src/test/java/org/apache/maven/plugins/gpg/GpgVersionTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

elharo
elharo reviewed Feb 26, 2021
View reviewed changes
Comment thread src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java
int otherValue = Integer.parseInt( otherSegments[index] );

int compareValue = Integer.compare( thisValue, otherValue );
int compareValue = Integer.compare( thisSegments[index], otherSegments[index] );

@elharo elharo Feb 26, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a simple int comparison? e.g.

if (thisSegments[index] != otherSegments[index]) {
  return thisSegments[index] - otherSegments[index]
}

(Double check my order there)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Syquel Syquel Feb 26, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be preferable to adhere to the contract of Integer#compareTo / Integer#compare, which is internally implemented as (x < y) ? -1 : ((x == y) ? 0 : 1), because this class is in my opinion just a container for an int array and should behave as such.

But your solution works of course, too. Your call.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Feb 26, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We should adhere to the contract. The contract is more lenient than the current implementation. It just requires negative, positive, or zero at the appropriate places, not -1, 0, or +1 specifically.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Syquel

Syquel commented Feb 26, 2021

Copy link
Copy Markdown
Contributor Author

can you split this into individual PRs for each issue? That makes it much easier to review and track in Jira and release notes.

I will reduce this PR to MGPG-81 by removing GpgVersion#equals and GpgVersion#hashCode first and submit another PR for MGPG-80 later on after this one is merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Syquel
[MGPG-81] refactor GpgVersion
64e1d4e
@Syquel Syquel changed the title [MGPG-80][MGPG-81] refactor GpgVersion [MGPG-81] refactor GpgVersion Feb 26, 2021
@elharo elharo changed the title [MGPG-81] refactor GpgVersion [MGPG-81] check format in constructor Feb 26, 2021
elharo
elharo reviewed Feb 26, 2021
View reviewed changes
Comment thread src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java
int otherValue = Integer.parseInt( otherSegments[index] );

int compareValue = Integer.compare( thisValue, otherValue );
int compareValue = Integer.compare( thisSegments[index], otherSegments[index] );

@elharo elharo Feb 26, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We should adhere to the contract. The contract is more lenient than the current implementation. It just requires negative, positive, or zero at the appropriate places, not -1, 0, or +1 specifically.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java

@Override
public int compareTo( GpgVersion other )
public static GpgVersion parse( String rawVersion )

@elharo elharo Feb 26, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this version string come from? That is, what is it the version of? Is it ever anything that does not match this pattern? E.g. 3.45.2-beta?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Syquel Syquel Feb 26, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see the original author of this class made the assumption that it will always be a sequence of numbers delimited by dots (although the original author wrote in the class-level comment, that this is a SemVer parser).
The raw version string is read from the output of gpg --version apparently.

Unfortunately I am in no position to evaluate whether GPG will continue using this versioning scheme, but it seems they have consistently used it up until now: https://files.gpg4win.org/
In my opinion we can make the assumption, that GPG will continue using a three segment wide versioning scheme just as the original author implemented it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java
String[] thisSegments;
Matcher m = p.matcher( rawVersion );
if ( m.find() )
final Matcher versionMatcher = VERSION_PATTERN.matcher( rawVersion );

@elharo elharo Feb 26, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex might be overkill. Looks like you can just catch and convert the number format exception below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Syquel Syquel Feb 26, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original author implemented it in a way, that the full output of gpg --version (e.g. gpg (GnuPG) 2.2.1 or gpg (GnuPG) 2.0.26 (Gpg4win 2.2.3)) is passed to this function.
They used the regex to extract the version part out of that output.

It is debatable whether that is the best way to extract the version number (personally I would have extracted the version number part already in GpgVersionParser.GpgVersionConsumer before passing it in here), but I would like to avoid introducing new bugs by breaking with the existing external contract of this class.

In the end it's your call again; I could widen the scope of the refactoring to the whole GPG version parser.
In that case we could change the contract to expect a dot-separated sequence of numbers, move the regex to GpgVersionParser.GpgVersionConsumer and simply parse it here via splitting.

// EDIT
IMO widening the scope would break the scope of the ticket. The goal was to refactor this class to use IllegalArgumentException in a proper semantic way by moving the actual parsing from compareTo to the time the object is created.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo
elharo approved these changes Feb 26, 2021
View reviewed changes
@elharo

elharo commented Feb 26, 2021

Copy link
Copy Markdown
Contributor

give me a minute to run this through jenkins

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@elharo

elharo commented Feb 26, 2021

Copy link
Copy Markdown
Contributor

https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-gpg-plugin/job/check/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@elharo
elharo merged commit b38c638 into apache:master Feb 26, 2021
@Syquel

Syquel commented Feb 26, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for merging.

As promised I submitted PR #12 for MGPG-80.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Tibor17
Tibor17 reviewed May 6, 2021
View reviewed changes
Comment thread src/main/java/org/apache/maven/plugins/gpg/GpgVersion.java
{
this.rawVersion = rawVersion;
}
private static final Pattern VERSION_PATTERN = Pattern.compile( "(\\d+\\.)+(\\d+)" );

@Tibor17 Tibor17 May 6, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Syquel
@elharo
How many times these patterns exist in the project?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Syquel Syquel May 6, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two patterns AFAIK: One in GpgVersionParser.GpgVersionConsumer and this one here.
This one could possibly be removed and GpgVersionParser.GpgVersionConsumer could pass the extracted version number to GpgVersion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Syquel Syquel May 6, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be even better to use gpgconf --query-swdb gnupg instead of gpg --version, because gpgconf returns machine-readable output.

$ gpgconf --query-swdb gnupg
gnupg:2.2.27:-::32849:::::::

although I don't know if that would work with all distributions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bmarwell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@bmarwell bmarwell May 6, 2021

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works on mac, too:

$ gpgconf --query-swdb gnupg
gnupg:2.2.21:-::32849:::::::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced May 10, 2021
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-snowflake#77
Closed
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-cassandra#78
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-hibernate#318
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-redshift#50
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-maxdb#37
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-teradata#46
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-hanadb#64
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-cache#28
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-sqlfire#30
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-db2i#38
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-oracle#71
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-mongodb#132
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-postgresql#56
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-mssql#32
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-vertica#51
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-db2i#43
Merged
This was referenced May 12, 2021
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-mssql#39
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-oracle#76
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-sqlfire#36
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-teradata#52
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-vertica#61
Merged
Bump maven-gpg-plugin from 1.6 to 3.0.1 liquibase/liquibase-mongodb#141
Merged
@jira-importer

jira-importer commented Jun 14, 2025

Copy link
Copy Markdown

Resolve #219

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jira-importer

jira-importer commented Jun 14, 2025

Copy link
Copy Markdown

Resolve #223

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 similar comment
@jira-importer

jira-importer commented Jun 14, 2025

Copy link
Copy Markdown

Resolve #223

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jira-importer

jira-importer commented Jun 14, 2025

Copy link
Copy Markdown

Resolve #219

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Tibor17 Tibor17 Tibor17 left review comments
@bmarwell bmarwell bmarwell left review comments
@elharo elharo elharo approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@Syquel @elharo @jira-importer @Tibor17 @bmarwell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.