♻️ Turn plugin year into instance method
[Sone.git] / src / main / java / net / pterodactylus / sone / main / SonePlugin.java
index ffaad9f..82a0217 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - SonePlugin.java - Copyright © 2010–2013 David Roden
+ * Sone - SonePlugin.java - Copyright © 2010–2019 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,7 +26,11 @@ import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
+import javax.inject.Singleton;
+
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.database.Database;
+import net.pterodactylus.sone.database.memory.MemoryDatabase;
 import net.pterodactylus.sone.fcp.FcpInterface;
 import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend;
 import net.pterodactylus.sone.freenet.wot.Context;
@@ -54,7 +58,6 @@ import com.google.inject.spi.TypeListener;
 import freenet.client.async.PersistenceDisabledException;
 import freenet.l10n.BaseL10n.LANGUAGE;
 import freenet.l10n.PluginL10n;
-import freenet.node.Node;
 import freenet.pluginmanager.FredPlugin;
 import freenet.pluginmanager.FredPluginBaseL10n;
 import freenet.pluginmanager.FredPluginFCP;
@@ -69,8 +72,6 @@ import freenet.support.api.Bucket;
 /**
  * This class interfaces with Freenet. It is the class that is loaded by the
  * node and starts up the whole Sone system.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, FredPluginBaseL10n, FredPluginThreadless, FredPluginVersioned {
 
@@ -115,13 +116,10 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                });
        }
 
-       /** The version. */
-       public static final Version VERSION = new Version(0, 9, 3);
-
        /** The current year at time of release. */
-       private static final int YEAR = 2015;
+       private static final int YEAR = 2017;
        private static final String SONE_HOMEPAGE = "USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/";
-       private static final int LATEST_EDITION = 70;
+       private static final int LATEST_EDITION = 77;
 
        /** The logger. */
        private static final Logger logger = getLogger(SonePlugin.class.getName());
@@ -175,7 +173,12 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                return l10n;
        }
 
-       public static int getYear() {
+       public static String getPluginVersion() {
+               net.pterodactylus.sone.main.Version version = VersionParserKt.getParsedVersion();
+               return (version == null) ? "unknown" : version.getNice();
+       }
+
+       public int getYear() {
                return YEAR;
        }
 
@@ -183,6 +186,10 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                return SONE_HOMEPAGE + LATEST_EDITION;
        }
 
+       public static long getLatestEdition() {
+               return LATEST_EDITION;
+       }
+
        //
        // FREDPLUGIN METHODS
        //
@@ -230,15 +237,8 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                final EventBus eventBus = new EventBus();
 
                /* Freenet injector configuration. */
-               AbstractModule freenetModule = new AbstractModule() {
+               FreenetModule freenetModule =  new FreenetModule(pluginRespirator);
 
-                       @Override
-                       @SuppressWarnings("synthetic-access")
-                       protected void configure() {
-                               bind(PluginRespirator.class).toInstance(SonePlugin.this.pluginRespirator);
-                               bind(Node.class).toInstance(SonePlugin.this.pluginRespirator.getNode());
-                       }
-               };
                /* Sone injector configuration. */
                AbstractModule soneModule = new AbstractModule() {
 
@@ -250,6 +250,17 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
                                bind(Context.class).toInstance(context);
                                bind(getOptionalContextTypeLiteral()).toInstance(of(context));
                                bind(SonePlugin.class).toInstance(SonePlugin.this);
+                               bind(Version.class).toInstance(Version.parse(getVersion()));
+                               bind(PluginVersion.class).toInstance(new PluginVersion(getVersion()));
+                               bind(PluginYear.class).toInstance(new PluginYear(getYear()));
+                               bind(PluginHomepage.class).toInstance(new PluginHomepage(getHomepage()));
+                               bind(Database.class).to(MemoryDatabase.class).in(Singleton.class);
+                               if (startConfiguration.getBooleanValue("Developer.LoadFromFilesystem").getValue(false)) {
+                                       String path = startConfiguration.getStringValue("Developer.FilesystemPath").getValue(null);
+                                       if (path != null) {
+                                               bind(Loaders.class).toInstance(new DebugLoaders(path));
+                                       }
+                               }
                                bindListener(Matchers.any(), new TypeListener() {
 
                                        @Override
@@ -394,7 +405,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr
         */
        @Override
        public String getVersion() {
-               return VERSION.toString();
+               return getPluginVersion();
        }
 
 }