#1255: Enhance snapshot version recognition in IDEasy#1962
#1255: Enhance snapshot version recognition in IDEasy#1962AdemZarrouki wants to merge 8 commits into
Conversation
…ducing isSameSnapshotVersion
Coverage Report for CI Build 26283433836Coverage increased (+0.006%) to 71.121%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions75 previously-covered lines in 2 files lost coverage.
Coverage Stats💛 - Coveralls |
hohwille
left a comment
There was a problem hiding this comment.
@AdemZarrouki thanks for your PR and sorry for stepping in early. I just found some time to have a look already and want to give fast feedback...
Your approach looks good and your test with overriding the methods in anonymous class is very elegant to properly test the logic. 👍
For the regex stuff I left some suggestion to improve.
| } | ||
|
|
||
| // extract base year (YYYY) | ||
| Matcher baseMatcher_installed = Pattern.compile("^(\\d{4})\\.\\d{2}\\.\\d{3}$").matcher(base_installed); |
There was a problem hiding this comment.
As a best-practice we create Patterns as constants. This has the following advantages:
- the pattern is compile only once (what takes some time even though it may be peanuts, in a server side app with millions of users this could make a difference) when the class is loaded and not every time the method gets executed
- if the pattern has a syntax error you get fast fail behaviour and an exception will already be raised when the class is loaded and not only later when the method gets executed. Should not make much difference since you also cover the method in a JUnit test but if the regex breaks you would already get an exception if you run IDEasy but forget to run the test...
- when we use groups, we even add a comment above to mark the group numbers so complex regular expressions get maintainable. See e.g. https://github.com/m-m-m/db/blob/c2b356923cf915ee6a1e13087f321b52fc494f95/schema/src/main/java/io/github/mmm/db/schema/impl/DbSchemaManagerImpl.java#L32-L34 (I was thinking or hoping that we follow these best-practices already in IDEasy but unfortunately not really yet - but it is never too late to improve the code style so for existing code I may find the time to do a cleanup PR on regex stuff).
I would simply create two REGEX constants one for the SNAPSHOT version pattern build into IDEasy and one for the maven/nexus SNAPSHOT version pattern for downloads.
Then you can compare the corresponding groups from both matchers in one go.
IMHO that would be easier to understand than having first two identical redundant regex patterns only for the base version and then additional regex patterns for the part after the dash.
WDYT?
|
@hohwille thanks for the early review and the improvements you mentioned. I updated the PR with the requested changes and also i think that using two REGEX constants is easier to understand. |
This PR fixes #1255
Implemented changes:
isSameSnapshotVersionto compare 2 snapshot versionscheckIfUpdateIsAvailablewith explicit snapshot vs stable version comparison logicTesting instructions
testCheckIfUpdateIsAvailableWithSameSnapshotVersionsandtestCheckIfUpdateIsAvailableWithDifferentSnapshotVersions."C:\Users\projects\IDEasy\workspaces\main\IDEasy\cli\target\ideasy.exe"status you get only2026.05.001-SNAPSHOTso we can't really compare it with the latest version (here2026.05.001-20260520.032326-18)Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internal