if (version.compareTo(currentLatestVersion) > 0) {
currentLatestVersion = version;
latestVersionDate = releaseTime;
- logger.log(Level.INFO, String.format("Found new version: %s (%tc)", version, new Date(releaseTime)));
- eventBus.post(new UpdateFoundEvent(version, releaseTime, edition));
+ boolean disruptive = disruptiveVersionBetweenCurrentAndFound(properties);
+ logger.log(Level.INFO, String.format("Found new version: %s (%tc%s)", version, new Date(releaseTime), disruptive ? ", disruptive" : ""));
+ eventBus.post(new UpdateFoundEvent(version, releaseTime, edition, disruptive));
}
}
+ private boolean disruptiveVersionBetweenCurrentAndFound(Properties properties) {
+ for (String key : properties.stringPropertyNames()) {
+ if (key.startsWith("DisruptiveVersion/")) {
+ Version disruptiveVersion = Version.parse(key.substring("DisruptiveVersion/".length()));
+ if (disruptiveVersion.compareTo(currentRunningVersion) > 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
}
*/
public class UpdateFoundEvent {
- /** The version that was found. */
private final Version version;
-
- /** The time the update was released. */
private final long releaseTime;
-
- /** The latest edition of the update page. */
private final long latestEdition;
+ private final boolean disruptive;
- /**
- * Creates a new “update found” event.
- *
- * @param version
- * The version of the update
- * @param releaseTime
- * The release time of the update
- * @param latestEdition
- * The latest edition of the update page
- */
- public UpdateFoundEvent(Version version, long releaseTime, long latestEdition) {
+ public UpdateFoundEvent(Version version, long releaseTime, long latestEdition, boolean disruptive) {
this.version = version;
this.releaseTime = releaseTime;
this.latestEdition = latestEdition;
+ this.disruptive = disruptive;
}
- //
- // ACCESSORS
- //
-
- /**
- * Returns the version of the update.
- *
- * @return The version of the update
- */
public Version version() {
return version;
}
- /**
- * Returns the release time of the update.
- *
- * @return The releae time of the update (in milliseconds since Jan 1, 1970
- * UTC)
- */
public long releaseTime() {
return releaseTime;
}
- /**
- * Returns the latest edition of the update page.
- *
- * @return The latest edition of the update page
- */
public long latestEdition() {
return latestEdition;
}
+ public boolean disruptive() {
+ return disruptive;
+ }
+
}
package net.pterodactylus.sone.core;
import static java.lang.Long.MAX_VALUE;
-import static net.pterodactylus.sone.main.SonePlugin.VERSION;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
setupFetchResult(createFutureFetchResult());
setupCallbackWithEdition(MAX_VALUE, true, false);
verifyAFreenetUriIsFetched();
- ArgumentCaptor<UpdateFoundEvent> updateFoundEvent = forClass(UpdateFoundEvent.class);
- verify(eventBus, times(1)).post(updateFoundEvent.capture());
- assertThat(updateFoundEvent.getValue().version(), is(new Version(99, 0, 0)));
- assertThat(updateFoundEvent.getValue().releaseTime(), is(11865368297000L));
- assertThat(updateChecker.getLatestVersion(), is(new Version(99, 0, 0)));
- assertThat(updateChecker.getLatestVersionDate(), is(11865368297000L));
- assertThat(updateChecker.hasLatestVersion(), is(true));
+ verifyEventIsFired(new Version(99, 0, 0), 11865368297000L, false);
+ verifyThatUpdateCheckerKnowsLatestVersion(new Version(99, 0, 0), 11865368297000L);
}
private FetchResult createFutureFetchResult() {
ClientMetadata clientMetadata = new ClientMetadata("application/xml");
Bucket fetched = new ArrayBucket(("# MapConfigurationBackendVersion=1\n" +
"CurrentVersion/Version: 99.0.0\n" +
- "CurrentVersion/ReleaseTime: 11865368297000").getBytes());
+ "CurrentVersion/ReleaseTime: 11865368297000\n" +
+ "DisruptiveVersion/0.1.2: true").getBytes());
return new FetchResult(clientMetadata, fetched);
}
+ private void verifyEventIsFired(Version version, long releaseTime, boolean disruptive) {
+ ArgumentCaptor<UpdateFoundEvent> updateFoundEvent = forClass(UpdateFoundEvent.class);
+ verify(eventBus, times(1)).post(updateFoundEvent.capture());
+ assertThat(updateFoundEvent.getValue().version(), is(version));
+ assertThat(updateFoundEvent.getValue().releaseTime(), is(releaseTime));
+ assertThat(updateFoundEvent.getValue().disruptive(), is(disruptive));
+ }
+
+ private void verifyThatUpdateCheckerKnowsLatestVersion(Version version, long releaseTime) {
+ assertThat(updateChecker.getLatestVersion(), is(version));
+ assertThat(updateChecker.getLatestVersionDate(), is(releaseTime));
+ assertThat(updateChecker.hasLatestVersion(), is(true));
+ }
+
@Test
public void callbackDoesNotStartIfNoNewEditionIsFound() {
setupFetchResult(createPastFetchResult());
return new FetchResult(clientMetadata, fetched);
}
+ @Test
+ public void disruptiveVersionGetsNotification() {
+ setupFetchResult(createDisruptiveVersionFetchResult());
+ setupCallbackWithEdition(MAX_VALUE, true, false);
+ verifyAFreenetUriIsFetched();
+ verifyEventIsFired(new Version(1, 2, 3), 1289417883000L, true);
+ verifyThatUpdateCheckerKnowsLatestVersion(new Version(1, 2, 3), 1289417883000L);
+ }
+
+ private FetchResult createDisruptiveVersionFetchResult() {
+ ClientMetadata clientMetadata = new ClientMetadata("application/xml");
+ Bucket fetched = new ArrayBucket(("# MapConfigurationBackendVersion=1\n" +
+ "CurrentVersion/Version: 1.2.3\n" +
+ "CurrentVersion/ReleaseTime: 1289417883000\n" +
+ "DisruptiveVersion/1.2.3: true").getBytes());
+ return new FetchResult(clientMetadata, fetched);
+ }
+
}