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;
}
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;
}
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();
}
}
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\"");
}
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();
}
Aggregations