Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#692 : UrlUpdater fetches every defined version for Docker and latest version is now accepted as well #1117

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE

Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/692[#692]: "Latest" version of Docker causes installation problems


The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/24?closed=1[milestone 2025.03.002].

== 2025.03.001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ protected void addVersion(UrlVersion urlVersion) {
// get Code for version
String body = doGetResponseBodyAsString("https://docs.docker.com/desktop/release-notes/");
String regex = "href=#" + version
// .......1.........................................................2.................
+ ".{8,12}(\r\n|\r|\n).{0,350}href=https://desktop\\.docker\\.com.*?(\\d{5,6}).*\\.exe";
// .....................................................(Group.1.)..........
+ ".{8,12}.{0,350}href=https://desktop\\.docker\\.com.*?(\\d{5,6}).*\\.exe";
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
Matcher matcher = pattern.matcher(body);
String code;
if (matcher.find()) {
code = matcher.group(2);
code = matcher.group(1);
boolean success = doAddVersion(urlVersion,
"https://desktop.docker.com/win/main/amd64/" + code + "/Docker%20Desktop%20Installer.exe", WINDOWS);
if (!success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public abstract class AbstractToolRepository implements ToolRepository {

private static final int MAX_TEMP_DOWNLOADS = 9;

/** The owning {@link IdeContext}. */
protected final IdeContext context;

Expand Down Expand Up @@ -135,7 +135,11 @@ protected String createDownloadFilename(String tool, String edition, VersionIden
StringBuilder sb = new StringBuilder(32);
sb.append(tool);
sb.append("-");
sb.append(version);
if (VersionIdentifier.LATEST.equals(version)) {
sb.append("latest");
} else {
sb.append(version);
}
if (!edition.equals(tool)) {
sb.append("-");
sb.append(edition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public int getChildCount() {
public C getChild(String name) {

load(false);
if ("*".equals(name)) {
return this.childMap.get("latest");
}
return this.childMap.get(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class UrlUpdaterMockSingle extends UrlUpdaterMock {

private static final Set<String> versions = new HashSet<>(List.of("1.0"));
private static Set<String> versions = new HashSet<>(List.of("1.0"));

/**
* The constructor
Expand All @@ -30,6 +30,15 @@ protected Set<String> getVersions() {
return versions;
}

/**
* Enables the possibility to change the version which should be tested.
*
* @param newVersion the new Version to be set.
*/
protected void setVersion(final String newVersion) {
versions = Set.of(newVersion);
}

@Override
protected void addVersion(UrlVersion urlVersion) {
doAddVersion(urlVersion, wmRuntimeInfo.getHttpBaseUrl() + "/os/windows_x64_url.tgz", WINDOWS, X64, "123");
Expand Down
22 changes: 22 additions & 0 deletions cli/src/test/java/com/devonfw/tools/ide/tool/UrlUpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,26 @@ public void testUrlUpdaterWithTextContentTypeWillNotCreateStatusJson(@TempDir Pa

}

/**
* Tests if the {@link com.devonfw.tools.ide.url.updater.UrlUpdater} will handle the literally latest version of a tool correctly
*
* @param tempDir Temporary directory
* @param wmRuntimeInfo wireMock server on a random port
*/
@Test
public void testUrlUpdaterWithOnlyLatestVersion(@TempDir Path tempDir, WireMockRuntimeInfo wmRuntimeInfo) {
//given
stubFor(any(urlMatching("/os/.*")).willReturn(aResponse().withStatus(200).withBody("aBody")));
UrlRepository urlRepository = UrlRepository.load(tempDir);
UrlUpdaterMockSingle updater = new UrlUpdaterMockSingle(wmRuntimeInfo);
updater.setVersion("latest");

// when
updater.update(urlRepository);

// then
Path versionsPath = tempDir.resolve("mocked").resolve("mocked").resolve("latest");
assertThat(versionsPath.resolve("status.json")).exists();
}

}