Skip to content

Commit f536793

Browse files
authored
Encode SDK_VERSION in a Java class instead of looking up a ResouceBun… (#609)
1 parent 27d5f6b commit f536793

7 files changed

Lines changed: 30 additions & 6 deletions

File tree

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Version 1.7.9
22
-------------
33

4-
-
4+
- Encode SDK_VERSION in a Java class instead of looking up a ResouceBundle.
55

66
Version 1.7.8
77
-------------

sentry/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@
9898
</resource>
9999
</resources>
100100
<plugins>
101+
<plugin>
102+
<groupId>org.codehaus.mojo</groupId>
103+
<artifactId>templating-maven-plugin</artifactId>
104+
<version>1.0.0</version>
105+
<executions>
106+
<execution>
107+
<id>filtering-java-templates</id>
108+
<goals>
109+
<goal>filter-sources</goal>
110+
</goals>
111+
</execution>
112+
</executions>
113+
</plugin>
101114
<plugin>
102115
<groupId>org.codehaus.mojo</groupId>
103116
<artifactId>buildnumber-maven-plugin</artifactId>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.sentry.environment;
2+
3+
public final class Version {
4+
public static final String SDK_VERSION = "${buildNumber}";
5+
6+
private Version() {
7+
8+
}
9+
}

sentry/src/main/java/io/sentry/environment/SentryEnvironment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import java.util.ResourceBundle;
76
import java.util.concurrent.atomic.AtomicInteger;
87

98
/**
@@ -20,7 +19,7 @@ public final class SentryEnvironment {
2019
/**
2120
* Version of this SDK.
2221
*/
23-
public static final String SDK_VERSION = ResourceBundle.getBundle("sentry-build").getString("build.name");
22+
public static final String SDK_VERSION = Version.SDK_VERSION;
2423
/**
2524
* Indicates whether the current thread is managed by sentry or not.
2625
*/

sentry/src/test/java/io/sentry/SentryTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.sentry.context.ContextManager;
77
import io.sentry.context.SingletonContextManager;
88
import io.sentry.dsn.Dsn;
9+
import io.sentry.environment.Version;
910
import io.sentry.event.Event;
1011
import io.sentry.event.EventBuilder;
1112
import io.sentry.event.helper.EventBuilderHelper;
@@ -141,7 +142,7 @@ public void testInitStringDsn() throws Exception {
141142
assertThat(sentryUrl.getPath(), equalTo("/api/1/store/"));
142143

143144
String authHeader = getField(connection, "authHeader");
144-
assertThat(authHeader, equalTo("Sentry sentry_version=6,sentry_client=sentry-java/test,sentry_key=public,sentry_secret=private"));
145+
assertThat(authHeader, equalTo("Sentry sentry_version=6,sentry_client=sentry-java/" + Version.SDK_VERSION + ",sentry_key=public,sentry_secret=private"));
145146
}
146147

147148
@Test
@@ -157,7 +158,7 @@ public void testInitStringDsnAndFactory() throws Exception {
157158
assertThat(sentryUrl.getPath(), equalTo("/api/1/store/"));
158159

159160
String authHeader = getField(connection, "authHeader");
160-
assertThat(authHeader, equalTo("Sentry sentry_version=6,sentry_client=sentry-java/test,sentry_key=public,sentry_secret=private"));
161+
assertThat(authHeader, equalTo("Sentry sentry_version=6,sentry_client=sentry-java/" + Version.SDK_VERSION + ",sentry_key=public,sentry_secret=private"));
161162
}
162163

163164
@Test

sentry/src/test/java/io/sentry/connection/AbstractConnectionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.connection;
22

33
import io.sentry.BaseTest;
4+
import io.sentry.environment.Version;
45
import io.sentry.time.FixedClock;
56
import mockit.*;
67
import io.sentry.event.Event;
@@ -40,7 +41,7 @@ public void testAuthHeader() throws Exception {
4041
String authHeader = abstractConnection.getAuthHeader();
4142

4243
assertThat(authHeader, is("Sentry sentry_version=6,"
43-
+ "sentry_client=sentry-java/test,"
44+
+ "sentry_client=sentry-java/" + Version.SDK_VERSION + ","
4445
+ "sentry_key=" + publicKey + ","
4546
+ "sentry_secret=" + secretKey));
4647
}

src/checkstyle/suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
<suppressions>
77
<suppress files="io.sentry/util/CircularFifoQueue\.java" checks=".*"/>
8+
<suppress files="io.sentry/environment/Version\.java" checks=".*"/>
89
</suppressions>

0 commit comments

Comments
 (0)