Skip to content

Commit

Permalink
Convert file store and subclasses to kotlin (#1929)
Browse files Browse the repository at this point in the history
* fix(code convert) add FileStore, sessionStore and EventStore Kotlin classes

* fix(code convert) add FileStore, sessionStore and EventStore Kotlin classes

* fix(code convert) add FileStore, sessionStore and EventStore Kotlin classes

* fix(code convert) add FileStore, sessionStore and EventStore Kotlin classes
  • Loading branch information
SmartbearYing authored Nov 24, 2023
1 parent b10b0b7 commit 5952cad
Show file tree
Hide file tree
Showing 24 changed files with 701 additions and 679 deletions.
10 changes: 9 additions & 1 deletion bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ID>MagicNumber:DefaultDelivery.kt$DefaultDelivery$299</ID>
<ID>MagicNumber:DefaultDelivery.kt$DefaultDelivery$429</ID>
<ID>MagicNumber:DefaultDelivery.kt$DefaultDelivery$499</ID>
<ID>MagicNumber:EventStore.kt$EventStore$60</ID>
<ID>MagicNumber:JsonHelper.kt$JsonHelper$0xff</ID>
<ID>MagicNumber:JsonHelper.kt$JsonHelper$1000</ID>
<ID>MagicNumber:JsonHelper.kt$JsonHelper$16</ID>
Expand All @@ -31,15 +32,20 @@
<ID>MagicNumber:JsonHelper.kt$JsonHelper$3</ID>
<ID>MagicNumber:JsonHelper.kt$JsonHelper$8</ID>
<ID>MagicNumber:LastRunInfoStore.kt$LastRunInfoStore$3</ID>
<ID>MagicNumber:SessionStore.kt$SessionStore$60</ID>
<ID>MaxLineLength:LastRunInfo.kt$LastRunInfo$return "LastRunInfo(consecutiveLaunchCrashes=$consecutiveLaunchCrashes, crashed=$crashed, crashedDuringLaunch=$crashedDuringLaunch)"</ID>
<ID>MaxLineLength:ThreadState.kt$ThreadState$"[${allThreads.size - maxThreadCount} threads omitted as the maxReportedThreads limit ($maxThreadCount) was exceeded]"</ID>
<ID>NestedBlockDepth:FileStore.kt$FileStore$fun deleteStoredFiles(storedFiles: Collection&lt;File>?)</ID>
<ID>NestedBlockDepth:FileStore.kt$FileStore$fun discardOldestFileIfNeeded()</ID>
<ID>NestedBlockDepth:FileStore.kt$FileStore$fun findStoredFiles(): MutableList&lt;File></ID>
<ID>NestedBlockDepth:JsonHelper.kt$JsonHelper$fun jsonToLong(value: Any?): Long?</ID>
<ID>ProtectedMemberInFinalClass:ConfigInternal.kt$ConfigInternal$protected val plugins = HashSet&lt;Plugin>()</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun isAnr(event: Event): Boolean</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun shouldDiscardClass(): Boolean</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun updateSeverityInternal(severity: Severity)</ID>
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun updateSeverityReason(@SeverityReason.SeverityReasonType reason: String)</ID>
<ID>ReturnCount:DefaultDelivery.kt$DefaultDelivery$fun deliver( urlString: String, json: ByteArray, headers: Map&lt;String, String?> ): DeliveryStatus</ID>
<ID>SpreadOperator:FileStore.kt$FileStore$(*listFiles)</ID>
<ID>SwallowedException:AppDataCollector.kt$AppDataCollector$e: Exception</ID>
<ID>SwallowedException:BugsnagEventMapper.kt$BugsnagEventMapper$pe: IllegalArgumentException</ID>
<ID>SwallowedException:ConnectivityCompat.kt$ConnectivityLegacy$e: NullPointerException</ID>
Expand All @@ -48,8 +54,10 @@
<ID>SwallowedException:DeviceDataCollector.kt$DeviceDataCollector$exc: Exception</ID>
<ID>SwallowedException:DeviceDataCollector.kt$DeviceDataCollector$exception: Exception</ID>
<ID>SwallowedException:DeviceIdFilePersistence.kt$DeviceIdFilePersistence$exc: OverlappingFileLockException</ID>
<ID>SwallowedException:ImmutableConfig.kt$e: Exception</ID>
<ID>SwallowedException:EventStore.kt$EventStore$exception: RejectedExecutionException</ID>
<ID>SwallowedException:EventStore.kt$EventStore$ioe: Exception</ID>
<ID>SwallowedException:ForegroundDetector.kt$ForegroundDetector$e: Exception</ID>
<ID>SwallowedException:ImmutableConfig.kt$e: Exception</ID>
<ID>SwallowedException:JsonHelperTest.kt$JsonHelperTest$e: IllegalArgumentException</ID>
<ID>SwallowedException:PluginClient.kt$PluginClient$exc: ClassNotFoundException</ID>
<ID>SwallowedException:SharedPrefMigrator.kt$SharedPrefMigrator$e: RuntimeException</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ package com.bugsnag.android

import android.app.Application
import androidx.test.core.app.ApplicationProvider
import com.bugsnag.android.EventStore.Companion.EVENT_COMPARATOR
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner
import java.io.File
import java.util.Comparator

@RunWith(MockitoJUnitRunner::class)
class FileStoreTest {

@Test
fun sendsInternalErrorReport() {

val delegate = CustomDelegate()
val dir = File(ApplicationProvider.getApplicationContext<Application>().cacheDir, "tmp")
val store = CustomFileStore(dir, 1, null, delegate)
val store = CustomFileStore(dir, 1, EVENT_COMPARATOR, delegate)
val exc = RuntimeException("Whoops")
store.write(CustomStreamable(exc))

Expand Down Expand Up @@ -44,8 +49,8 @@ class CustomStreamable(private val exc: Throwable) : JsonStream.Streamable {
internal class CustomFileStore(
folder: File,
maxStoreCount: Int,
comparator: Comparator<File>?,
comparator: Comparator<in File?>,
delegate: Delegate?
) : FileStore(folder, maxStoreCount, comparator, NoopLogger, delegate) {
override fun getFilename(`object`: Any?) = "foo.json"
override fun getFilename(obj: Any?) = "foo.json"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,14 @@ internal class EventStorageModule(
) else null
}

val eventStore by future { EventStore(cfg, cfg.logger, notifier, bgTaskService, delegate, callbackState) }
val eventStore by future {
EventStore(
cfg,
cfg.logger,
notifier,
bgTaskService,
delegate,
callbackState
)
}
}
299 changes: 0 additions & 299 deletions bugsnag-android-core/src/main/java/com/bugsnag/android/EventStore.java

This file was deleted.

Loading

0 comments on commit 5952cad

Please sign in to comment.