From 49872c388489260aa2e4ecd42dfda1aaebb8d2db Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 28 Jul 2019 15:53:11 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=94=A5=20Replace=20debug=20flag=20collecti?= =?utf8?q?on=20with=20simple=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 7 ++-- .../net/pterodactylus/sone/web/WebInterface.java | 2 +- .../pterodactylus/sone/core/DebugInformation.kt | 28 ---------------- .../net/pterodactylus/sone/main/SoneModule.kt | 9 ----- src/main/resources/templates/include/soneMenu.html | 2 +- .../kotlin/net/pterodactylus/sone/core/CoreTest.kt | 4 +-- .../sone/core/DebugInformationTest.kt | 38 ---------------------- .../net/pterodactylus/sone/main/SoneModuleTest.kt | 12 ------- 8 files changed, 8 insertions(+), 94 deletions(-) delete mode 100644 src/main/kotlin/net/pterodactylus/sone/core/DebugInformation.kt delete mode 100644 src/test/kotlin/net/pterodactylus/sone/core/DebugInformationTest.kt 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()) } -- 2.7.4