This commit is contained in:
Eduard Heimbuch
2020-09-22 17:08:22 +02:00
parent 6014eea193
commit ff6aaf7bc5
3 changed files with 22 additions and 24 deletions

View File

@@ -73,7 +73,7 @@ public class ScmConfiguration implements Configuration {
* SCM Manager release feed url
*/
public static final String DEFAULT_RELEASE_FEED_URL =
"https://www.scm-manager.org/download/rss.xml";
"https://scm-manager.org/download/rss.xml";
/**
* Default url for login information (plugin and feature tips on the login page).

View File

@@ -44,16 +44,21 @@ public class ReleaseFeedParser {
this.client = client;
}
Optional<ReleaseInfo> findLatestRelease(String url) throws IOException {
Optional<ReleaseInfo> findLatestRelease(String url) {
LOG.info("Search for newer versions of SCM-Manager");
ReleaseFeedDto releaseFeed = client.get(url).request().contentFromXml(ReleaseFeedDto.class);
Optional<ReleaseFeedDto.Release> latestRelease = filterForLatestRelease(releaseFeed);
if (latestRelease.isPresent()) {
ReleaseFeedDto.Release release = latestRelease.get();
return Optional.of(new ReleaseInfo(release.getTitle(), release.getLink()));
Optional<ReleaseFeedDto.Release> latestRelease = parseLatestReleaseFromRssFeed(url);
return latestRelease.map(release -> new ReleaseInfo(release.getTitle(), release.getLink()));
}
private Optional<ReleaseFeedDto.Release> parseLatestReleaseFromRssFeed(String url) {
try {
ReleaseFeedDto releaseFeed = client.get(url).request().contentFromXml(ReleaseFeedDto.class);
return filterForLatestRelease(releaseFeed);
} catch (IOException e) {
LOG.error(String.format("Could not parse release feed from %s", url));
return Optional.empty();
}
}
private Optional<ReleaseFeedDto.Release> filterForLatestRelease(ReleaseFeedDto releaseFeed) {
return releaseFeed.getChannel().getReleases()

View File

@@ -34,7 +34,6 @@ import sonia.scm.config.ScmConfiguration;
import sonia.scm.version.Version;
import javax.inject.Inject;
import java.io.IOException;
import java.util.Optional;
public class ReleaseVersionChecker {
@@ -65,12 +64,11 @@ public class ReleaseVersionChecker {
if (cachedReleaseInfo != null) {
return Optional.of(cachedReleaseInfo);
} else {
return findLatestReleaseInRssFeed();
return findLatestRelease();
}
}
private Optional<ReleaseInfo> findLatestReleaseInRssFeed() {
try {
private Optional<ReleaseInfo> findLatestRelease() {
String releaseFeedUrl = scmConfiguration.getReleaseFeedUrl();
Optional<ReleaseInfo> latestRelease = releaseFeedParser.findLatestRelease(releaseFeedUrl);
if (latestRelease.isPresent() && isNewerVersion(latestRelease.get())) {
@@ -79,11 +77,6 @@ public class ReleaseVersionChecker {
}
LOG.info("No newer version found for SCM-Manager");
return Optional.empty();
} catch (IOException e) {
// This is a silent action. We don't want the user to get any kind of error for this.
LOG.info("No newer version found for SCM-Manager");
return Optional.empty();
}
}
private boolean isNewerVersion(ReleaseInfo releaseInfo) {