Search in sources :

Example 6 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)

Example 7 with Semver

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

the class PluginVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            boolean result = false;
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    result = true;
                }
            }
            ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, result);
            fulfilledConstraints.add(constraintCheckResult);
        }
    }
    return fulfilledConstraints.build();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Requirement(com.vdurmont.semver4j.Requirement) ImmutableSet(com.google.common.collect.ImmutableSet) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Semver(com.vdurmont.semver4j.Semver)

Example 8 with Semver

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

the class SemverDeserializerTest method successfullyDeserializesString.

@Test
public void successfullyDeserializesString() throws IOException {
    final Semver version = objectMapper.readValue("\"1.3.7-rc.2+build.2.b8f12d7\"", Semver.class);
    assertThat(version).isEqualTo(new Semver("1.3.7-rc.2+build.2.b8f12d7", Semver.SemverType.NPM));
}
Also used : Semver(com.vdurmont.semver4j.Semver) Test(org.junit.Test)

Example 9 with Semver

use of com.vdurmont.semver4j.Semver in project TOSCAna by StuPro-TOSCAna.

the class MapperEngine method determineTagFromMinorVersion.

/**
 *     Tries to determine the tag from the list of possible minor versions
 */
private String determineTagFromMinorVersion(List<DockerImageTag> possibleTags, Semver version) {
    DockerImageTag resultTag = null;
    int i = 0;
    DockerImageTag tag;
    Semver tagVersion;
    do {
        tag = possibleTags.get(i);
        tagVersion = tag.toVersion();
        if (tagVersion.getMinor() == version.getMinor()) {
            int j = i;
            DockerImageTag prev = null;
            DockerImageTag t = null;
            Semver tv;
            do {
                prev = t;
                t = possibleTags.get(j);
                tv = t.toVersion();
                j++;
            } while (tv.getMinor().equals(version.getMinor()) && j < possibleTags.size());
            resultTag = prev;
        }
        i++;
    } while (i < possibleTags.size());
    if (resultTag == null) {
        throw new UnsupportedOperationException("Mapping failed");
    }
    return resultTag.getName();
}
Also used : DockerImageTag(org.opentosca.toscana.plugins.kubernetes.docker.mapper.model.DockerImageTag) Semver(com.vdurmont.semver4j.Semver)

Example 10 with Semver

use of com.vdurmont.semver4j.Semver in project Robot by fo0.

the class UpdateUtils method doUpdate.

public static void doUpdate() {
    try {
        GitHub gitHub = GitHub.connectAnonymously();
        GHRepository repository = gitHub.getRepository(CONSTANTS.GITHUB_URI);
        GHRelease latest = repository.getLatestRelease();
        boolean newerVersionAvailable = new Semver(latest.getTagName().replaceAll("v", "")).isGreaterThan(new Semver(CONSTANTS.VERSION));
        if (!newerVersionAvailable) {
            Logger.info("no newer version available, skipping now");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return;
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
        }
        GHAsset asset = latest.getAssets().get(0);
        Logger.info("downloading file from github: " + asset.getBrowserDownloadUrl());
        File latestFile = File.createTempFile(Random.alphanumeric(10), ".patch");
        latestFile.deleteOnExit();
        FileUtils.copyToFile(new URL(asset.getBrowserDownloadUrl()).openStream(), latestFile);
        Logger.info("download finished");
        Logger.info("applying patch...");
        File currentPath = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
        Utils.writeBytesToFile(IOUtils.toByteArray(new FileInputStream(latestFile)), currentPath);
        // FileUtils.moveFile(latestFile, currentPath);
        try {
            latestFile.delete();
        } catch (Exception e) {
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) Semver(com.vdurmont.semver4j.Semver) File(java.io.File) GHAsset(org.kohsuke.github.GHAsset) URL(java.net.URL) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) GHRelease(org.kohsuke.github.GHRelease)

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