@Test public void shouldGetAllChangesIncludingPrereleaseWhenRunningFinal() throws Exception { when(webAccessMock.callUrl(eq("http:/127.0.0.1:7070/changelog"))).thenReturn( objectMapper.writeValueAsString(Arrays.asList( new ChangelogVersionEntry("2.0.1", null, false, Arrays.asList(new ChangelogChangeEntry("note", "this is a newer prerelease"))), new ChangelogVersionEntry("2.0.0", null, true, Arrays.asList(new ChangelogChangeEntry("note", "Next final release"))), new ChangelogVersionEntry("1.0.1", null, false, Arrays.asList(new ChangelogChangeEntry("note", "A betal release"))), new ChangelogVersionEntry("1.0.0", null, true, Arrays.asList(new ChangelogChangeEntry("note", "Initial final release"))) ))); List<ChangelogVersionEntry> changesSince = testee.getChangesSinceCurrentVersion(); assertEquals(2, changesSince.size()); assertEquals("2.0.0", changesSince.get(0).getVersion()); assertEquals("1.0.1", changesSince.get(1).getVersion()); }
public List<ChangelogVersionEntry> getChangesSinceCurrentVersion() throws UpdateException { if (latestVersion == null) { getLatestVersion(); } List<ChangelogVersionEntry> allChanges; try { String response = webAccess.callUrl(changelogUrl); allChanges = objectMapper.readValue(response, new TypeReference<List<ChangelogVersionEntry>>() { }); } catch (IOException e) { throw new UpdateException("Error while getting changelog: " + e.getMessage()); } final Optional<ChangelogVersionEntry> newestFinalUpdate = allChanges.stream().filter(x -> x.isFinal() && new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)).max(Comparator.naturalOrder()); List<ChangelogVersionEntry> collectedVersionChanges = allChanges.stream().filter(x -> { if (!new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)) { return false; } if (x.isFinal()) { return true; } else { if (configProvider.getBaseConfig().getMain().isUpdateToPrereleases()) { return true; } else { return newestFinalUpdate.isPresent() && newestFinalUpdate.get().getSemanticVersion().isUpdateFor(x.getSemanticVersion()); } } } ).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); return collectedVersionChanges.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); }
UpdateManager implements InitializingBean { public List<ChangelogVersionEntry> getChangesSinceCurrentVersion() throws UpdateException { if (latestVersion == null) { getLatestVersion(); } List<ChangelogVersionEntry> allChanges; try { String response = webAccess.callUrl(changelogUrl); allChanges = objectMapper.readValue(response, new TypeReference<List<ChangelogVersionEntry>>() { }); } catch (IOException e) { throw new UpdateException("Error while getting changelog: " + e.getMessage()); } final Optional<ChangelogVersionEntry> newestFinalUpdate = allChanges.stream().filter(x -> x.isFinal() && new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)).max(Comparator.naturalOrder()); List<ChangelogVersionEntry> collectedVersionChanges = allChanges.stream().filter(x -> { if (!new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)) { return false; } if (x.isFinal()) { return true; } else { if (configProvider.getBaseConfig().getMain().isUpdateToPrereleases()) { return true; } else { return newestFinalUpdate.isPresent() && newestFinalUpdate.get().getSemanticVersion().isUpdateFor(x.getSemanticVersion()); } } } ).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); return collectedVersionChanges.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); } }
UpdateManager implements InitializingBean { public List<ChangelogVersionEntry> getChangesSinceCurrentVersion() throws UpdateException { if (latestVersion == null) { getLatestVersion(); } List<ChangelogVersionEntry> allChanges; try { String response = webAccess.callUrl(changelogUrl); allChanges = objectMapper.readValue(response, new TypeReference<List<ChangelogVersionEntry>>() { }); } catch (IOException e) { throw new UpdateException("Error while getting changelog: " + e.getMessage()); } final Optional<ChangelogVersionEntry> newestFinalUpdate = allChanges.stream().filter(x -> x.isFinal() && new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)).max(Comparator.naturalOrder()); List<ChangelogVersionEntry> collectedVersionChanges = allChanges.stream().filter(x -> { if (!new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)) { return false; } if (x.isFinal()) { return true; } else { if (configProvider.getBaseConfig().getMain().isUpdateToPrereleases()) { return true; } else { return newestFinalUpdate.isPresent() && newestFinalUpdate.get().getSemanticVersion().isUpdateFor(x.getSemanticVersion()); } } } ).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); return collectedVersionChanges.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); } UpdateManager(); }
UpdateManager implements InitializingBean { public List<ChangelogVersionEntry> getChangesSinceCurrentVersion() throws UpdateException { if (latestVersion == null) { getLatestVersion(); } List<ChangelogVersionEntry> allChanges; try { String response = webAccess.callUrl(changelogUrl); allChanges = objectMapper.readValue(response, new TypeReference<List<ChangelogVersionEntry>>() { }); } catch (IOException e) { throw new UpdateException("Error while getting changelog: " + e.getMessage()); } final Optional<ChangelogVersionEntry> newestFinalUpdate = allChanges.stream().filter(x -> x.isFinal() && new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)).max(Comparator.naturalOrder()); List<ChangelogVersionEntry> collectedVersionChanges = allChanges.stream().filter(x -> { if (!new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)) { return false; } if (x.isFinal()) { return true; } else { if (configProvider.getBaseConfig().getMain().isUpdateToPrereleases()) { return true; } else { return newestFinalUpdate.isPresent() && newestFinalUpdate.get().getSemanticVersion().isUpdateFor(x.getSemanticVersion()); } } } ).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); return collectedVersionChanges.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); } UpdateManager(); boolean isUpdateAvailable(); boolean latestVersionFinalOrPreEnabled(); boolean latestVersionIgnored(); boolean latestVersionBlocked(); String getLatestVersionString(); String getCurrentVersionString(); void ignore(String version); List<ChangelogVersionEntry> getChangesSinceCurrentVersion(); List<ChangelogVersionEntry> getAllVersionChangesUpToCurrentVersion(); List<ChangelogVersionEntry> getAutomaticUpdateVersionHistory(); void installUpdate(boolean isAutomaticUpdate); void exitWithReturnCode(final int returnCode); @Override void afterPropertiesSet(); PackageInfo getPackageInfo(); }
UpdateManager implements InitializingBean { public List<ChangelogVersionEntry> getChangesSinceCurrentVersion() throws UpdateException { if (latestVersion == null) { getLatestVersion(); } List<ChangelogVersionEntry> allChanges; try { String response = webAccess.callUrl(changelogUrl); allChanges = objectMapper.readValue(response, new TypeReference<List<ChangelogVersionEntry>>() { }); } catch (IOException e) { throw new UpdateException("Error while getting changelog: " + e.getMessage()); } final Optional<ChangelogVersionEntry> newestFinalUpdate = allChanges.stream().filter(x -> x.isFinal() && new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)).max(Comparator.naturalOrder()); List<ChangelogVersionEntry> collectedVersionChanges = allChanges.stream().filter(x -> { if (!new SemanticVersion(x.getVersion()).isUpdateFor(currentVersion)) { return false; } if (x.isFinal()) { return true; } else { if (configProvider.getBaseConfig().getMain().isUpdateToPrereleases()) { return true; } else { return newestFinalUpdate.isPresent() && newestFinalUpdate.get().getSemanticVersion().isUpdateFor(x.getSemanticVersion()); } } } ).sorted(Comparator.reverseOrder()).collect(Collectors.toList()); return collectedVersionChanges.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); } UpdateManager(); boolean isUpdateAvailable(); boolean latestVersionFinalOrPreEnabled(); boolean latestVersionIgnored(); boolean latestVersionBlocked(); String getLatestVersionString(); String getCurrentVersionString(); void ignore(String version); List<ChangelogVersionEntry> getChangesSinceCurrentVersion(); List<ChangelogVersionEntry> getAllVersionChangesUpToCurrentVersion(); List<ChangelogVersionEntry> getAutomaticUpdateVersionHistory(); void installUpdate(boolean isAutomaticUpdate); void exitWithReturnCode(final int returnCode); @Override void afterPropertiesSet(); PackageInfo getPackageInfo(); static final int SHUTDOWN_RETURN_CODE; static final int UPDATE_RETURN_CODE; static final int RESTART_RETURN_CODE; static final int RESTORE_RETURN_CODE; static final String KEY; }