Don’t expose the plugin version directly
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 20 Sep 2016 17:02:05 +0000 (19:02 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 20 Sep 2016 17:02:05 +0000 (19:02 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/main/java/net/pterodactylus/sone/fcp/VersionCommand.java
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/main/java/net/pterodactylus/sone/web/AboutPage.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java
src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java

index 3b958f1..91825a6 100644 (file)
@@ -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);
index 46558ab..7cea6fd 100644 (file)
@@ -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);
index b887926..ee0f2e5 100644 (file)
@@ -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());
        }
 
 }
index bff0a49..f3e8dfc 100644 (file)
@@ -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;
        }
index 76a475f..d201e0b 100644 (file)
@@ -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;
index b3e7a6a..203a87d 100644 (file)
@@ -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());
index 271111e..b7e3287 100644 (file)
@@ -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)));
index d0cba79..65d3943 100644 (file)
@@ -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());
index 552746e..1572191 100644 (file)
@@ -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"));
        }