Skip to content

Commit c87d136

Browse files
wziebaclaude
andcommitted
Fix FileLogger dependency injection and remove Hilt from commons
This fixes the ClassCastException when running WooCommerce tests after moving WooLog to the commons module. Changes: 1. Remove Hilt/KSP plugins from commons module - commons doesn't need to process Hilt annotations itself. The WooCommerce and Wear modules that depend on commons will process any Hilt annotations found in commons (like @Inject on WooFileLogger). 2. Replace EntryPoints.get() pattern with direct injection - Changed WooLog.init() to accept WooFileLogger directly instead of using Context and EntryPoints.get(). This is cleaner and removes the code smell of using EntryPoints for something that can be injected. 3. Update WooCommerce's AppConfigModule to inject WooFileLogger into provideWooLog() and pass it to WooLog.init(). This approach avoids forcing the Wear module to provide dependencies (AppCoroutineScope, CoroutineDispatchers) that it doesn't actually use, since Wear doesn't use WooLog at all. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0fd2bc2 commit c87d136

File tree

2 files changed

+5
-15
lines changed
  • WooCommerce/src/main/kotlin/com/woocommerce/android/di
  • libs/commons/src/main/java/com/woocommerce/android/util

2 files changed

+5
-15
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/di/AppConfigModule.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.woocommerce.android.BuildConfig
77
import com.woocommerce.android.FeedbackPrefs
88
import com.woocommerce.android.util.StringUtils
99
import com.woocommerce.android.util.WooLog
10+
import com.woocommerce.android.util.logs.WooFileLogger
1011
import dagger.Module
1112
import dagger.Provides
1213
import dagger.hilt.InstallIn
@@ -53,8 +54,8 @@ class AppConfigModule {
5354

5455
@Provides
5556
@Singleton
56-
fun provideWooLog(context: Context): WooLog {
57-
WooLog.init(context)
57+
fun provideWooLog(fileLogger: WooFileLogger): WooLog {
58+
WooLog.init(fileLogger)
5859
return WooLog
5960
}
6061
}

libs/commons/src/main/java/com/woocommerce/android/util/WooLog.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.woocommerce.android.util
22

3-
import android.content.Context
43
import android.util.Log
54
import com.woocommerce.android.util.logs.LogEntry
65
import com.woocommerce.android.util.logs.WooFileLogger
7-
import dagger.hilt.EntryPoint
8-
import dagger.hilt.EntryPoints
9-
import dagger.hilt.InstallIn
10-
import dagger.hilt.components.SingletonComponent
116
import java.io.PrintWriter
127
import java.io.StringWriter
138
import org.wordpress.android.util.AppLog as WordPressAppLog
@@ -64,13 +59,13 @@ object WooLog {
6459

6560
private lateinit var fileLogger: WooFileLogger
6661

67-
fun init(context: Context) {
62+
fun init(fileLogger: WooFileLogger) {
6863
// add listener for WP app log so we can capture login & FluxC logs
6964
WordPressAppLog.addListener { tag, logLevel, message ->
7065
addWPLogEntry(tag, logLevel, message)
7166
}
7267

73-
fileLogger = EntryPoints.get(context, FileLoggerEntryPoint::class.java).fileLogger()
68+
this.fileLogger = fileLogger
7469
tempListBeforeInit.forEach { entry ->
7570
fileLogger.addEntry(entry)
7671
}
@@ -212,9 +207,3 @@ object WooLog {
212207
return errors.toString()
213208
}
214209
}
215-
216-
@InstallIn(SingletonComponent::class)
217-
@EntryPoint
218-
private interface FileLoggerEntryPoint {
219-
fun fileLogger(): WooFileLogger
220-
}

0 commit comments

Comments
 (0)