Search in sources :

Example 1 with Semver

use of com.vdurmont.semver4j.Semver in project cas by apereo.

the class SystemUtils method injectUpdateInfoIntoBannerIfNeeded.

@SneakyThrows
private static void injectUpdateInfoIntoBannerIfNeeded(final Map<String, Object> info) {
    final Properties properties = System.getProperties();
    if (!properties.containsKey("CAS_UPDATE_CHECK_ENABLED")) {
        return;
    }
    final URL url = new URL(UPDATE_CHECK_MAVEN_URL);
    final Map results = MAPPER.readValue(url, Map.class);
    if (!results.containsKey("response")) {
        return;
    }
    final Map response = (Map) results.get("response");
    if (!response.containsKey("numFound") && (int) response.get("numFound") != 1) {
        return;
    }
    final List docs = (List) response.get("docs");
    if (docs.isEmpty()) {
        return;
    }
    final Map entry = (Map) docs.get(0);
    final String latestVersion = (String) entry.get("latestVersion");
    if (StringUtils.isNotBlank(latestVersion)) {
        final String currentVersion = CasVersion.getVersion();
        final Semver latestSem = new Semver(latestVersion);
        final Semver currentSem = new Semver(currentVersion);
        if (currentSem.isLowerThan(latestSem)) {
            final String updateString = String.format("[Latest Version: %s / Stable: %s]", latestVersion, StringUtils.capitalize(BooleanUtils.toStringYesNo(latestSem.isStable())));
            info.put("Update Availability", updateString);
        }
    }
}
Also used : List(java.util.List) Properties(java.util.Properties) Semver(com.vdurmont.semver4j.Semver) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) URL(java.net.URL) SneakyThrows(lombok.SneakyThrows)

Example 2 with Semver

use of com.vdurmont.semver4j.Semver in project mule by mulesoft.

the class BundleDescriptorUtils method isCompatibleVersion.

/**
 * Determines if a version is compatible with another one
 *
 * @param availableVersion version that is available to use. Non empty
 * @param expectedVersion version that is expected. Non empty
 * @return true if versions are compatible, false otherwise
 */
public static boolean isCompatibleVersion(String availableVersion, String expectedVersion) {
    checkArgument(!isEmpty(availableVersion), "availableVersion cannot be empty");
    checkArgument(!isEmpty(expectedVersion), "expectedVersion cannot be empty");
    if (availableVersion.equals(expectedVersion)) {
        return true;
    }
    Semver available = getBundleVersion(availableVersion);
    Semver expected = getBundleVersion(expectedVersion);
    if (available.isGreaterThan(expected)) {
        return available.getMajor().equals(expected.getMajor());
    }
    return false;
}
Also used : Semver(com.vdurmont.semver4j.Semver)

Example 3 with Semver

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

the class SystemUpdateService method sendMessageForEachVersion.

public void sendMessageForEachVersion(Map<Semver, Map<String, String>> patchVersions) {
    Set<User> recipients = getRecipients();
    for (Map.Entry<Semver, Map<String, String>> entry : patchVersions.entrySet()) {
        Semver version = entry.getKey();
        Map<String, String> message = entry.getValue();
        for (User recipient : recipients) {
            // Check if message has been sent before using
            // version.getValue() as extMessageId
            List<MessageConversation> existingMessages = messageService.getMatchingExtId(version.getValue());
            if (existingMessages.isEmpty()) {
                MessageConversationParams params = new MessageConversationParams.Builder().withRecipients(ImmutableSet.of(recipient)).withSubject(NEW_VERSION_AVAILABLE_MESSAGE_SUBJECT).withText(buildMessageText(message)).withMessageType(MessageType.SYSTEM).withExtMessageId(version.getValue()).build();
                messageService.sendMessage(params);
            }
        }
    }
}
Also used : User(org.hisp.dhis.user.User) MessageConversationParams(org.hisp.dhis.message.MessageConversationParams) MessageConversation(org.hisp.dhis.message.MessageConversation) Semver(com.vdurmont.semver4j.Semver) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with Semver

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

the class SystemUpdateService method convertJsonToMap.

/**
 * Converts a list of json elements representing patch versions, into a map
 * of: SemVer (parsed version) and a map of strings representing the message
 * to send to the admin user(s).
 */
protected static Map<Semver, Map<String, String>> convertJsonToMap(List<JsonElement> patchVersions) {
    Map<Semver, Map<String, String>> versionsAndMessage = new TreeMap<>();
    for (JsonElement patchVersion : patchVersions) {
        JsonObject patchJsonObject = patchVersion.getAsJsonObject();
        String version = patchJsonObject.getAsJsonPrimitive(FIELD_NAME_NAME).getAsString();
        Map<String, String> message = new HashMap<>();
        message.put(FIELD_NAME_VERSION, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_NAME).getAsString());
        message.put(FIELD_NAME_RELEASE_DATE, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_RELEASE_DATE).getAsString());
        message.put(FIELD_NAME_DOWNLOAD_URL, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_URL).getAsString());
        versionsAndMessage.put(new Semver(version), message);
    }
    return versionsAndMessage;
}
Also used : HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Semver(com.vdurmont.semver4j.Semver) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with Semver

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

the class SystemSoftwareUpdateNotifyController method checkSystemUpdate.

@GetMapping(SystemSoftwareUpdateNotifyController.RESOURCE_PATH)
@ResponseBody
public WebMessage checkSystemUpdate(@RequestParam(value = "forceVersion", required = false) String forceVersion) throws Exception {
    Semver currentVersion = SystemUpdateService.getCurrentVersion();
    if (forceVersion != null) {
        currentVersion = new Semver(forceVersion);
    }
    Map<Semver, Map<String, String>> newerVersions = SystemUpdateService.getLatestNewerThan(currentVersion);
    systemUpdateService.sendMessageForEachVersion(newerVersions);
    WebMessage ok = WebMessageUtils.ok();
    ok.setResponse(new SoftwareUpdateResponse(newerVersions));
    return ok;
}
Also used : Semver(com.vdurmont.semver4j.Semver) Map(java.util.Map) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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