Search in sources :

Example 11 with Semver

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

the class UpdateUtils method isAvailable.

public static boolean isAvailable() {
    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 false;
        } else {
            Logger.info("detected new version");
            Logger.info("current version: " + CONSTANTS.VERSION);
            Logger.info("latest version: " + latest.getTagName().replaceAll("v", ""));
            return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : GHRepository(org.kohsuke.github.GHRepository) GitHub(org.kohsuke.github.GitHub) IOException(java.io.IOException) Semver(com.vdurmont.semver4j.Semver) GHRelease(org.kohsuke.github.GHRelease)

Example 12 with Semver

use of com.vdurmont.semver4j.Semver in project syndesis-qe by syndesisio.

the class UpgradeSteps method getPreviousVersion.

private String getPreviousVersion(String current, List<String> tags) {
    // Semver needs 1.2.3 version style, so add ".0" if it's missing
    if (current.matches("^\\d\\.\\d+")) {
        current += ".0";
    }
    Semver currentVersion = new Semver(current);
    // Find previous version by incrementing until the next one is equal to current
    Semver increment = new Semver("1.0.0");
    String previousVersion = "";
    // Max minor version in one version
    int maxMinor = 20;
    while (!currentVersion.equals(increment)) {
        // For lambda to be final
        Semver finalIncrement = increment;
        // Check if this tag exists, an if yes, use the "latest" as the version
        String previousTag = tags.stream().filter(t -> t.matches("^" + getMajorMinor(finalIncrement.toString()).replaceAll("\\.", "\\\\.") + "(\\.\\d+)?$")).reduce((first, second) -> second).orElse(null);
        // If this tag exists, save it
        if (previousTag != null) {
            previousVersion = previousTag;
        }
        increment = increment.getMinor() == maxMinor ? increment.nextMajor() : increment.withIncMinor();
    }
    log.info("Previous version for {} is {}", current, previousVersion);
    return previousVersion;
}
Also used : Then(io.cucumber.java.en.Then) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TimeoutException(java.util.concurrent.TimeoutException) StringUtils(org.apache.commons.lang3.StringUtils) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) IntegrationsEndpoint(io.syndesis.qe.endpoint.IntegrationsEndpoint) Semver(com.vdurmont.semver4j.Semver) Syndesis(io.syndesis.qe.resource.impl.Syndesis) InfraFail(io.syndesis.qe.test.InfraFail) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) When(io.cucumber.java.en.When) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) PreviousSyndesis(io.syndesis.qe.resource.impl.PreviousSyndesis) HTTPUtils(io.syndesis.qe.utils.http.HTTPUtils) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) TestUtils(io.syndesis.qe.utils.TestUtils) SampleDbConnectionManager(io.syndesis.qe.utils.SampleDbConnectionManager) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) SYNDESIS_DOCKER_REGISTRY(io.syndesis.qe.TestConfiguration.SYNDESIS_DOCKER_REGISTRY) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) Semver(com.vdurmont.semver4j.Semver) IntegrationsEndpoint(io.syndesis.qe.endpoint.IntegrationsEndpoint)

Example 13 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) GHRelease(org.kohsuke.github.GHRelease)

Example 14 with Semver

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

the class SemverSerializerTest method successfullySerializesVersion.

@Test
public void successfullySerializesVersion() throws JsonProcessingException {
    final Semver version = new Semver("1.3.7-rc.2+build.2.b8f12d7");
    final String s = objectMapper.writeValueAsString(version);
    assertThat(s).isEqualTo("\"1.3.7-rc.2+build.2.b8f12d7\"");
}
Also used : Semver(com.vdurmont.semver4j.Semver) Test(org.junit.Test)

Example 15 with Semver

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

the class SemverDeserializerTest method successfullyDeserializesNull.

@Test
public void successfullyDeserializesNull() throws IOException {
    final Semver version = objectMapper.readValue("null", Semver.class);
    assertThat(version).isNull();
}
Also used : Semver(com.vdurmont.semver4j.Semver) Test(org.junit.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