Skip to content

Commit 465de40

Browse files
authored
Merge 2f9b728 into f43539f
2 parents f43539f + 2f9b728 commit 465de40

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-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+
### Features
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.16.1-alpha.2
410

511
### Fixes

sentry/api/sentry.api

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6743,7 +6743,10 @@ public abstract interface class io/sentry/util/CollectionUtils$Predicate {
67436743
public final class io/sentry/util/DebugMetaPropertiesApplier {
67446744
public static field DEBUG_META_PROPERTIES_FILENAME Ljava/lang/String;
67456745
public fun <init> ()V
6746+
public static fun apply (Lio/sentry/SentryOptions;Ljava/util/List;)V
67466747
public static fun applyToOptions (Lio/sentry/SentryOptions;Ljava/util/List;)V
6748+
public static fun getBuildTool (Ljava/util/Properties;)Ljava/lang/String;
6749+
public static fun getBuildToolVersion (Ljava/util/Properties;)Ljava/lang/String;
67476750
public static fun getProguardUuid (Ljava/util/Properties;)Ljava/lang/String;
67486751
}
67496752

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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
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 java.net.URL
79
import java.nio.charset.Charset
810
import java.util.Collections
911
import kotlin.test.Test
12+
import kotlin.test.assertContains
1013
import kotlin.test.assertEquals
14+
import kotlin.test.assertFalse
1115
import kotlin.test.assertNotNull
1216
import kotlin.test.assertNull
1317
import org.mockito.kotlin.mock
@@ -139,4 +143,79 @@ class ResourcesDebugMetaLoaderTest {
139143

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

0 commit comments

Comments
 (0)