Skip to content

Commit 6324037

Browse files
#1255: Enhance snapshot version recognition in IDEasy (#1962)
Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>
1 parent dc1835d commit 6324037

3 files changed

Lines changed: 137 additions & 7 deletions

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE
66

77
Release with new features and bugfixes:
88

9+
* https://github.com/devonfw/IDEasy/issues/1255[#1255]: Enhance snapshot version recognition in IDEasy
910
* https://github.com/devonfw/IDEasy/issues/1964[#1964]: Fixed gui not launching with older project java versions
1011
* https://github.com/devonfw/IDEasy/issues/1968[#1968]: Fixed gui blocking the terminal session while running.
1112
* https://github.com/devonfw/IDEasy/issues/1849[#1849]: Add VSCodium support

cli/src/main/java/com/devonfw/tools/ide/tool/IdeasyCommandlet.java

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.List;
1010
import java.util.Map;
1111
import java.util.Set;
12+
import java.util.regex.Matcher;
13+
import java.util.regex.Pattern;
1214

1315
import org.slf4j.Logger;
1416
import org.slf4j.LoggerFactory;
@@ -71,6 +73,27 @@ public class IdeasyCommandlet extends MvnBasedLocalToolCommandlet {
7173

7274
private final UpgradeMode mode;
7375

76+
/** Pattern for IDEasy SNAPSHOT versions built locally. */
77+
// ..............................................................................1..........................2........3........4
78+
private static final Pattern PATTERN_IDEASY_SNAPSHOT_VERSION = Pattern.compile("^(\\d{4}\\.\\d{2}\\.\\d{3})-(\\d{2})_(\\d{2})_(\\d{2}).*-SNAPSHOT$");
79+
80+
/** Pattern for Maven/Nexus SNAPSHOT versions from downloads . */
81+
// .............................................................................1..........................2.......3.......4..........5
82+
private static final Pattern PATTERN_MAVEN_SNAPSHOT_VERSION = Pattern.compile("^(\\d{4}\\.\\d{2}\\.\\d{3})-(\\d{4})(\\d{2})(\\d{2})\\.(\\d{2})\\d{4}.*$");
83+
84+
// Group numbers for PATTERN_IDEASY_SNAPSHOT_VERSION
85+
private static final int GROUP_IDEASY_BASE = 1;
86+
private static final int GROUP_IDEASY_MONTH = 2;
87+
private static final int GROUP_IDEASY_DAY = 3;
88+
private static final int GROUP_IDEASY_HOUR = 4;
89+
90+
// Group numbers for PATTERN_MAVEN_SNAPSHOT_VERSION
91+
private static final int GROUP_MAVEN_BASE = 1;
92+
private static final int GROUP_MAVEN_YEAR = 2;
93+
private static final int GROUP_MAVEN_MONTH = 3;
94+
private static final int GROUP_MAVEN_DAY = 4;
95+
private static final int GROUP_MAVEN_HOUR = 5;
96+
7497
/**
7598
* The constructor.
7699
*
@@ -178,15 +201,60 @@ public boolean checkIfUpdateIsAvailable() {
178201
return false;
179202
}
180203
VersionIdentifier latestVersion = getLatestVersion();
181-
if (installedVersion.equals(latestVersion)) {
182-
IdeLogLevel.SUCCESS.log(LOG, "Your are using the latest version of IDEasy and no update is available.");
204+
if (IdeVersion.isSnapshot()) {
205+
if (isSameSnapshotVersion(installedVersion.toString(), latestVersion.toString())) {
206+
IdeLogLevel.SUCCESS.log(LOG, "Your are using the latest snapshot version of IDEasy and no update is available.");
207+
return false;
208+
}
209+
} else if (installedVersion.equals(latestVersion)) {
210+
IdeLogLevel.SUCCESS.log(LOG, "Your are using the latest stable version of IDEasy and no update is available.");
183211
return false;
184-
} else {
185-
IdeLogLevel.INTERACTION.log(LOG,
186-
"Your version of IDEasy is {} but version {} is available. Please run the following command to upgrade to the latest version:\n"
187-
+ "ide upgrade", installedVersion, latestVersion);
188-
return true;
189212
}
213+
IdeLogLevel.INTERACTION.log(LOG,
214+
"Your version of IDEasy is {} but version {} is available. Please run the following command to upgrade to the latest version:\n"
215+
+ "ide upgrade", installedVersion, latestVersion);
216+
return true;
217+
}
218+
219+
/**
220+
* Checks if two snapshot versions represent the version
221+
*
222+
* @param installed the installed version string
223+
* @param latest the latest available version string
224+
* @return {@code true} if both versions represent the same version, {@code false} otherwise.
225+
*/
226+
private boolean isSameSnapshotVersion(String installed, String latest) {
227+
if (installed == null || latest == null) {
228+
return false;
229+
}
230+
231+
Matcher installedMatcher = PATTERN_IDEASY_SNAPSHOT_VERSION.matcher(installed);
232+
Matcher latestMatcher = PATTERN_MAVEN_SNAPSHOT_VERSION.matcher(latest);
233+
234+
if (!installedMatcher.matches() || !latestMatcher.matches()) {
235+
return false;
236+
}
237+
238+
// Compare base versions
239+
String baseInstalled = installedMatcher.group(GROUP_IDEASY_BASE);
240+
String baseLatest = latestMatcher.group(GROUP_MAVEN_BASE);
241+
if (!baseInstalled.equals(baseLatest)) {
242+
return false;
243+
}
244+
245+
// Compare year
246+
String yearLatest = latestMatcher.group(GROUP_MAVEN_YEAR);
247+
String baseYear = baseInstalled.split("\\.")[0];
248+
if (!baseYear.equals(yearLatest)) {
249+
return false;
250+
}
251+
252+
// Compare MMDD.HH for both versions
253+
String keyInstalled =
254+
installedMatcher.group(GROUP_IDEASY_MONTH) + installedMatcher.group(GROUP_IDEASY_DAY) + "." + installedMatcher.group(GROUP_IDEASY_HOUR);
255+
String keyLatest = latestMatcher.group(GROUP_MAVEN_MONTH) + latestMatcher.group(GROUP_MAVEN_DAY) + "." + latestMatcher.group(GROUP_MAVEN_HOUR);
256+
257+
return keyInstalled.equals(keyLatest);
190258
}
191259

192260
/**

cli/src/test/java/com/devonfw/tools/ide/tool/IdeasyCommandletTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.devonfw.tools.ide.os.SystemInfoMock;
1616
import com.devonfw.tools.ide.os.WindowsHelper;
1717
import com.devonfw.tools.ide.os.WindowsPathSyntax;
18+
import com.devonfw.tools.ide.version.VersionIdentifier;
1819

1920
/**
2021
* Test of {@link IdeasyCommandlet}.
@@ -155,6 +156,66 @@ void testInstallIdeasyTwiceDoesNotDuplicateGitLongpaths() {
155156
assertThat(gitconfigPath).content().doesNotContain("longpaths = false");
156157
}
157158

159+
/**
160+
* Test of {@link IdeasyCommandlet#checkIfUpdateIsAvailable()} with same snapshot versions.
161+
*/
162+
@Test
163+
void testCheckIfUpdateIsAvailableWithSameSnapshotVersions() {
164+
165+
// arrange
166+
IdeTestContext context = newContext("install");
167+
context.getStartContext().setOfflineMode(false);
168+
IdeasyCommandlet ideasy = new IdeasyCommandlet(context) {
169+
@Override
170+
public VersionIdentifier getInstalledVersion() {
171+
return VersionIdentifier.of("2025.04.002-04_17_02-SNAPSHOT");
172+
}
173+
174+
@Override
175+
public VersionIdentifier getLatestVersion() {
176+
return VersionIdentifier.of("2025.04.002-20250417.024201-5");
177+
}
178+
};
179+
180+
// act
181+
boolean updateAvailable = ideasy.checkIfUpdateIsAvailable();
182+
183+
// assert
184+
assertThat(updateAvailable).isFalse();
185+
assertThat(context).logAtSuccess().hasMessage("Your are using the latest snapshot version of IDEasy and no update is available.");
186+
}
187+
188+
/**
189+
* Test of {@link IdeasyCommandlet#checkIfUpdateIsAvailable()} with different snapshot versions.
190+
*/
191+
@Test
192+
void testCheckIfUpdateIsAvailableWithDifferentSnapshotVersions() {
193+
194+
// arrange
195+
IdeTestContext context = newContext("install");
196+
context.getStartContext().setOfflineMode(false);
197+
IdeasyCommandlet ideasy = new IdeasyCommandlet(context) {
198+
@Override
199+
public VersionIdentifier getInstalledVersion() {
200+
return VersionIdentifier.of("2025.04.002-04_17_02-SNAPSHOT");
201+
}
202+
203+
@Override
204+
public VersionIdentifier getLatestVersion() {
205+
return VersionIdentifier.of("2026.05.001-20260519.032313-17");
206+
}
207+
};
208+
209+
// act
210+
boolean updateAvailable = ideasy.checkIfUpdateIsAvailable();
211+
212+
// assert
213+
assertThat(updateAvailable).isTrue();
214+
assertThat(context).logAtInteraction()
215+
.hasMessageContaining("version 2026.05.001-20260519.032313-17 is available. Please run the following command to upgrade to the latest version:\n"
216+
+ "ide upgrade");
217+
}
218+
158219
private void verifyInstallation(Path installationPath) {
159220

160221
assertThat(installationPath).isDirectory();

0 commit comments

Comments
 (0)