From 4ac3d01f279557483b5c57a37d8d56e83f1f017a Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Mon, 21 Oct 2024 13:58:00 +0200 Subject: [PATCH 1/2] feat: Add Core2 & SentryLog modules --- Core2/SentryLog/build.gradle.kts | 34 ++++++ Core2/SentryLog/consumer-rules.pro | 0 .../SentryLog/gradle/sentrylog.versions.toml | 5 + Core2/SentryLog/proguard-rules.pro | 21 ++++ .../com/infomaniak/sentrylog/SentryLog.kt | 103 ++++++++++++++++++ Core2/build.gradle.kts | 34 ++++++ Core2/consumer-rules.pro | 0 Core2/proguard-rules.pro | 21 ++++ FileTypes/.gitignore | 1 - FileTypes/build.gradle.kts | 8 +- ....versions.toml => filetypes.versions.toml} | 0 app/build.gradle.kts | 2 +- gradle/libs.versions.toml | 2 - settings.gradle.kts | 7 +- 14 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 Core2/SentryLog/build.gradle.kts create mode 100644 Core2/SentryLog/consumer-rules.pro create mode 100644 Core2/SentryLog/gradle/sentrylog.versions.toml create mode 100644 Core2/SentryLog/proguard-rules.pro create mode 100644 Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt create mode 100644 Core2/build.gradle.kts create mode 100644 Core2/consumer-rules.pro create mode 100644 Core2/proguard-rules.pro delete mode 100644 FileTypes/.gitignore rename FileTypes/gradle/{filetype.versions.toml => filetypes.versions.toml} (100%) diff --git a/Core2/SentryLog/build.gradle.kts b/Core2/SentryLog/build.gradle.kts new file mode 100644 index 000000000..33d1ef8b6 --- /dev/null +++ b/Core2/SentryLog/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.infomaniak.sentrylog" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + implementation(sentrylog.sentry.android) +} diff --git a/Core2/SentryLog/consumer-rules.pro b/Core2/SentryLog/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/Core2/SentryLog/gradle/sentrylog.versions.toml b/Core2/SentryLog/gradle/sentrylog.versions.toml new file mode 100644 index 000000000..d11dbef7c --- /dev/null +++ b/Core2/SentryLog/gradle/sentrylog.versions.toml @@ -0,0 +1,5 @@ +[versions] +sentry-android = "7.15.0" + +[libraries] +sentry-android = { module = "io.sentry:sentry-android", version.ref = "sentry-android" } diff --git a/Core2/SentryLog/proguard-rules.pro b/Core2/SentryLog/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/Core2/SentryLog/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt b/Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt new file mode 100644 index 000000000..c8136c6af --- /dev/null +++ b/Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt @@ -0,0 +1,103 @@ +/* + * Infomaniak Core - Android + * Copyright (C) 2024 Infomaniak Network SA + * + * 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 com.infomaniak.sentrylog + +import android.util.Log +import io.sentry.Breadcrumb +import io.sentry.Sentry +import io.sentry.SentryEvent +import io.sentry.SentryLevel +import io.sentry.protocol.Message + +object SentryLog { + + private val TAG = SentryLog::class.java.simpleName + + fun v(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.v(TAG, formattedMessage, throwable) + SentryLevel.DEBUG.addBreadcrumb(formattedMessage, throwable) + } + + fun d(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.d(TAG, formattedMessage, throwable) + SentryLevel.DEBUG.addBreadcrumb(formattedMessage, throwable) + } + + fun i(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.i(TAG, formattedMessage, throwable) + SentryLevel.INFO.addBreadcrumb(formattedMessage, throwable) + } + + fun w(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.w(TAG, formattedMessage, throwable) + SentryLevel.WARNING.addBreadcrumb(formattedMessage, throwable) + } + + fun e(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.e(TAG, formattedMessage, throwable) + SentryLevel.ERROR.apply { + addBreadcrumb(formattedMessage, throwable) + captureEvent(tag, msg, throwable) + } + } + + fun wtf(tag: String, msg: String, throwable: Throwable? = null) { + val formattedMessage = formatLogMessage(tag, msg) + Log.wtf(TAG, formattedMessage, throwable) + SentryLevel.FATAL.apply { + addBreadcrumb(formattedMessage, throwable) + captureEvent(tag, msg, throwable) + } + } + + private fun SentryLevel.captureEvent(tag: String, msg: String, throwable: Throwable?) { + val sentryEvent = SentryEvent().apply { + setTag("SentryLogTag", tag) + level = this@captureEvent + logger = TAG + message = Message().apply { this.message = msg } + throwable?.let(::setThrowable) + } + + Sentry.captureEvent(sentryEvent) + } + + private fun SentryLevel.addBreadcrumb(msg: String, throwable: Throwable?) { + + val throwableMsg = throwable?.message + val breadCrumb = when { + throwableMsg != null -> Breadcrumb.error(throwableMsg).apply { + category = "exception" + } + else -> Breadcrumb().apply { + level = this@addBreadcrumb + category = TAG + message = msg + } + } + + Sentry.addBreadcrumb(breadCrumb) + } + + private fun formatLogMessage(tag: String, msg: String) = "($tag): $msg" +} diff --git a/Core2/build.gradle.kts b/Core2/build.gradle.kts new file mode 100644 index 000000000..0387011ee --- /dev/null +++ b/Core2/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.infomaniak.core2" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + +} diff --git a/Core2/consumer-rules.pro b/Core2/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/Core2/proguard-rules.pro b/Core2/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/Core2/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/FileTypes/.gitignore b/FileTypes/.gitignore deleted file mode 100644 index 42afabfd2..000000000 --- a/FileTypes/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/FileTypes/build.gradle.kts b/FileTypes/build.gradle.kts index 826a2df5d..b4aeaf7ac 100644 --- a/FileTypes/build.gradle.kts +++ b/FileTypes/build.gradle.kts @@ -39,10 +39,10 @@ android { dependencies { implementation(libs.androidx.core.ktx) - implementation(filetype.androidx.ui.android) - implementation(filetype.androidx.foundation.android) - implementation(filetype.androidx.ui.tooling.preview.android) + implementation(filetypes.androidx.ui.android) + implementation(filetypes.androidx.foundation.android) + implementation(filetypes.androidx.ui.tooling.preview.android) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) - debugImplementation(filetype.androidx.ui.tooling) + debugImplementation(filetypes.androidx.ui.tooling) } diff --git a/FileTypes/gradle/filetype.versions.toml b/FileTypes/gradle/filetypes.versions.toml similarity index 100% rename from FileTypes/gradle/filetype.versions.toml rename to FileTypes/gradle/filetypes.versions.toml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 724cc93e3..3cce8cbaa 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -80,6 +80,7 @@ sentry { } dependencies { + implementation(project(":Core2:SentryLog")) implementation(project(":FileTypes")) implementation(kotlin("reflect")) @@ -96,7 +97,6 @@ dependencies { implementation(libs.compose.material3.adaptative.navigation) implementation(libs.navigation.compose) implementation(libs.androidx.constraintlayout.compose) - implementation(libs.sentry.android) implementation(libs.androidx.adaptive) implementation(libs.androidx.adaptive.layout) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 590bd9b93..a94342672 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,6 @@ navigation = "2.8.1" serialization = "1.7.1" swisstransfer = "0.3.0" sentry = "4.12.0" -sentry-android = "7.15.0" recaptcha = "18.6.1" [libraries] @@ -45,7 +44,6 @@ hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", ve kotlinx-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" } navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation" } swisstransfer-core = { module = "com.github.Infomaniak.multiplatform-SwissTransfer:STCore", version.ref = "swisstransfer" } -sentry-android = { module = "io.sentry:sentry-android", version.ref = "sentry-android" } recaptcha = { module = "com.google.android.recaptcha:recaptcha", version.ref = "recaptcha" } # Tests androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 674765690..b3e7443f0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,12 +22,13 @@ dependencyResolutionManagement { maven { url = uri("https://jitpack.io") } } versionCatalogs { - create("filetype") { - from(files("FileTypes/gradle/filetype.versions.toml")) - } + create("sentrylog") { from(files("Core2/SentryLog/gradle/sentrylog.versions.toml")) } + create("filetypes") { from(files("FileTypes/gradle/filetypes.versions.toml")) } } } rootProject.name = "android-SwissTransfer" include(":app") +include(":Core2") +include(":Core2:SentryLog") include(":FileTypes") From ef29a8f8968dcaf583af973bc895d595261612e3 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Mon, 21 Oct 2024 14:27:20 +0200 Subject: [PATCH 2/2] refactor: Rename SentryLog module into Sentry --- Core2/{SentryLog => Sentry}/build.gradle.kts | 4 ++-- Core2/{SentryLog => Sentry}/consumer-rules.pro | 0 Core2/{SentryLog => Sentry}/proguard-rules.pro | 0 .../src/main/java/com/infomaniak/sentry}/SentryLog.kt | 2 +- .../sentrylog.versions.toml => gradle/core2.versions.toml} | 0 app/build.gradle.kts | 2 +- settings.gradle.kts | 4 ++-- 7 files changed, 6 insertions(+), 6 deletions(-) rename Core2/{SentryLog => Sentry}/build.gradle.kts (88%) rename Core2/{SentryLog => Sentry}/consumer-rules.pro (100%) rename Core2/{SentryLog => Sentry}/proguard-rules.pro (100%) rename Core2/{SentryLog/src/main/java/com/infomaniak/sentrylog => Sentry/src/main/java/com/infomaniak/sentry}/SentryLog.kt (99%) rename Core2/{SentryLog/gradle/sentrylog.versions.toml => gradle/core2.versions.toml} (100%) diff --git a/Core2/SentryLog/build.gradle.kts b/Core2/Sentry/build.gradle.kts similarity index 88% rename from Core2/SentryLog/build.gradle.kts rename to Core2/Sentry/build.gradle.kts index 33d1ef8b6..229de5fb8 100644 --- a/Core2/SentryLog/build.gradle.kts +++ b/Core2/Sentry/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } android { - namespace = "com.infomaniak.sentrylog" + namespace = "com.infomaniak.sentry" compileSdk = 34 defaultConfig { @@ -30,5 +30,5 @@ android { } dependencies { - implementation(sentrylog.sentry.android) + api(core2.sentry.android) } diff --git a/Core2/SentryLog/consumer-rules.pro b/Core2/Sentry/consumer-rules.pro similarity index 100% rename from Core2/SentryLog/consumer-rules.pro rename to Core2/Sentry/consumer-rules.pro diff --git a/Core2/SentryLog/proguard-rules.pro b/Core2/Sentry/proguard-rules.pro similarity index 100% rename from Core2/SentryLog/proguard-rules.pro rename to Core2/Sentry/proguard-rules.pro diff --git a/Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt b/Core2/Sentry/src/main/java/com/infomaniak/sentry/SentryLog.kt similarity index 99% rename from Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt rename to Core2/Sentry/src/main/java/com/infomaniak/sentry/SentryLog.kt index c8136c6af..fb818c04d 100644 --- a/Core2/SentryLog/src/main/java/com/infomaniak/sentrylog/SentryLog.kt +++ b/Core2/Sentry/src/main/java/com/infomaniak/sentry/SentryLog.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.sentrylog +package com.infomaniak.sentry import android.util.Log import io.sentry.Breadcrumb diff --git a/Core2/SentryLog/gradle/sentrylog.versions.toml b/Core2/gradle/core2.versions.toml similarity index 100% rename from Core2/SentryLog/gradle/sentrylog.versions.toml rename to Core2/gradle/core2.versions.toml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3cce8cbaa..97c49f1e5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -80,7 +80,7 @@ sentry { } dependencies { - implementation(project(":Core2:SentryLog")) + implementation(project(":Core2:Sentry")) implementation(project(":FileTypes")) implementation(kotlin("reflect")) diff --git a/settings.gradle.kts b/settings.gradle.kts index b3e7443f0..4a8de3dc0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,7 +22,7 @@ dependencyResolutionManagement { maven { url = uri("https://jitpack.io") } } versionCatalogs { - create("sentrylog") { from(files("Core2/SentryLog/gradle/sentrylog.versions.toml")) } + create("core2") { from(files("Core2/gradle/core2.versions.toml")) } create("filetypes") { from(files("FileTypes/gradle/filetypes.versions.toml")) } } } @@ -30,5 +30,5 @@ dependencyResolutionManagement { rootProject.name = "android-SwissTransfer" include(":app") include(":Core2") -include(":Core2:SentryLog") +include(":Core2:Sentry") include(":FileTypes")