From: David ‘Bombe’ Roden Date: Sun, 28 Jul 2019 13:53:11 +0000 (+0200) Subject: 🔥 Replace debug flag collection with simple flag X-Git-Tag: v81^2~171 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=49872c388489260aa2e4ecd42dfda1aaebb8d2db;p=Sone.git 🔥 Replace debug flag collection with simple flag --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index be4ce4e..e0bd804 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -37,6 +37,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -120,7 +121,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** The start time. */ private final long startupTime = System.currentTimeMillis(); - private final DebugInformation debugInformation = new DebugInformation(); + private final AtomicBoolean debug = new AtomicBoolean(false); /** The preferences. */ private final Preferences preferences; @@ -230,8 +231,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } @Nonnull - public DebugInformation getDebugInformation() { - return debugInformation; + public boolean getDebug() { + return debug.get(); } /** diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index a439e4b..ee1bd1e 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -616,7 +616,7 @@ public class WebInterface implements SessionProvider { pageToadletRegistry.addPage(new EmptyImageTitlePage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new EmptyAlbumTitlePage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new DismissNotificationPage(this, loaders, templateRenderer)); - if (getCore().getDebugInformation().getShowMetrics()) { + if (getCore().getDebug()) { pageToadletRegistry.addPage(new MetricsPage(this, loaders, templateRenderer, metricRegistry)); } pageToadletRegistry.addPage(loaders.loadStaticPage("css/", "/static/css/", "text/css")); diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DebugInformation.kt b/src/main/kotlin/net/pterodactylus/sone/core/DebugInformation.kt deleted file mode 100644 index 3115b87..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/core/DebugInformation.kt +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Sone - DebugInformation.kt - Copyright © 2019 David ‘Bombe’ 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.core - -class DebugInformation { - - @Volatile - var showVersionInformation = false - - @Volatile - var showMetrics = false - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt index 6657486..dcb5b3b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt @@ -8,7 +8,6 @@ import com.google.inject.matcher.* import com.google.inject.name.Names.* import com.google.inject.spi.* import freenet.l10n.* -import net.pterodactylus.sone.core.* import net.pterodactylus.sone.database.* import net.pterodactylus.sone.database.memory.* import net.pterodactylus.sone.freenet.wot.* @@ -62,14 +61,6 @@ open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: }) } - @Provides - @Singleton - fun getCore(configuration: Configuration, freenetInterface: FreenetInterface, identityManager: IdentityManager, soneDownloader: SoneDownloader, imageInserter: ImageInserter, updateChecker: UpdateChecker, webOfTrustUpdater: WebOfTrustUpdater, eventBus: EventBus, database: Database) = - Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database).apply { - debugInformation.showVersionInformation = configuration.getBooleanValue("Debug/ShowVersionInformation").getValue(false) - debugInformation.showMetrics = configuration.getBooleanValue("Debug/ShowMetrics").getValue(false) - }.also(eventBus::register) - } private fun String.parseVersion(): Version = Version.parse(this) diff --git a/src/main/resources/templates/include/soneMenu.html b/src/main/resources/templates/include/soneMenu.html index 6722e6b..fa6dd02 100644 --- a/src/main/resources/templates/include/soneMenu.html +++ b/src/main/resources/templates/include/soneMenu.html @@ -10,7 +10,7 @@
<%sone.niceName|html> - (<%= View.Sone.Stats.Posts|l10n 0=sone.posts.size>, <%= View.Sone.Stats.Replies|l10n 0=sone.replies.size><%if ! sone.allImages.size|match value==0>, <%= View.Sone.Stats.Images|l10n 0=sone.allImages.size><%/if><%if core.debugInformation.showVersionInformation>, <% sone.client|html><%/if>) + (<%= View.Sone.Stats.Posts|l10n 0=sone.posts.size>, <%= View.Sone.Stats.Replies|l10n 0=sone.replies.size><%if ! sone.allImages.size|match value==0>, <%= View.Sone.Stats.Images|l10n 0=sone.allImages.size><%/if><%if core.debug>, <% sone.client|html><%/if>)
» <% =View.Post.WebOfTrustLink|l10n|html>
<%foreach sone.albums album> diff --git a/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt index d8d4f0b..d6c56d4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/CoreTest.kt @@ -137,7 +137,7 @@ class CoreTest { } @Test - fun `core starts without debug flags`() { + fun `core starts with debug set to false`() { val configuration = mock() val freenetInterface = mock() val identityManager = mock() @@ -148,7 +148,7 @@ class CoreTest { val eventBus = mock() val database = mock() val core = Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database) - assertThat(core.debugInformation.showVersionInformation, equalTo(false)) + assertThat(core.debug, equalTo(false)) } } diff --git a/src/test/kotlin/net/pterodactylus/sone/core/DebugInformationTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/DebugInformationTest.kt deleted file mode 100644 index 6813253..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/core/DebugInformationTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Sone - DebugInformationTest.kt - Copyright © 2019 David ‘Bombe’ 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.core - -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import kotlin.test.* - -class DebugInformationTest { - - private val debugInformation = DebugInformation() - - @Test - fun `new debug information has show version information set to off`() { - assertThat(debugInformation.showVersionInformation, equalTo(false)) - } - - @Test - fun `new debug information has show metrics set to off`() { - assertThat(debugInformation.showMetrics, equalTo(false)) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index d125769..31b232d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -102,18 +102,6 @@ class SoneModuleTest { } @Test - fun `show version information debug information flag is read from config`() { - File(currentDir, "sone.properties").writeText("Debug/ShowVersionInformation=true") - assertThat(injector.getInstance().debugInformation.showVersionInformation, equalTo(true)) - } - - @Test - fun `show metrics debug information flag is read from config`() { - File(currentDir, "sone.properties").writeText("Debug/ShowMetrics=true") - assertThat(injector.getInstance().debugInformation.showMetrics, equalTo(true)) - } - - @Test fun `event bus is bound`() { assertThat(injector.getInstance(), notNullValue()) }