Skip to content

Commit 8640676

Browse files
runningcodeclaude
andauthored
ref(plugin): Replace File.separator with forward slash (#1242)
* ref(plugin): Replace File.separator with forward slash Java's File class accepts forward slashes on all platforms, making File.separator unnecessary for path construction. This simplifies path building throughout the codebase. Also replaces manual string manipulation with Kotlin stdlib (toRelativeString, nameWithoutExtension) where applicable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * ref(plugin): Apply spotless formatting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ed68d51 commit 8640676

14 files changed

Lines changed: 37 additions & 70 deletions

File tree

examples/android-instrumentation-sample/src/main/java/io/sentry/samples/instrumentation/ui/LyricsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class LyricsActivity : ComponentActivity() {
3737
filesystem = intent.getSerializableExtra(FILESYSTEM_EXTRA_KEY) as Filesystem
3838
toolbar.title = "Lyrics for ${track.name}"
3939

40-
val dir = File("$filesDir${File.separatorChar}lyrics")
40+
val dir = File("$filesDir/lyrics")
4141
dir.mkdirs()
4242

4343
lyricsInput.setText(filesystem.read(this, "${track.id}.txt"))

plugin-build/buildSrc/src/main/kotlin/io/sentry/android/gradle/internal/ASMifyTask.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ abstract class ASMifyTask : Exec() {
7171
val dir = File(tmpDir)
7272
dir.mkdirs()
7373

74-
val filename =
75-
clazz.substringAfterLast(File.separator).substringBefore(".") + "_asmified.java"
74+
val filename = File(clazz).nameWithoutExtension + "_asmified.java"
7675

7776
val file = File(dir, filename)
7877
if (file.exists()) {

plugin-build/src/main/kotlin/io/sentry/android/gradle/SentryPlugin.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.sentry.BuildConfig
55
import io.sentry.android.gradle.autoinstall.installDependencies
66
import io.sentry.android.gradle.extensions.SentryPluginExtension
77
import io.sentry.android.gradle.util.AgpVersions
8-
import java.io.File
98
import javax.inject.Inject
109
import org.gradle.api.Plugin
1110
import org.gradle.api.Project
@@ -74,8 +73,6 @@ constructor(private val buildEvents: BuildEventListenerRegistryInternal) : Plugi
7473
const val SENTRY_PROJECT_PARAMETER = "sentryProject"
7574
internal const val SENTRY_SDK_VERSION = BuildConfig.SdkVersion
7675

77-
internal val sep = File.separator
78-
7976
// a single unified logger used by instrumentation
8077
internal val logger by lazy { LoggerFactory.getLogger(SentryPlugin::class.java) }
8178
}

plugin-build/src/main/kotlin/io/sentry/android/gradle/SentryPropertiesFileProvider.kt

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,37 @@ internal object SentryPropertiesFileProvider {
2525
val projDir = project.projectDir
2626
val rootDir = project.rootDir
2727

28-
val sep = File.separator
29-
3028
// Local Project dirs
3129
val possibleFiles = mutableListOf<String>()
3230
if (buildTypeName.isNotBlank()) {
33-
possibleFiles.add("${projDir}${sep}src${sep}${buildTypeName}${sep}$FILENAME")
31+
possibleFiles.add("${projDir}/src/${buildTypeName}/$FILENAME")
3432
}
3533
if (flavorName.isNotBlank()) {
3634
if (buildTypeName.isNotBlank()) {
37-
possibleFiles.add(
38-
"${projDir}${sep}src${sep}${buildTypeName}${sep}$flavorName${sep}$FILENAME"
39-
)
40-
possibleFiles.add(
41-
"${projDir}${sep}src${sep}${flavorName}${sep}${buildTypeName}${sep}$FILENAME"
42-
)
35+
possibleFiles.add("${projDir}/src/${buildTypeName}/$flavorName/$FILENAME")
36+
possibleFiles.add("${projDir}/src/${flavorName}/${buildTypeName}/$FILENAME")
4337
}
44-
possibleFiles.add("${projDir}${sep}src${sep}${flavorName}${sep}$FILENAME")
38+
possibleFiles.add("${projDir}/src/${flavorName}/$FILENAME")
4539
}
46-
possibleFiles.add("${projDir}${sep}$FILENAME")
40+
possibleFiles.add("${projDir}/$FILENAME")
4741

4842
// Other flavors dirs
4943
possibleFiles.addAll(
50-
variant?.productFlavors?.map { "${projDir}${sep}src${sep}${it}${sep}$FILENAME" }
51-
?: emptyList()
44+
variant?.productFlavors?.map { "${projDir}/src/${it}/$FILENAME" } ?: emptyList()
5245
)
5346

5447
// Root project dirs
5548
if (buildTypeName.isNotBlank()) {
56-
possibleFiles.add("${rootDir}${sep}src${sep}${buildTypeName}${sep}$FILENAME")
49+
possibleFiles.add("${rootDir}/src/${buildTypeName}/$FILENAME")
5750
}
5851
if (flavorName.isNotBlank()) {
59-
possibleFiles.add("${rootDir}${sep}src${sep}${flavorName}${sep}$FILENAME")
52+
possibleFiles.add("${rootDir}/src/${flavorName}/$FILENAME")
6053
if (buildTypeName.isNotBlank()) {
61-
possibleFiles.add(
62-
"${rootDir}${sep}src${sep}${buildTypeName}${sep}${flavorName}${sep}$FILENAME"
63-
)
64-
possibleFiles.add(
65-
"${rootDir}${sep}src${sep}${flavorName}${sep}${buildTypeName}${sep}$FILENAME"
66-
)
54+
possibleFiles.add("${rootDir}/src/${buildTypeName}/${flavorName}/$FILENAME")
55+
possibleFiles.add("${rootDir}/src/${flavorName}/${buildTypeName}/$FILENAME")
6756
}
6857
}
69-
possibleFiles.add("${rootDir}${sep}$FILENAME")
58+
possibleFiles.add("${rootDir}/$FILENAME")
7059

7160
return possibleFiles
7261
.distinct()

plugin-build/src/main/kotlin/io/sentry/android/gradle/SentryTasksProvider.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,10 @@ internal object SentryTasksProvider {
112112
dexguardEnabled: Boolean = false,
113113
): Provider<FileCollection> {
114114
if (dexguardEnabled) {
115-
val sep = File.separator
116115
if (project.plugins.hasPlugin("com.guardsquare.proguard")) {
117116
val fileCollection =
118117
project.files(
119-
File(
120-
project.buildDir,
121-
"outputs${sep}proguard${sep}${variant.name}${sep}mapping${sep}mapping.txt",
122-
)
118+
File(project.buildDir, "outputs/proguard/${variant.name}/mapping/mapping.txt")
123119
)
124120
return project.provider { fileCollection }
125121
}
@@ -135,25 +131,25 @@ internal object SentryTasksProvider {
135131
project.files(
136132
File(
137133
project.buildDir,
138-
basePath.plus(listOf("apk", variant.name, "mapping.txt")).joinToString(sep),
134+
basePath.plus(listOf("apk", variant.name, "mapping.txt")).joinToString("/"),
139135
),
140136
File(
141137
project.buildDir,
142-
basePath.plus(listOf("bundle", variant.name, "mapping.txt")).joinToString(sep),
138+
basePath.plus(listOf("bundle", variant.name, "mapping.txt")).joinToString("/"),
143139
),
144140
File(
145141
project.buildDir,
146142
basePath
147143
.plus(listOf("apk", variant.flavorName, variant.buildTypeName, "mapping.txt"))
148144
.filterNotNull()
149-
.joinToString(sep),
145+
.joinToString("/"),
150146
),
151147
File(
152148
project.buildDir,
153149
basePath
154150
.plus(listOf("bundle", variant.flavorName, variant.buildTypeName, "mapping.txt"))
155151
.filterNotNull()
156-
.joinToString(sep),
152+
.joinToString("/"),
157153
),
158154
)
159155
return project.provider { fileCollection }

plugin-build/src/main/kotlin/io/sentry/android/gradle/sourcecontext/CollectSourcesTask.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ internal class SourceCollector {
7575
if (sourceDir.exists()) {
7676
SentryPlugin.logger.debug { "Collecting sources in ${sourceDir.absolutePath}" }
7777
sourceDir.walk().forEach { sourceFile ->
78-
val relativePath =
79-
sourceFile.absolutePath
80-
.removePrefix(sourceDir.absolutePath)
81-
.removePrefix(File.separator)
78+
val relativePath = sourceFile.toRelativeString(sourceDir)
8279
val targetFile = outDir.resolve(File(relativePath))
8380
if (sourceFile.isFile) {
8481
if (relativePath.isBlank()) {

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadNativeSymbolsTask.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {
4141
args.add("--no-upload")
4242
}
4343

44-
val sep = File.separator
45-
4644
// eg absoluteProjectFolderPath/build/intermediates/merged_native_libs/{variantName}
4745
// where {variantName} could be debug/release...
4846
args.add(
49-
File(buildDir.get(), "intermediates${sep}merged_native_libs${sep}${variantName.get()}")
50-
.absolutePath
47+
File(buildDir.get(), "intermediates/merged_native_libs/${variantName.get()}").absolutePath
5148
)
5249

5350
// Only include sources if includeNativeSources is enabled, as this is opt-in feature

plugin-build/src/main/kotlin/io/sentry/jvm/gradle/SentryJvmPlugin.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import io.sentry.android.gradle.util.SentryPluginUtils
1414
import io.sentry.android.gradle.util.hookWithAssembleTasks
1515
import io.sentry.android.gradle.util.info
1616
import io.sentry.gradle.common.JavaVariant
17-
import java.io.File
1817
import java.util.concurrent.atomic.AtomicBoolean
1918
import javax.inject.Inject
2019
import org.gradle.api.Plugin
@@ -45,7 +44,7 @@ constructor(private val buildEvents: BuildEventListenerRegistryInternal) : Plugi
4544

4645
val javaExtension = project.extensions.getByType(JavaPluginExtension::class.java)
4746

48-
val sentryResDir = project.layout.buildDirectory.dir("generated${sep}sentry")
47+
val sentryResDir = project.layout.buildDirectory.dir("generated/sentry")
4948

5049
val javaVariant = JavaVariant(project, javaExtension)
5150
val outputPaths = OutputPaths(project, "java")
@@ -135,8 +134,4 @@ constructor(private val buildEvents: BuildEventListenerRegistryInternal) : Plugi
135134
project.installDependencies(extension, false)
136135
}
137136
}
138-
139-
companion object {
140-
internal val sep = File.separator
141-
}
142137
}

plugin-build/src/test/kotlin/io/sentry/android/gradle/SentryCliProviderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class SentryCliProviderTest {
113113

114114
val foundPath = getResourceUrl(resourcePath)
115115
assertNotNull(foundPath)
116-
assertTrue(foundPath.endsWith("${File.separator}dummy-bin${File.separator}dummy-sentry-cli"))
116+
assertTrue(foundPath.endsWith("/dummy-bin/dummy-sentry-cli"))
117117

118118
resourceFile?.delete()
119119
}

plugin-build/src/test/kotlin/io/sentry/android/gradle/SentryPropertiesFileProviderTest.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ import org.junit.runners.Parameterized
1414
@RunWith(Parameterized::class)
1515
class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
1616

17-
private val sep = File.separator
18-
1917
@Test
2018
fun `getPropertiesFilePath finds file inside debug folder`() {
2119
val (project, _) = createTestAndroidProject(forceEvaluate = !AgpVersions.isAGP74(agpVersion))
22-
createTestFile(project.projectDir, "src${sep}debug${sep}sentry.properties")
20+
createTestFile(project.projectDir, "src/debug/sentry.properties")
2321

2422
val variant = project.retrieveAndroidVariant("debug")
2523

@@ -44,7 +42,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
4442
productFlavors.create("lite")
4543
productFlavors.create("full")
4644
}
47-
createTestFile(project.projectDir, "src${sep}lite${sep}sentry.properties")
45+
createTestFile(project.projectDir, "src/lite/sentry.properties")
4846

4947
val variant = project.retrieveAndroidVariant("liteDebug")
5048

@@ -59,7 +57,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
5957
productFlavors.create("lite")
6058
productFlavors.create("full")
6159
}
62-
createTestFile(project.projectDir, "src${sep}lite${sep}debug${sep}sentry.properties")
60+
createTestFile(project.projectDir, "src/lite/debug/sentry.properties")
6361

6462
val variant = project.retrieveAndroidVariant("liteDebug")
6563

@@ -74,7 +72,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
7472
productFlavors.create("lite")
7573
productFlavors.create("full")
7674
}
77-
createTestFile(project.projectDir, "src${sep}debug${sep}lite${sep}sentry.properties")
75+
createTestFile(project.projectDir, "src/debug/lite/sentry.properties")
7876

7977
val variant = project.retrieveAndroidVariant("liteDebug")
8078

@@ -89,7 +87,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
8987
productFlavors.create("lite") { it.dimension("version") }
9088
productFlavors.create("api30") { it.dimension("api") }
9189
}
92-
createTestFile(project.projectDir, "src${sep}liteApi30${sep}sentry.properties")
90+
createTestFile(project.projectDir, "src/liteApi30/sentry.properties")
9391

9492
val variant = project.retrieveAndroidVariant("liteApi30Debug")
9593

@@ -104,7 +102,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
104102
productFlavors.create("lite") { it.dimension("version") }
105103
productFlavors.create("api30") { it.dimension("api") }
106104
}
107-
createTestFile(project.projectDir, "src${sep}api30${sep}sentry.properties")
105+
createTestFile(project.projectDir, "src/api30/sentry.properties")
108106

109107
val variant = project.retrieveAndroidVariant("liteApi30Debug")
110108

@@ -134,7 +132,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
134132
parent = rootProject,
135133
forceEvaluate = !AgpVersions.isAGP74(agpVersion),
136134
)
137-
createTestFile(rootProject.projectDir, "src${sep}debug${sep}sentry.properties")
135+
createTestFile(rootProject.projectDir, "src/debug/sentry.properties")
138136

139137
val variant = project.retrieveAndroidVariant("debug")
140138

@@ -152,7 +150,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
152150
flavorDimensions("version")
153151
productFlavors.create("lite")
154152
}
155-
createTestFile(rootProject.projectDir, "src${sep}lite${sep}sentry.properties")
153+
createTestFile(rootProject.projectDir, "src/lite/sentry.properties")
156154

157155
val variant = project.retrieveAndroidVariant("liteDebug")
158156

@@ -170,7 +168,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
170168
flavorDimensions("version")
171169
productFlavors.create("lite")
172170
}
173-
createTestFile(rootProject.projectDir, "src${sep}lite${sep}debug${sep}sentry.properties")
171+
createTestFile(rootProject.projectDir, "src/lite/debug/sentry.properties")
174172

175173
val variant = project.retrieveAndroidVariant("liteDebug")
176174

@@ -194,7 +192,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
194192
forceEvaluate = !AgpVersions.isAGP74(agpVersion),
195193
)
196194
// Only place the file under src/debug/ — with null variant this should not be found
197-
createTestFile(project.projectDir, "src${sep}debug${sep}sentry.properties")
195+
createTestFile(project.projectDir, "src/debug/sentry.properties")
198196

199197
assertEquals(null, getPropertiesFilePath(project))
200198
}
@@ -210,7 +208,7 @@ class SentryPropertiesFileProviderTest(private val agpVersion: SemVer) {
210208
flavorDimensions("version")
211209
productFlavors.create("lite")
212210
}
213-
createTestFile(rootProject.projectDir, "src${sep}debug${sep}lite${sep}sentry.properties")
211+
createTestFile(rootProject.projectDir, "src/debug/lite/sentry.properties")
214212

215213
val variant = project.retrieveAndroidVariant("liteDebug")
216214

0 commit comments

Comments
 (0)