From f9b5addb5d0e7a080e9f314cf6712143f5e26060 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 20 Sep 2016 19:02:05 +0200 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20expose=20the=20plugin=20version?= =?utf8?q?=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 2 +- src/main/java/net/pterodactylus/sone/core/SoneInserter.java | 2 +- src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java | 2 +- src/main/java/net/pterodactylus/sone/main/SonePlugin.java | 6 +++++- src/main/java/net/pterodactylus/sone/web/AboutPage.java | 4 ++-- src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java | 2 +- src/main/java/net/pterodactylus/sone/web/WebInterface.java | 2 +- .../net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java | 2 +- src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 3b958f1..91825a6 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -643,7 +643,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, Sone sone = database.newSoneBuilder().local().from(ownIdentity).build(); String property = fromNullable(ownIdentity.getProperty("Sone.LatestEdition")).or("0"); sone.setLatestEdition(fromNullable(tryParse(property)).or(0L)); - sone.setClient(new Client("Sone", SonePlugin.VERSION.toString())); + sone.setClient(new Client("Sone", SonePlugin.getPluginVersion())); sone.setKnown(true); SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId()); eventBus.register(soneInserter); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index 46558ab..7cea6fd 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -393,7 +393,7 @@ public class SoneInserter extends AbstractService { templateContext.set("core", core); templateContext.set("currentSone", soneProperties); templateContext.set("currentEdition", core.getUpdateChecker().getLatestEdition()); - templateContext.set("version", SonePlugin.VERSION); + templateContext.set("version", SonePlugin.getPluginVersion()); StringWriter writer = new StringWriter(); try { template.render(templateContext, writer); diff --git a/src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java b/src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java index b887926..ee0f2e5 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java @@ -45,7 +45,7 @@ public class VersionCommand extends AbstractSoneCommand { */ @Override public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) { - return new Response("Version", new SimpleFieldSetBuilder().put("Version", SonePlugin.VERSION.toString()).put("ProtocolVersion", 1).get()); + return new Response("Version", new SimpleFieldSetBuilder().put("Version", SonePlugin.getPluginVersion()).put("ProtocolVersion", 1).get()); } } diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index bff0a49..f3e8dfc 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -116,7 +116,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr } /** The version. */ - public static final Version VERSION = new Version(0, 9, 5); + private static final Version VERSION = new Version(0, 9, 5); /** The current year at time of release. */ private static final int YEAR = 2016; @@ -175,6 +175,10 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr return l10n; } + public static String getPluginVersion() { + return VERSION.toString(); + } + public static int getYear() { return YEAR; } diff --git a/src/main/java/net/pterodactylus/sone/web/AboutPage.java b/src/main/java/net/pterodactylus/sone/web/AboutPage.java index 76a475f..d201e0b 100644 --- a/src/main/java/net/pterodactylus/sone/web/AboutPage.java +++ b/src/main/java/net/pterodactylus/sone/web/AboutPage.java @@ -29,11 +29,11 @@ import net.pterodactylus.util.version.Version; */ public class AboutPage extends SoneTemplatePage { - private final Version version; + private final String version; private final int year; private final String homepage; - public AboutPage(Template template, WebInterface webInterface, Version version, int year, String homepage) { + public AboutPage(Template template, WebInterface webInterface, String version, int year, String homepage) { super("about.html", template, "Page.About.Title", webInterface, false); this.version = version; this.year = year; diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index b3e7a6a..203a87d 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -243,7 +243,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { templateContext.set("currentSone", currentSone); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); - templateContext.set("currentVersion", SonePlugin.VERSION); + templateContext.set("currentVersion", SonePlugin.getPluginVersion()); templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion()); templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 271111e..b7e3287 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -717,7 +717,7 @@ public class WebInterface { pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout")); pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options")); pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue")); - pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION, SonePlugin.getYear(), SonePlugin.getHomepage()), "About")); + pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.getPluginVersion(), SonePlugin.getYear(), SonePlugin.getHomepage()), "About")); pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java index d0cba79..65d3943 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java @@ -113,7 +113,7 @@ public class GetNotificationsAjaxPage extends JsonPage { templateContext.set("currentSone", webInterface.getCurrentSone(request.getToadletContext(), false)); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); - templateContext.set("currentVersion", SonePlugin.VERSION); + templateContext.set("currentVersion", SonePlugin.getPluginVersion()); templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion()); templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); diff --git a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java index 552746e..1572191 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java @@ -260,7 +260,7 @@ public class SoneInserterTest { assertThat(manifestElement.getName(), is("test.txt")); assertThat(manifestElement.getMimeTypeOverride(), is("plain/text; charset=utf-8")); String templateContent = new String(toByteArray(manifestElement.getData().getInputStream()), Charsets.UTF_8); - assertThat(templateContent, containsString("Sone Version: " + SonePlugin.VERSION.toString() + "\n")); + assertThat(templateContent, containsString("Sone Version: " + SonePlugin.getPluginVersion() + "\n")); assertThat(templateContent, containsString("Core Startup: " + now + "\n")); assertThat(templateContent, containsString("Sone ID: " + "SoneId" + "\n")); } -- 2.7.4