Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: migrate to SLF4J and Logback logging implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Mar 16, 2024
1 parent 940c7b0 commit ab101fb
Show file tree
Hide file tree
Showing 409 changed files with 2,729 additions and 2,725 deletions.
7 changes: 6 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.itsaky.androidide.actions.ActionsRegistry
import com.itsaky.androidide.actions.FillMenuParams
import com.itsaky.androidide.actions.OnActionClickListener
import com.itsaky.androidide.actions.locations.CodeActionsMenu
import com.itsaky.androidide.utils.ILogger
import com.itsaky.androidide.utils.withStopWatch
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
Expand All @@ -35,6 +34,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import kotlinx.coroutines.withContext
import org.slf4j.LoggerFactory
import java.util.concurrent.ConcurrentHashMap

/**
Expand All @@ -45,13 +45,16 @@ import java.util.concurrent.ConcurrentHashMap
@AutoService(ActionsRegistry::class)
class DefaultActionsRegistry : ActionsRegistry() {

private val log = ILogger.newInstance("DefaultActionsRegistry")
private val actions = ConcurrentHashMap<String, ConcurrentHashMap<String, ActionItem>>()
private val listeners = HashSet<ActionExecListener>()

private val actionsCoroutineScope = CoroutineScope(Dispatchers.Default) +
CoroutineName("DefaultActionsRegistry")

companion object {
private val log = LoggerFactory.getLogger(DefaultActionsRegistry::class.java)
}

init {
registerAction(CodeActionsMenu)
}
Expand Down Expand Up @@ -217,7 +220,7 @@ class DefaultActionsRegistry : ActionsRegistry() {
}.also { job ->
job.invokeOnCompletion { error ->
if (error != null) {
log.error("An error occurred when performing action '${action.id}'", error)
log.error("An error occurred when performing action '{}'", action.id, error)
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@file:Suppress("UnstableApiUsage")

import ch.qos.logback.core.util.EnvUtil
import com.itsaky.androidide.build.config.BuildConfig
import com.itsaky.androidide.desugaring.ch.qos.logback.core.util.DesugarEnvUtil
import com.itsaky.androidide.desugaring.utils.JavaIOReplacements.applyJavaIOReplacements
import com.itsaky.androidide.plugins.AndroidIDEAssetsPlugin
import kotlin.reflect.jvm.javaMethod

plugins {
id("com.android.application")
Expand All @@ -17,6 +20,13 @@ apply {
plugin(AndroidIDEAssetsPlugin::class.java)
}

buildscript {
dependencies {
classpath(libs.logging.logback.core)
classpath(libs.composite.desugaringCore)
}
}

android {
namespace = BuildConfig.packageName

Expand Down Expand Up @@ -45,9 +55,20 @@ kapt { arguments { arg("eventBusIndex", "${BuildConfig.packageName}.events.AppEv

desugaring {
replacements {
includePackage("org.eclipse.jgit")
includePackage(
"org.eclipse.jgit",
"ch.qos.logback.classic.util",
)

applyJavaIOReplacements()

// EnvUtil.logbackVersion() uses newer Java APIs like Class.getModule() which is not available
// on Android. We replace the method usage with DesugarEnvUtil.logbackVersion() which
// always returns null
replaceMethod(
EnvUtil::logbackVersion.javaMethod!!,
DesugarEnvUtil::logbackVersion.javaMethod!!
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.itsaky.androidide.actions

import com.itsaky.androidide.lookup.Lookup
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.utils.ILogger

/**
* Marker class for actions that execute build related tasks.
Expand All @@ -28,7 +27,6 @@ import com.itsaky.androidide.utils.ILogger
*/
abstract class BaseBuildAction : EditorActivityAction() {

protected val log: ILogger = ILogger.newInstance(javaClass.simpleName)
protected val buildService: BuildService?
get() = Lookup.getDefault().lookup(BuildService.KEY_BUILD_SERVICE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.itsaky.androidide.utils.resolveAttr
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.slf4j.LoggerFactory
import java.io.File

/**
Expand All @@ -55,6 +56,11 @@ import java.io.File
class QuickRunWithCancellationAction(context: Context, override val order: Int) :
BaseBuildAction() {

companion object {

private val log = LoggerFactory.getLogger(QuickRunWithCancellationAction::class.java)
}

init {
label = context.getString(R.string.quick_run_debug)
icon = ContextCompat.getDrawable(context, R.drawable.ic_run_outline)
Expand Down Expand Up @@ -130,7 +136,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
) {

val buildService = this.buildService ?: run {
log.error("Cannot execute task '$taskName'. BuildService not found.")
log.error("Cannot execute task '{}'. BuildService not found.", taskName)
return
}

Expand All @@ -143,7 +149,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
data.getActivity()
?: run {
log.error(
"Cannot execute task '$taskName'. Activity instance not provided in ActionData.")
"Cannot execute task '{}'. Activity instance not provided in ActionData.", taskName)
return
}

Expand All @@ -154,17 +160,17 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
buildService.executeTasks(taskName).get()
}

log.debug("Task execution result:", result)
log.debug("Task execution result: {}", result)

if (result?.isSuccessful != true) {
log.error("Tasks failed to execute: '$taskName'")
log.error("Tasks failed to execute: '{}'", taskName)
return@launch
}

handleResult(data, result, module, variant)
}.invokeOnCompletion { error ->
if (error != null) {
log.error("Failed to run '$taskName'", error)
log.error("Failed to run '{}'", taskName, error)
}
}
}
Expand All @@ -186,7 +192,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)

if (!result.wasEnqueued) {
log.warn(
"Unable to enqueue cancellation request",
"Unable to enqueue cancellation request reason={} reason.message={}",
result.failureReason,
result.failureReason!!.message
)
Expand All @@ -210,7 +216,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
return
}

log.debug("Installing APK(s) for project: '${module.path}' variant: '${variant.name}'")
log.debug("Installing APK(s) for project: '{}' variant: '{}'", module.path, variant.name)

val main = variant.mainArtifact
val outputListingFile = main.assembleTaskOutputListingFile
Expand All @@ -219,15 +225,15 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
return
}

log.verbose("Parsing metadata")
log.trace("Parsing metadata")
val apkFile = ApkMetadata.findApkFile(outputListingFile)
if (apkFile == null) {
log.error("No apk file specified in output listing file:", outputListingFile)
log.error("No apk file specified in output listing file: {}", outputListingFile)
return
}

if (!apkFile.exists()) {
log.error("APK file specified in output listing file does not exist!", apkFile)
log.error("APK file specified in output listing file does not exist! {}", apkFile)
return
}

Expand All @@ -243,7 +249,7 @@ class QuickRunWithCancellationAction(context: Context, override val order: Int)
}

activity.runOnUiThread {
log.debug("Installing APK:", apk)
log.debug("Installing APK: {}", apk)

if (!apk.exists()) {
log.error("APK file does not exist!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package com.itsaky.androidide.actions.editor

import android.content.Context
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.BaseEditorAction
import com.itsaky.androidide.resources.R

/** @author Akash Yadav */
class CopyAction(context: Context, override val order: Int) : BaseEditorAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package com.itsaky.androidide.actions.editor

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem
import com.itsaky.androidide.actions.EditorRelatedAction
import com.itsaky.androidide.resources.R

/**
* Expands the current selection using the language server set in editor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.itsaky.androidide.actions.etc

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.EditorRelatedAction
import com.itsaky.androidide.resources.R

/** @author Akash Yadav */
class FindInFileAction() : EditorRelatedAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package com.itsaky.androidide.actions.etc

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.EditorActivityAction
import com.itsaky.androidide.actions.markInvisible
import com.itsaky.androidide.projects.IProjectManager
import com.itsaky.androidide.resources.R

/** @author Akash Yadav */
class FindInProjectAction() : EditorActivityAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.EditorActivityAction
import com.itsaky.androidide.actions.markInvisible
import com.itsaky.androidide.actions.openApplicationModuleChooser
import com.itsaky.androidide.builder.model.UNKNOWN_PACKAGE
import com.itsaky.androidide.projects.IProjectManager
import com.itsaky.androidide.utils.ILogger
import com.itsaky.androidide.utils.IntentUtils
import com.itsaky.androidide.utils.flashError
import org.slf4j.LoggerFactory

/**
* An action to launch the already installed application on the device.
Expand All @@ -47,7 +46,7 @@ class LaunchAppAction(context: Context, override val order: Int) : EditorActivit
}

companion object {
private val log = ILogger.newInstance("LaunchAppAction")
private val log = LoggerFactory.getLogger(LaunchAppAction::class.java)
}

override fun prepare(data: ActionData) {
Expand All @@ -67,7 +66,7 @@ class LaunchAppAction(context: Context, override val order: Int) : EditorActivit
openApplicationModuleChooser(data) { app ->
val variant = app.getSelectedVariant()

log.debug("Selected variant: ${variant?.name}")
log.debug("Selected variant: {}", variant?.name)

if (variant == null) {
flashError(R.string.err_selected_variant_not_found)
Expand All @@ -81,7 +80,7 @@ class LaunchAppAction(context: Context, override val order: Int) : EditorActivit
return@openApplicationModuleChooser
}

log.info("Launching application: $applicationId")
log.info("Launching application: {}", applicationId)

val activity = data.requireActivity()
IntentUtils.launchApp(activity, applicationId, logError = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ package com.itsaky.androidide.actions.etc
import android.content.Context
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import com.blankj.utilcode.util.ThreadUtils
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.EditorActivityAction
import com.itsaky.androidide.editor.schemes.IDEColorSchemeProvider
import com.itsaky.androidide.tasks.executeAsyncProvideError
import com.itsaky.androidide.tasks.executeWithProgress
import com.itsaky.androidide.tasks.launchAsyncWithProgress
import com.itsaky.androidide.utils.ILogger
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand All @@ -46,8 +42,6 @@ class ReloadColorSchemesAction(context: Context, override val order: Int) : Edit
// the UI thread
override var requiresUIThread: Boolean = true

private val log = ILogger.newInstance("ReloadColorSchemesAction")

init {
label = context.getString(R.string.title_reload_color_schemes)
icon = ContextCompat.getDrawable(context, R.drawable.ic_reload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.itsaky.androidide.actions.file

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.activities.editor.EditorHandlerActivity
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.activities.editor.EditorHandlerActivity

/**
* Closes all opened files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.itsaky.androidide.actions.file

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.activities.editor.EditorHandlerActivity
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.activities.editor.EditorHandlerActivity

/**
* Closes the current file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.itsaky.androidide.actions.file

import android.content.Context
import androidx.core.content.ContextCompat
import com.itsaky.androidide.activities.editor.EditorHandlerActivity
import com.itsaky.androidide.R
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.activities.editor.EditorHandlerActivity

/**
* Closes all opened files except the selected one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package com.itsaky.androidide.actions.file

import com.itsaky.androidide.activities.editor.EditorHandlerActivity
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.ActionItem.Location
import com.itsaky.androidide.actions.ActionItem.Location.EDITOR_FILE_TABS
import com.itsaky.androidide.actions.EditorActivityAction
import com.itsaky.androidide.actions.markInvisible
import com.itsaky.androidide.activities.editor.EditorHandlerActivity

/**
* Action related to file tabs. Shown only when there is at least one file opened.
Expand Down
Loading

0 comments on commit ab101fb

Please sign in to comment.