diff --git a/core/resources/build.properties b/core/resources/build.properties index 16395f062..af4f46bbd 100644 --- a/core/resources/build.properties +++ b/core/resources/build.properties @@ -1,6 +1,6 @@ # The OpenRocket build version -build.version=23.09 +build.version=23.09.SNAPSHOT # The copyright year for the build. Displayed in the about dialog. # Will show as Copyright 2013-${build.copyright} diff --git a/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java b/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java index 96ede4c05..41eb4ec1b 100644 --- a/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java +++ b/core/src/net/sf/openrocket/communication/UpdateInfoRetriever.java @@ -39,6 +39,8 @@ public class UpdateInfoRetriever { { "RC", 3 }, // Release Candidate }).collect(Collectors.toMap(c -> (String) c[0], c -> (Integer) c[1])); + public static final String snapshotTag = "SNAPSHOT"; + /* Enum for the current build version. Values: OLDER: current build version is older than the latest official release LATEST: current build is the latest official release @@ -280,7 +282,7 @@ public class UpdateInfoRetriever { public static List filterOfficialRelease(List names) { if (names == null) return null; return names.stream().filter(c -> Arrays.stream(devTags.keySet().toArray(new String[0])) - .noneMatch(c::contains)).collect(Collectors.toList()); + .noneMatch(c::contains) && !c.contains(snapshotTag)).collect(Collectors.toList()); } /** @@ -358,8 +360,8 @@ public class UpdateInfoRetriever { // If the loop is still going until this condition, you have the situation where tag1 is e.g. // '15.03' and tag2 '15.03.01', so tag is in that case the more recent version. if (i >= tag1Split.length) { - // Tag 1 is e.g. '15.03' and tag2 '15.03.01', so tag2 is the more recent version - if (tag2Split[i].matches("\\d+")) { + // Tag 1 is e.g. '15.03' and tag2 '15.03.01' or '15.03.SNAPSHOT', so tag2 is the more recent version + if (tag2Split[i].matches("\\d+") || snapshotTag.equals(tag2Split[i])) { return ReleaseStatus.OLDER; } // Tag 1 is e.g. '15.03' and tag2 '15.03.beta.01', so tag1 is the more recent version (it's an official release) @@ -392,6 +394,30 @@ public class UpdateInfoRetriever { continue; } + // Handle snapshots + if (snapshotTag.equals(tag1Split[i]) || snapshotTag.equals(tag2Split[i])) { + // In case when e.g. tag1 is '23.09.SNAPSHOT.02' and tag2 '23.09.SNAPSHOT.01', go to the next loop to compare '01' and '02' + if (snapshotTag.equals(tag1Split[i]) && snapshotTag.equals(tag2Split[i])) { + continue; + } + // In case when e.g. tag1 is '23.09.SNAPSHOT' and tag2 '23.09', tag1 is newer + else if (snapshotTag.equals(tag1Split[i])) { + // E.g. tag1 is '23.09.SNAPSHOT', tag2 is '23.09.01' + if (tag2Split[i].matches("\\d+")) { + return ReleaseStatus.OLDER; + } else { + return ReleaseStatus.NEWER; + } + } else { + // E.g. tag1 is '23.09.01', tag2 is '23.09.SNAPSHOT' + if (tag1Split[i].matches("\\d+")) { + return ReleaseStatus.NEWER; + } else { + return ReleaseStatus.OLDER; + } + } + } + // In case tag1 is e.g. '20.alpha.01', but tag2 is already an official release with a number instead of // a text, e.g. '20.01' if (tag2Split[i].matches("\\d+")) { @@ -445,7 +471,7 @@ public class UpdateInfoRetriever { log.warn(message); throw new UpdateCheckerException(message); } - if (!devTags.containsKey(tagSplit[i])) { + if (!devTags.containsKey(tagSplit[i]) && !snapshotTag.equals(tagSplit[i])) { String message = String.format("Malformed release tag: '%s'", String.join(".", tagSplit)); log.warn(message); throw new UpdateCheckerException(message); diff --git a/core/test/net/sf/openrocket/communication/UpdateInfoTest.java b/core/test/net/sf/openrocket/communication/UpdateInfoTest.java index e6b03316d..8ee7671e1 100644 --- a/core/test/net/sf/openrocket/communication/UpdateInfoTest.java +++ b/core/test/net/sf/openrocket/communication/UpdateInfoTest.java @@ -215,6 +215,30 @@ public class UpdateInfoTest extends BaseTestCase { assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("22.02.RC.01", "22.02.02")); + // Test snapshots + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09", "23.09.SNAPSHOT")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.LATEST, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT", "23.09.SNAPSHOT")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT", "23.09")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("24.01", "23.09.SNAPSHOT")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT", "24.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("24.01.SNAPSHOT", "23.09")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT.01", "23.09.SNAPSHOT.02")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.LATEST, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT.02", "23.09.SNAPSHOT.02")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT.02", "23.09.SNAPSHOT.01")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.NEWER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.01", "23.09.SNAPSHOT")); + assertEquals(UpdateInfoRetriever.ReleaseStatus.OLDER, + UpdateInfoRetriever.UpdateInfoFetcher.compareLatest("23.09.SNAPSHOT", "23.09.01")); + // Test bogus releases assertExceptionCompareLatest("22.02.gamma.01", "22.02"); diff --git a/core/test/net/sf/openrocket/communication/WelcomeInfoTest.java b/core/test/net/sf/openrocket/communication/WelcomeInfoTest.java index aeb4f75d7..e7cb6d324 100644 --- a/core/test/net/sf/openrocket/communication/WelcomeInfoTest.java +++ b/core/test/net/sf/openrocket/communication/WelcomeInfoTest.java @@ -1,8 +1,10 @@ package net.sf.openrocket.communication; import net.sf.openrocket.util.BaseTestCase.BaseTestCase; +import net.sf.openrocket.util.BuildProperties; import org.junit.Test; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -12,12 +14,15 @@ public class WelcomeInfoTest extends BaseTestCase { @Test public void testWelcomeInfo() throws Exception { // Test the welcome info for the current build version - String welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo(); - assertNotNull("Current release version not present in release notes", welcomeInfo); - assertTrue("Body of release notes is empty", welcomeInfo.length() > 0); + String version = BuildProperties.getVersion(); + if (!version.contains(UpdateInfoRetriever.snapshotTag)) { // Ignore snapshot releases; they don't need release notes + String welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo(); + assertNotNull("Current release version not present in release notes", welcomeInfo); + assertFalse("Body of release notes is empty", welcomeInfo.isEmpty()); + } // Test the release info for a bogus release version - welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo("bogus release"); + String welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo("bogus release"); assertNull(welcomeInfo); } }