♻️ Turn plugin homepage into instance method
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 5 Mar 2019 10:06:02 +0000 (11:06 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 5 Mar 2019 14:20:58 +0000 (15:20 +0100)
src/main/java/net/pterodactylus/sone/core/UpdateChecker.java
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java

index 2c2f121..9f6963f 100644 (file)
@@ -31,6 +31,7 @@ import java.util.logging.Logger;
 import javax.inject.Singleton;
 
 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
+import net.pterodactylus.sone.main.PluginHomepage;
 import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.version.Version;
@@ -69,6 +70,8 @@ public class UpdateChecker {
        /** The release date of the latest version. */
        private long latestVersionDate;
 
+       private final PluginHomepage pluginHomepage;
+
        /**
         * Creates a new update checker.
         *
@@ -78,11 +81,12 @@ public class UpdateChecker {
         *            The freenet interface to use
         */
        @Inject
-       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface, Version currentVersion) {
+       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface, Version currentVersion, PluginHomepage pluginHomepage) {
                this.eventBus = eventBus;
                this.freenetInterface = freenetInterface;
                this.currentRunningVersion = currentVersion;
                this.currentLatestVersion = currentVersion;
+               this.pluginHomepage = pluginHomepage;
        }
 
        //
@@ -138,7 +142,7 @@ public class UpdateChecker {
         */
        public void start() {
                try {
-                       currentUri = new FreenetURI(SonePlugin.getHomepage());
+                       currentUri = new FreenetURI(pluginHomepage.getHomepage());
                } catch (MalformedURLException mue1) {
                        /* this can not really happen unless I screw up. */
                        logger.log(Level.SEVERE, "Sone Homepage URI invalid!", mue1);
index 82a0217..f9bbe05 100644 (file)
@@ -182,7 +182,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                return YEAR;
        }
 
-       public static String getHomepage() {
+       public String getHomepage() {
                return SONE_HOMEPAGE + LATEST_EDITION;
        }
 
index 92e5034..125f496 100644 (file)
@@ -753,7 +753,7 @@ public class WebInterface implements SessionProvider {
                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, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(SonePlugin.getHomepage())), "About"));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage())), "About"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", this, noPermissionTemplate, "Page.NoPermission.Title")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", this, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", this, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title")));
index 663b709..e7f1afe 100644 (file)
@@ -18,6 +18,7 @@ import java.io.InputStream;
 
 import net.pterodactylus.sone.core.FreenetInterface.Callback;
 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
+import net.pterodactylus.sone.main.PluginHomepage;
 import net.pterodactylus.util.version.Version;
 
 import freenet.client.ClientMetadata;
@@ -41,7 +42,8 @@ public class UpdateCheckerTest {
        private final EventBus eventBus = mock(EventBus.class);
        private final FreenetInterface freenetInterface = mock(FreenetInterface.class);
        private final Version currentVersion = new Version(1, 0, 0);
-       private final UpdateChecker updateChecker = new UpdateChecker(eventBus, freenetInterface, currentVersion);
+       private final PluginHomepage pluginHomepage = new PluginHomepage("KSK@homepage");
+       private final UpdateChecker updateChecker = new UpdateChecker(eventBus, freenetInterface, currentVersion, pluginHomepage);
 
        @Before
        public void startUpdateChecker() {