Search in sources :

Example 16 with Semver

use of com.vdurmont.semver4j.Semver in project graylog2-server by Graylog2.

the class SemverDeserializerTest method successfullyDeserializesInteger.

@Test
public void successfullyDeserializesInteger() throws IOException {
    final Semver version = objectMapper.readValue("5", Semver.class);
    assertThat(version).isEqualTo(new Semver("5", Semver.SemverType.LOOSE));
}
Also used : Semver(com.vdurmont.semver4j.Semver) Test(org.junit.Test)

Example 17 with Semver

use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.

the class SystemUpdateService method extractNewerPatchVersions.

protected static List<JsonElement> extractNewerPatchVersions(Semver currentVersion, JsonObject allVersions) {
    List<JsonElement> newerPatchVersions = new ArrayList<>();
    for (JsonElement versionElement : allVersions.getAsJsonArray("versions")) {
        String majorDotMinor = versionElement.getAsJsonObject().getAsJsonPrimitive(FIELD_NAME_NAME).getAsString();
        Semver semver = new Semver(String.format("%s.0", majorDotMinor));
        // patch versions higher than the currentVersion's patch version
        if (Objects.equals(currentVersion.getMajor(), semver.getMajor()) && Objects.equals(currentVersion.getMinor(), semver.getMinor())) {
            int latestPatchVersion = versionElement.getAsJsonObject().getAsJsonPrimitive("latestPatchVersion").getAsInt();
            if (currentVersion.getPatch() < latestPatchVersion) {
                for (JsonElement patchElement : versionElement.getAsJsonObject().getAsJsonArray("patchVersions")) {
                    int patchVersion = patchElement.getAsJsonObject().getAsJsonPrimitive(FIELD_NAME_VERSION).getAsInt();
                    if (currentVersion.getPatch() < patchVersion) {
                        log.debug("Found a newer patch version, " + "adding it the result list; version={}", patchVersion);
                        newerPatchVersions.add(patchElement);
                    }
                }
            }
        }
    }
    return newerPatchVersions;
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) Semver(com.vdurmont.semver4j.Semver)

Example 18 with Semver

use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.

the class SystemUpdateServiceTest method testParseJsonPatchVersions_Success.

@Test
void testParseJsonPatchVersions_Success() {
    List<JsonElement> newerPatchVersions = new ArrayList<>();
    JsonObject patchJsonObject = new JsonObject();
    patchJsonObject.addProperty("name", "1.2.3");
    patchJsonObject.addProperty("releaseDate", "2018-01-01");
    patchJsonObject.addProperty("url", "https://example.com/download/1.2.3");
    newerPatchVersions.add(patchJsonObject);
    Map<Semver, Map<String, String>> versionsAndMetadata = SystemUpdateService.convertJsonToMap(newerPatchVersions);
    assertNotNull(versionsAndMetadata);
    assertEquals(1, newerPatchVersions.size());
    Semver semverKey = new Semver("1.2.3");
    assertEquals("1.2.3", versionsAndMetadata.get(semverKey).get("version"));
    assertEquals("2018-01-01", versionsAndMetadata.get(semverKey).get("releaseDate"));
    assertEquals("https://example.com/download/1.2.3", versionsAndMetadata.get(semverKey).get("downloadUrl"));
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Semver(com.vdurmont.semver4j.Semver) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 19 with Semver

use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.

the class SystemUpdateServiceTest method testGetNewerPatchVersions_NoNewerPatchVersions.

@Test
void testGetNewerPatchVersions_NoNewerPatchVersions() {
    Semver currentVersion = new Semver("1.2.3");
    JsonObject allVersions = new JsonObject();
    allVersions.add("versions", new JsonArray());
    List<JsonElement> newerPatchVersions = SystemUpdateService.extractNewerPatchVersions(currentVersion, allVersions);
    assertTrue(newerPatchVersions.isEmpty());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Semver(com.vdurmont.semver4j.Semver) Test(org.junit.jupiter.api.Test)

Example 20 with Semver

use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.

the class SystemUpdateServiceTest method testGetNewerPatchVersions_Success.

@Test
void testGetNewerPatchVersions_Success() {
    // Given
    Semver currentVersion = new Semver("1.2.2");
    JsonObject allVersions = new JsonObject();
    allVersions.add("versions", new JsonArray());
    JsonObject versionElement = new JsonObject();
    versionElement.add("name", new JsonPrimitive("1.2"));
    versionElement.add("version", new JsonPrimitive(2));
    versionElement.add("latestPatchVersion", new JsonPrimitive(3));
    versionElement.add("patchVersions", new JsonArray());
    JsonObject patchElement = new JsonObject();
    patchElement.add("version", new JsonPrimitive(3));
    versionElement.getAsJsonArray("patchVersions").add(patchElement);
    allVersions.getAsJsonArray("versions").add(versionElement);
    // When
    List<JsonElement> newerPatchVersions = SystemUpdateService.extractNewerPatchVersions(currentVersion, allVersions);
    // Then
    assertNotNull(newerPatchVersions);
    assertEquals(1, newerPatchVersions.size());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Semver(com.vdurmont.semver4j.Semver) Test(org.junit.jupiter.api.Test)

Aggregations

Semver (com.vdurmont.semver4j.Semver)22 JsonElement (com.google.gson.JsonElement)5 Map (java.util.Map)5 JsonObject (com.google.gson.JsonObject)4 Test (org.junit.Test)4 GHRelease (org.kohsuke.github.GHRelease)4 GHRepository (org.kohsuke.github.GHRepository)4 GitHub (org.kohsuke.github.GitHub)4 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonArray (com.google.gson.JsonArray)2 Requirement (com.vdurmont.semver4j.Requirement)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2