Skip to content

Commit 31f5880

Browse files
authored
Merge 2a4fb26 into 6f23a76
2 parents 6f23a76 + 2a4fb26 commit 31f5880

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Internal
6+
7+
- Read build tool info from `sentry-debug-meta.properties` and attach it to events ([#4314](https://github.com/getsentry/sentry-java/pull/4314))
8+
39
## 8.6.0
410

511
### Behavioral Changes

sentry/api/sentry.api

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6364,7 +6364,10 @@ public abstract interface class io/sentry/util/CollectionUtils$Predicate {
63646364
public final class io/sentry/util/DebugMetaPropertiesApplier {
63656365
public static field DEBUG_META_PROPERTIES_FILENAME Ljava/lang/String;
63666366
public fun <init> ()V
6367+
public static fun apply (Lio/sentry/SentryOptions;Ljava/util/List;)V
63676368
public static fun applyToOptions (Lio/sentry/SentryOptions;Ljava/util/List;)V
6369+
public static fun getBuildTool (Ljava/util/Properties;)Ljava/lang/String;
6370+
public static fun getBuildToolVersion (Ljava/util/Properties;)Ljava/lang/String;
63686371
public static fun getProguardUuid (Ljava/util/Properties;)Ljava/lang/String;
63696372
}
63706373

sentry/src/main/java/io/sentry/util/DebugMetaPropertiesApplier.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.util;
22

3+
import io.sentry.SentryIntegrationPackageStorage;
34
import io.sentry.SentryLevel;
45
import io.sentry.SentryOptions;
56
import java.util.List;
@@ -11,6 +12,14 @@ public final class DebugMetaPropertiesApplier {
1112

1213
public static @NotNull String DEBUG_META_PROPERTIES_FILENAME = "sentry-debug-meta.properties";
1314

15+
public static void apply(
16+
final @NotNull SentryOptions options, final @Nullable List<Properties> debugMetaProperties) {
17+
if (debugMetaProperties != null) {
18+
applyToOptions(options, debugMetaProperties);
19+
applyBuildTool(options, debugMetaProperties);
20+
}
21+
}
22+
1423
public static void applyToOptions(
1524
final @NotNull SentryOptions options, final @Nullable List<Properties> debugMetaProperties) {
1625
if (debugMetaProperties != null) {
@@ -49,7 +58,35 @@ private static void applyProguardUuid(
4958
}
5059
}
5160

61+
private static void applyBuildTool(
62+
final @NotNull SentryOptions options, @NotNull List<Properties> debugMetaProperties) {
63+
for (Properties properties : debugMetaProperties) {
64+
final @Nullable String buildTool = getBuildTool(properties);
65+
if (buildTool != null) {
66+
@Nullable String buildToolVersion = getBuildToolVersion(properties);
67+
if (buildToolVersion == null) {
68+
buildToolVersion = "unknown";
69+
}
70+
options
71+
.getLogger()
72+
.log(
73+
SentryLevel.DEBUG, "Build tool found: %s, version %s", buildTool, buildToolVersion);
74+
SentryIntegrationPackageStorage.getInstance().addPackage(buildTool, buildToolVersion);
75+
break;
76+
}
77+
}
78+
}
79+
5280
public static @Nullable String getProguardUuid(final @NotNull Properties debugMetaProperties) {
5381
return debugMetaProperties.getProperty("io.sentry.ProguardUuids");
5482
}
83+
84+
public static @Nullable String getBuildTool(final @NotNull Properties debugMetaProperties) {
85+
return debugMetaProperties.getProperty("io.sentry.build-tool");
86+
}
87+
88+
public static @Nullable String getBuildToolVersion(
89+
final @NotNull Properties debugMetaProperties) {
90+
return debugMetaProperties.getProperty("io.sentry.build-tool-version");
91+
}
5592
}

sentry/src/test/java/io/sentry/internal/debugmeta/ResourcesDebugMetaLoaderTest.kt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package io.sentry.internal.debugmeta
22

33
import io.sentry.ILogger
4+
import io.sentry.SentryIntegrationPackageStorage
45
import io.sentry.SentryOptions
6+
import io.sentry.protocol.SentryPackage
57
import io.sentry.util.DebugMetaPropertiesApplier
68
import org.mockito.kotlin.mock
79
import org.mockito.kotlin.whenever
810
import java.net.URL
911
import java.nio.charset.Charset
1012
import java.util.Collections
1113
import kotlin.test.Test
14+
import kotlin.test.assertContains
1215
import kotlin.test.assertEquals
16+
import kotlin.test.assertFalse
1317
import kotlin.test.assertNotNull
1418
import kotlin.test.assertNull
1519

@@ -132,4 +136,72 @@ class ResourcesDebugMetaLoaderTest {
132136

133137
assertNull(sut.loadDebugMeta())
134138
}
139+
140+
@Test
141+
fun `reads build-tool and build-version and adds them to packages`() {
142+
val sut = fixture.getSut(
143+
content = listOf(
144+
"""
145+
#Generated by sentry-maven-plugin
146+
#Wed May 17 15:33:34 CEST 2023
147+
io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b
148+
io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68
149+
io.sentry.build-tool=maven
150+
io.sentry.build-tool-version=1.0
151+
""".trimIndent()
152+
)
153+
)
154+
155+
val options = SentryOptions()
156+
assertNotNull(sut.loadDebugMeta()) {
157+
DebugMetaPropertiesApplier.apply(options, it)
158+
}
159+
160+
val expected = SentryPackage("maven", "1.0")
161+
assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected)
162+
}
163+
164+
@Test
165+
fun `reads build-tool and adds it to packages with unknown version if build-tool-version is absent`() {
166+
val sut = fixture.getSut(
167+
content = listOf(
168+
"""
169+
#Generated by sentry-maven-plugin
170+
#Wed May 17 15:33:34 CEST 2023
171+
io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b
172+
io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68
173+
io.sentry.build-tool=maven
174+
""".trimIndent()
175+
)
176+
)
177+
178+
val options = SentryOptions()
179+
assertNotNull(sut.loadDebugMeta()) {
180+
DebugMetaPropertiesApplier.apply(options, it)
181+
}
182+
183+
val expected = SentryPackage("maven", "unknown")
184+
assertContains(SentryIntegrationPackageStorage.getInstance().packages, expected)
185+
}
186+
187+
@Test
188+
fun `does not add build-tool to packages if absent`() {
189+
val sut = fixture.getSut(
190+
content = listOf(
191+
"""
192+
#Generated manually
193+
#Wed May 17 15:33:34 CEST 2023
194+
io.sentry.ProguardUuids=34077988-a0e5-4839-9618-7400e1616d1b
195+
io.sentry.bundle-ids=88ba82db-cd26-4c09-8b31-21461d286b68
196+
""".trimIndent()
197+
)
198+
)
199+
200+
val options = SentryOptions()
201+
assertNotNull(sut.loadDebugMeta()) {
202+
DebugMetaPropertiesApplier.apply(options, it)
203+
}
204+
205+
assertFalse { SentryIntegrationPackageStorage.getInstance().packages.any { it.name.equals("io.sentry.build-tool") } }
206+
}
135207
}

0 commit comments

Comments
 (0)