forked from getsentry/sentry-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry.gradle
More file actions
184 lines (157 loc) · 6.21 KB
/
sentry.gradle
File metadata and controls
184 lines (157 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import org.apache.tools.ant.taskdefs.condition.Os
import java.util.regex.Matcher
import java.util.regex.Pattern
def config = project.hasProperty("sentryCli") ? project.sentryCli : [];
gradle.projectsEvaluated {
def releases = [:];
android.applicationVariants.each { variant ->
def releaseName = "${variant.getApplicationId()}-${variant.getVersionName()}";
variant.outputs.each { output ->
def versionCode = output.getVersionCode();
def variantName = variant.getName();
def outputName = output.getName();
if (releases[variantName] == null) {
releases[variantName] = [:];
}
releases[variantName][outputName] = [outputName, releaseName, versionCode];
}
}
// separately we then hook into the bundle task of react native to inject
// sourcemap generation parameters. In case for whatever reason no release
// was found for the asset folder we just bail.
def bundleTasks = tasks.findAll { task ->
task.name.startsWith("bundle") && task.name.endsWith("JsAndAssets")
}
bundleTasks.each { bundleTask ->
def props = bundleTask.getProperties();
def cmd = props.get("commandLine") as List<String>;
def cmdArgs = props.get("args") as List<String>;
def bundleOutput = null;
def sourcemapOutput = null;
def reactRoot = props.get("workingDir");
def shouldCleanUp = false;
cmdArgs.eachWithIndex{ String arg, int i ->
if (arg == "--bundle-output") {
bundleOutput = cmdArgs[i + 1];
} else if (arg == "--sourcemap-output") {
sourcemapOutput = cmdArgs[i + 1];
}
}
if (sourcemapOutput == null) {
sourcemapOutput = bundleOutput + ".map";
cmd.push("--sourcemap-output");
cmd.push(sourcemapOutput);
cmdArgs.push("--sourcemap-output");
cmdArgs.push(sourcemapOutput);
shouldCleanUp = true
}
bundleTask.setProperty("commandLine", cmd);
bundleTask.setProperty("args", cmdArgs);
if (config.flavorAware) {
println "**********************************"
println "* Flavor aware sentry properties *"
println "**********************************"
}
// Lets leave this here if we need to debug
// println bundleTask.properties
// .sort{it.key}
// .collect{it}
// .findAll{!['class', 'active'].contains(it.key)}
// .join('\n')
def currentRelease = "";
def pattern = Pattern.compile("bundle([A-Z][A-Za-z0-9]+)JsAndAssets")
Matcher matcher = pattern.matcher(bundleTask.name)
if (matcher.find()) {
def match = matcher.group(1);
currentRelease = match.substring(0, 1).toLowerCase() + match.substring(1);
}
def currentVariants = null;
releases.each { key, release ->
if (key == currentRelease) {
currentVariants = release;
}
}
def variant = null;
def releaseName = null;
def versionCodes = new ArrayList<Integer>(currentVariants.size());
if (currentVariants == null) return;
currentVariants.each { key, currentVariant ->
variant = currentVariant[0];
releaseName = currentVariant[1];
versionCodes.push(currentVariant[2]);
}
def cliTask = tasks.create(
name: bundleTask.getName() + variant + "SentryUpload",
type: Exec) {
description = "upload debug symbols to sentry"
def propertiesFile = "$reactRoot/android/sentry.properties";
if (config.flavorAware) {
propertiesFile = "$reactRoot/android/sentry-$variant"+".properties"
println "For $variant using: $propertiesFile"
} else {
environment("SENTRY_PROPERTIES", propertiesFile)
}
Properties sentryProps = new Properties();
try {
sentryProps.load(new FileInputStream(propertiesFile));
} catch (FileNotFoundException e) {
println "File not found: $propertiesFile"
}
def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/@sentry/cli/bin/sentry-cli");
workingDir reactRoot
def args = [
cliExecutable
];
if (config.logLevel) {
args.push("--log-level");
args.push(config.logLevel);
}
if (config.flavorAware) {
args.push("--url");
args.push(sentryProps.get("defaults.url"));
args.push("--auth-token");
args.push(sentryProps.get("auth.token"));
}
args.push("react-native");
args.push("gradle");
args.push("--bundle");
args.push(bundleOutput);
args.push("--sourcemap");
args.push(sourcemapOutput);
args.push("--release");
args.push(releaseName);
if (config.flavorAware) {
args.push("--org");
args.push(sentryProps.get("defaults.org"));
args.push("--project");
args.push(sentryProps.get("defaults.project"));
}
versionCodes.each { versionCode ->
args.add("--dist");
args.add(versionCode);
}
if (config.logLevel) {
println args
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", *args)
} else {
commandLine(*args)
}
enabled true
}
def cliCleanUpTask = tasks.create(
name: bundleTask.getName() + variant + "SentryUploadCleanUp",
type: Delete) {
description = "clean up extra sourcemap"
delete sourcemapOutput
};
bundleTask.doLast {
cliTask.execute();
if (shouldCleanUp) {
cliCleanUpTask.execute();
}
}
cliTask.dependsOn(bundleTask)
}
}