Skip to content

Commit 74ec796

Browse files
authored
Merge pull request #212 from getsentry/feature/flavoraware
Add functionality for flavor aware sentry properties in gradle
2 parents 0248a25 + 0cb540a commit 74ec796

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

appium/fastlane/Fastfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ platform :ios do
6868
end
6969

7070
lane :build_android_for_device_farm do
71-
android_build_output = sh("cd ../example/android/; ./gradlew -Psentryloglevel=debug assembleRelease --stacktrace")
71+
android_build_output = sh("cd ../example/android/; ./gradlew assembleRelease --stacktrace")
7272
validate_android_build_output(android_build_output)
7373
sh("jarsigner -verbose -digestalg SHA1 -sigalg MD5withRSA -keystore release.keystore -storepass 123456 ../example/android/app/build/outputs/apk/app-full-release-unsigned.apk release")
7474
end

examples

sentry.gradle

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
22

3+
def config = project.hasProperty("sentry") ? project.sentry : [];
4+
35
gradle.projectsEvaluated {
46
def releases = [];
57
android.applicationVariants.each { variant ->
@@ -24,12 +26,6 @@ gradle.projectsEvaluated {
2426
def bundleOutput = null;
2527
def sourcemapOutput = null;
2628
def reactRoot = props.get("workingDir");
27-
def propertiesFile = "$reactRoot/android/sentry.properties";
28-
Properties sentryProps = new Properties();
29-
try {
30-
sentryProps.load(new FileInputStream(propertiesFile));
31-
} catch (FileNotFoundException e) {}
32-
def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/sentry-cli-binary/bin/sentry-cli");
3329

3430
cmdArgs.eachWithIndex{ String arg, int i ->
3531
if (arg == "--bundle-output") {
@@ -50,22 +46,50 @@ gradle.projectsEvaluated {
5046
bundleTask.setProperty("commandLine", cmd);
5147
bundleTask.setProperty("args", cmdArgs);
5248

49+
if (config.flavorAware) {
50+
println "**********************************"
51+
println "* Flavor aware sentry properties *"
52+
println "**********************************"
53+
}
54+
5355
releases.each { variant, releaseName, versionCodes ->
5456
def cliTask = tasks.create(
5557
name: bundleTask.getName() + variant + "SentryUpload",
5658
type: Exec) {
5759
description = "upload debug symbols to sentry"
5860

61+
def propertiesFile = "$reactRoot/android/sentry.properties";
62+
if (config.flavorAware) {
63+
propertiesFile = "$reactRoot/android/sentry-$variant"+".properties"
64+
println "For $variant using: $propertiesFile"
65+
} else {
66+
environment("SENTRY_PROPERTIES", propertiesFile)
67+
}
68+
Properties sentryProps = new Properties();
69+
try {
70+
sentryProps.load(new FileInputStream(propertiesFile));
71+
} catch (FileNotFoundException e) {
72+
println "File not found: $propertiesFile"
73+
}
74+
def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/sentry-cli-binary/bin/sentry-cli");
75+
5976
workingDir reactRoot
60-
environment("SENTRY_PROPERTIES", propertiesFile)
6177

6278
def args = [
6379
cliExecutable
6480
];
65-
if (project.hasProperty("sentryloglevel") ) {
81+
if (config.logLevel) {
6682
args.push("--log-level");
67-
args.push(sentryloglevel);
83+
args.push(config.logLevel);
6884
}
85+
86+
if (config.flavorAware) {
87+
args.push("--url");
88+
args.push(sentryProps.get("defaults.url"));
89+
args.push("--auth-token");
90+
args.push(sentryProps.get("auth.token"));
91+
}
92+
6993
args.push("react-native");
7094
args.push("gradle");
7195
args.push("--bundle");
@@ -75,11 +99,21 @@ gradle.projectsEvaluated {
7599
args.push("--release");
76100
args.push(releaseName);
77101

102+
if (config.flavorAware) {
103+
args.push("--org");
104+
args.push(sentryProps.get("defaults.org"));
105+
args.push("--project");
106+
args.push(sentryProps.get("defaults.project"));
107+
}
108+
78109
versionCodes.each { versionCode ->
79110
args.add("--dist");
80111
args.add(versionCode);
81112
}
82113

114+
if (config.logLevel) {
115+
println args
116+
}
83117
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
84118
commandLine("cmd", "/c", *args)
85119
} else {

0 commit comments

Comments
 (0)