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

483: support multiple editions in update #555

Merged
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.devonfw.tools.ide.tool.intellij;

import java.util.Collection;
import java.util.List;

import com.devonfw.tools.ide.common.JsonVersionItem;
import com.devonfw.tools.ide.json.mapping.JsonMapping;
import com.devonfw.tools.ide.os.OperatingSystem;
import com.devonfw.tools.ide.os.SystemArchitecture;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
Expand All @@ -20,45 +19,9 @@ public class IntellijUrlUpdater extends JsonUrlUpdater<IntellijJsonObject, Intel

private static final String VERSION_BASE_URL = "https://data.services.jetbrains.com";
private static final String JSON_URL = "products?code=IIU%2CIIC&release.type=release";
private static final String ULTIMATE_EDITION = "ultimate";
private static final String COMMUNITY_EDITION = "intellij";
private static final List<String> EDITIONS = List.of("ultimate", "intellij");
private static final ObjectMapper MAPPER = JsonMapping.create();

@Override
public void update(UrlRepository urlRepository) {

UrlTool tool = urlRepository.getOrCreateChild(getTool());

try {
String response = doGetResponseBodyAsString(doGetVersionUrl());
IntellijJsonObject[] jsonObj = MAPPER.readValue(response, IntellijJsonObject[].class);
// Has 2 elements, 1. Ultimate Edition, 2. Community Edition
IntellijJsonObject ultimateRelease;
IntellijJsonObject communityRelease;

if (jsonObj.length == 2) {
ultimateRelease = jsonObj[0];
communityRelease = jsonObj[1];
UrlEdition edition;

if (ultimateRelease != null) {
edition = tool.getOrCreateChild(ULTIMATE_EDITION);
updateExistingVersions(edition);
collectVersionsWithDownloadsFromJson(ultimateRelease, edition);
}

if (communityRelease != null) {
edition = tool.getOrCreateChild(COMMUNITY_EDITION);
updateExistingVersions(edition);
collectVersionsWithDownloadsFromJson(communityRelease, edition);
}
}

} catch (Exception e) {
throw new IllegalStateException("Error while getting versions from JSON API " + JSON_URL, e);
}
}

/**
* Follows link and gets body as string which contains checksum
*/
Expand All @@ -74,6 +37,11 @@ protected String getTool() {
return "intellij";
}

@Override
protected List<String> getEditions() {
return EDITIONS;
}

@Override
protected String doGetVersionUrl() {

Expand Down Expand Up @@ -139,6 +107,11 @@ protected void addVersion(UrlVersion urlVersion, IntellijJsonRelease release) {
}
}

protected IntellijJsonObject getJsonObjectFromResponse(String response, String edition) throws JsonProcessingException {
IntellijJsonObject[] jsonObjects = MAPPER.readValue(response, IntellijJsonObject[].class);
return jsonObjects[EDITIONS.indexOf(edition)];
}

@Override
protected Collection<IntellijJsonRelease> getVersionItems(IntellijJsonObject jsonObject) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;

/**
* The {@Link JsonUrlUpdater} for Python
* The {@link JsonUrlUpdater} for Python
*/
public class PythonUrlUpdater extends JsonUrlUpdater<PythonJsonObject, PythonRelease> {

/**
* The base Url of the Python versions Json
*/
private String VERSION_BASE_URL = "https://raw.githubusercontent.com";
private final String VERSION_BASE_URL = "https://raw.githubusercontent.com";

private final static String VERSION_FILENAME = "actions/python-versions/main/versions-manifest.json";

Expand Down Expand Up @@ -79,7 +79,7 @@ protected Class<PythonJsonObject> getJsonObjectType() {
}

@Override
protected PythonJsonObject getJsonObjectFromResponse(String response) throws JsonProcessingException {
protected PythonJsonObject getJsonObjectFromResponse(String response, String edition) throws JsonProcessingException {
PythonRelease[] res = MAPPER.readValue(response, PythonRelease[].class);
PythonJsonObject jsonObj = new PythonJsonObject();
jsonObj.setReleases(List.of(res));
Expand Down
Loading
Loading