From e28da6b352ee649a71ca0d8d539494cb22c8771d Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Sat, 4 Nov 2023 17:30:58 +0530 Subject: [PATCH] fix: ILogger.Priority deserialization issues due to r8's enum unboxing --- .../services/builder/GradleBuildService.kt | 6 ++-- .../itsaky/androidide/tooling/impl/Main.java | 3 +- .../tooling/api/ForwardingToolingApiClient.kt | 6 ++-- .../tooling/api/IToolingApiClient.kt | 6 ++-- .../tooling/api/messages/LogMessageParams.kt | 35 +++++++++++++++++++ .../tooling/testing/ToolingApiTestLauncher.kt | 6 ++-- 6 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/messages/LogMessageParams.kt diff --git a/app/src/main/java/com/itsaky/androidide/services/builder/GradleBuildService.kt b/app/src/main/java/com/itsaky/androidide/services/builder/GradleBuildService.kt index af12daf480..fe907456ef 100644 --- a/app/src/main/java/com/itsaky/androidide/services/builder/GradleBuildService.kt +++ b/app/src/main/java/com/itsaky/androidide/services/builder/GradleBuildService.kt @@ -29,7 +29,6 @@ import com.itsaky.androidide.BuildConfig import com.itsaky.androidide.app.BaseApplication import com.itsaky.androidide.lookup.Lookup import com.itsaky.androidide.managers.ToolsManager -import com.itsaky.androidide.models.LogLine import com.itsaky.androidide.preferences.internal.isBuildCacheEnabled import com.itsaky.androidide.preferences.internal.isDebugEnabled import com.itsaky.androidide.preferences.internal.isInfoEnabled @@ -51,6 +50,7 @@ import com.itsaky.androidide.tooling.api.IToolingApiClient import com.itsaky.androidide.tooling.api.IToolingApiServer import com.itsaky.androidide.tooling.api.LogSenderConfig.PROPERTY_LOGSENDER_ENABLED import com.itsaky.androidide.tooling.api.messages.InitializeProjectParams +import com.itsaky.androidide.tooling.api.messages.LogMessageParams import com.itsaky.androidide.tooling.api.messages.TaskExecutionMessage import com.itsaky.androidide.tooling.api.messages.result.BuildCancellationRequestResult import com.itsaky.androidide.tooling.api.messages.result.BuildInfo @@ -58,6 +58,7 @@ import com.itsaky.androidide.tooling.api.messages.result.BuildResult import com.itsaky.androidide.tooling.api.messages.result.GradleWrapperCheckResult import com.itsaky.androidide.tooling.api.messages.result.InitializeResult import com.itsaky.androidide.tooling.api.messages.result.TaskExecutionResult +import com.itsaky.androidide.tooling.api.messages.toLogLine import com.itsaky.androidide.tooling.events.ProgressEvent import com.itsaky.androidide.utils.Environment import com.itsaky.androidide.utils.ILogger @@ -233,7 +234,8 @@ class GradleBuildService : Service(), BuildService, IToolingApiClient, return _toolingApiClient!! } - override fun logMessage(line: LogLine) { + override fun logMessage(params: LogMessageParams) { + val line = params.toLogLine() serverLogger.log(line.priority, line.formattedTagAndMessage()) } diff --git a/subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/Main.java b/subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/Main.java index 404cc351f5..3f79a67311 100644 --- a/subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/Main.java +++ b/subprojects/tooling-api-impl/src/main/java/com/itsaky/androidide/tooling/impl/Main.java @@ -21,6 +21,7 @@ import com.itsaky.androidide.models.LogLine; import com.itsaky.androidide.tooling.api.IToolingApiClient; +import com.itsaky.androidide.tooling.api.messages.LogMessageParams; import com.itsaky.androidide.tooling.api.util.ToolingApiLauncher; import com.itsaky.androidide.tooling.impl.internal.ProjectImpl; import com.itsaky.androidide.tooling.impl.progress.ForwardingProgressListener; @@ -126,7 +127,7 @@ public static void finalizeLauncher(ConfigurableLauncher launcher) { private static void onLog(Priority priority, String tag, String message) { if (client != null) { - client.logMessage(LogLine.obtain(priority, tag, message)); + client.logMessage(new LogMessageParams(priority.priorityChar, tag, message)); } } diff --git a/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/ForwardingToolingApiClient.kt b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/ForwardingToolingApiClient.kt index d426b33b62..c3a1f99362 100644 --- a/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/ForwardingToolingApiClient.kt +++ b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/ForwardingToolingApiClient.kt @@ -17,7 +17,7 @@ package com.itsaky.androidide.tooling.api -import com.itsaky.androidide.models.LogLine +import com.itsaky.androidide.tooling.api.messages.LogMessageParams import com.itsaky.androidide.tooling.api.messages.result.BuildInfo import com.itsaky.androidide.tooling.api.messages.result.BuildResult import com.itsaky.androidide.tooling.api.messages.result.GradleWrapperCheckResult @@ -31,8 +31,8 @@ import java.util.concurrent.CompletableFuture */ class ForwardingToolingApiClient(var client: IToolingApiClient?) : IToolingApiClient { - override fun logMessage(line: LogLine) { - client?.logMessage(line) + override fun logMessage(params: LogMessageParams) { + client?.logMessage(params) } override fun logOutput(line: String) { diff --git a/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/IToolingApiClient.kt b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/IToolingApiClient.kt index 78b272ae36..5bad249f35 100644 --- a/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/IToolingApiClient.kt +++ b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/IToolingApiClient.kt @@ -17,7 +17,7 @@ package com.itsaky.androidide.tooling.api -import com.itsaky.androidide.models.LogLine +import com.itsaky.androidide.tooling.api.messages.LogMessageParams import com.itsaky.androidide.tooling.api.messages.result.BuildInfo import com.itsaky.androidide.tooling.api.messages.result.BuildResult import com.itsaky.androidide.tooling.api.messages.result.GradleWrapperCheckResult @@ -38,9 +38,9 @@ interface IToolingApiClient { /** * Log the given log message. * - * @param line The [LogLine] to log. + * @param params The parameters to log the message. */ - @JsonNotification fun logMessage(line: LogLine) + @JsonNotification fun logMessage(params: LogMessageParams) /** * Log the build output received from Gradle. diff --git a/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/messages/LogMessageParams.kt b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/messages/LogMessageParams.kt new file mode 100644 index 0000000000..6cfef41933 --- /dev/null +++ b/subprojects/tooling-api/src/main/java/com/itsaky/androidide/tooling/api/messages/LogMessageParams.kt @@ -0,0 +1,35 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE 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. + * + * AndroidIDE 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 AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.tooling.api.messages + +import com.itsaky.androidide.models.LogLine +import com.itsaky.androidide.utils.ILogger + +/** + * Parameters for sending a log message from the tooling API to the IDE. + * + * @author Akash Yadav + */ +data class LogMessageParams(val level: Char, val tag: String, val message: String) + +/** + * Creates a new [LogLine] instance from this [LogMessageParams]. + */ +fun LogMessageParams.toLogLine(): LogLine { + return LogLine.obtain(ILogger.Priority.forChar(level), tag, message) +} diff --git a/testing/tooling/src/main/java/com/itsaky/androidide/tooling/testing/ToolingApiTestLauncher.kt b/testing/tooling/src/main/java/com/itsaky/androidide/tooling/testing/ToolingApiTestLauncher.kt index 96219f1e17..af8ba11e77 100644 --- a/testing/tooling/src/main/java/com/itsaky/androidide/tooling/testing/ToolingApiTestLauncher.kt +++ b/testing/tooling/src/main/java/com/itsaky/androidide/tooling/testing/ToolingApiTestLauncher.kt @@ -17,16 +17,17 @@ package com.itsaky.androidide.tooling.testing -import com.itsaky.androidide.models.LogLine import com.itsaky.androidide.tooling.api.IProject import com.itsaky.androidide.tooling.api.IToolingApiClient import com.itsaky.androidide.tooling.api.IToolingApiServer import com.itsaky.androidide.tooling.api.messages.GradleDistributionParams import com.itsaky.androidide.tooling.api.messages.InitializeProjectParams +import com.itsaky.androidide.tooling.api.messages.LogMessageParams import com.itsaky.androidide.tooling.api.messages.result.BuildInfo import com.itsaky.androidide.tooling.api.messages.result.BuildResult import com.itsaky.androidide.tooling.api.messages.result.GradleWrapperCheckResult import com.itsaky.androidide.tooling.api.messages.result.InitializeResult +import com.itsaky.androidide.tooling.api.messages.toLogLine import com.itsaky.androidide.tooling.api.util.ToolingApiLauncher import com.itsaky.androidide.tooling.events.ProgressEvent import com.itsaky.androidide.utils.FileProvider @@ -150,7 +151,8 @@ class ToolingApiTestLauncher { "DO NOT EDIT - Automatically generated file" } - override fun logMessage(line: LogLine) { + override fun logMessage(params: LogMessageParams) { + val line = params.toLogLine() log.log(line.priority, line.formattedTagAndMessage()) }