|
1 | 1 | import org.apache.tools.ant.taskdefs.condition.Os |
2 | 2 |
|
| 3 | +import java.util.regex.Matcher |
| 4 | +import java.util.regex.Pattern |
| 5 | + |
3 | 6 | def config = project.hasProperty("sentry") ? project.sentry : []; |
4 | 7 |
|
5 | 8 | gradle.projectsEvaluated { |
6 | 9 | def releases = [:]; |
7 | 10 | android.applicationVariants.each { variant -> |
8 | 11 | def releaseName = "${variant.getApplicationId()}-${variant.getVersionName()}"; |
9 | 12 | variant.outputs.each { output -> |
10 | | - def processTask = output.getProcessResources(); |
11 | 13 | def versionCode = output.getVersionCode(); |
12 | | - releases[releaseName] = [output.getName(), releaseName, versionCode]; |
| 14 | + releases[variant.getName()] = [output.getName(), releaseName, versionCode]; |
13 | 15 | } |
14 | 16 | } |
15 | | - |
16 | 17 | // separately we then hook into the bundle task of react native to inject |
17 | 18 | // sourcemap generation parameters. In case for whatever reason no release |
18 | 19 | // was found for the asset folder we just bail. |
@@ -59,85 +60,100 @@ gradle.projectsEvaluated { |
59 | 60 | // .findAll{!['class', 'active'].contains(it.key)} |
60 | 61 | // .join('\n') |
61 | 62 |
|
| 63 | + def currentVariant = ""; |
| 64 | + def pattern = Pattern.compile("bundle([A-Z][A-Za-z]+)JsAndAssets") |
| 65 | + Matcher matcher = pattern.matcher(bundleTask.name) |
| 66 | + if (matcher.find()) { |
| 67 | + def match = matcher.group(1); |
| 68 | + currentVariant = match.substring(0, 1).toLowerCase() + match.substring(1); |
| 69 | + } |
| 70 | + |
| 71 | + def currentRelease = null; |
62 | 72 | releases.each { key, release -> |
63 | | - def variant = release[0] |
64 | | - def releaseName = release[1] |
65 | | - def versionCodes = release[2] |
66 | | - |
67 | | - def cliTask = tasks.create( |
68 | | - name: bundleTask.getName() + variant + "SentryUpload", |
69 | | - type: Exec) { |
70 | | - description = "upload debug symbols to sentry" |
71 | | - |
72 | | - def propertiesFile = "$reactRoot/android/sentry.properties"; |
73 | | - if (config.flavorAware) { |
74 | | - propertiesFile = "$reactRoot/android/sentry-$variant"+".properties" |
75 | | - println "For $variant using: $propertiesFile" |
76 | | - } else { |
77 | | - environment("SENTRY_PROPERTIES", propertiesFile) |
78 | | - } |
79 | | - Properties sentryProps = new Properties(); |
80 | | - try { |
81 | | - sentryProps.load(new FileInputStream(propertiesFile)); |
82 | | - } catch (FileNotFoundException e) { |
83 | | - println "File not found: $propertiesFile" |
84 | | - } |
85 | | - def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/sentry-cli-binary/bin/sentry-cli"); |
86 | | - |
87 | | - workingDir reactRoot |
88 | | - |
89 | | - def args = [ |
90 | | - cliExecutable |
91 | | - ]; |
92 | | - if (config.logLevel) { |
93 | | - args.push("--log-level"); |
94 | | - args.push(config.logLevel); |
95 | | - } |
96 | | - |
97 | | - if (config.flavorAware) { |
98 | | - args.push("--url"); |
99 | | - args.push(sentryProps.get("defaults.url")); |
100 | | - args.push("--auth-token"); |
101 | | - args.push(sentryProps.get("auth.token")); |
102 | | - } |
103 | | - |
104 | | - args.push("react-native"); |
105 | | - args.push("gradle"); |
106 | | - args.push("--bundle"); |
107 | | - args.push(bundleOutput); |
108 | | - args.push("--sourcemap"); |
109 | | - args.push(sourcemapOutput); |
110 | | - args.push("--release"); |
111 | | - args.push(releaseName); |
112 | | - |
113 | | - if (config.flavorAware) { |
114 | | - args.push("--org"); |
115 | | - args.push(sentryProps.get("defaults.org")); |
116 | | - args.push("--project"); |
117 | | - args.push(sentryProps.get("defaults.project")); |
118 | | - } |
119 | | - |
120 | | - versionCodes.each { versionCode -> |
121 | | - args.add("--dist"); |
122 | | - args.add(versionCode); |
123 | | - } |
124 | | - |
125 | | - if (config.logLevel) { |
126 | | - println args |
127 | | - } |
128 | | - if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
129 | | - commandLine("cmd", "/c", *args) |
130 | | - } else { |
131 | | - commandLine(*args) |
132 | | - } |
133 | | - enabled true |
| 73 | + if (key == currentVariant) { |
| 74 | + currentRelease = release; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + if (currentRelease == null) return; |
| 79 | + |
| 80 | + def variant = currentRelease[0] |
| 81 | + def releaseName = currentRelease[1] |
| 82 | + def versionCodes = currentRelease[2] |
| 83 | + |
| 84 | + def cliTask = tasks.create( |
| 85 | + name: bundleTask.getName() + variant + "SentryUpload", |
| 86 | + type: Exec) { |
| 87 | + description = "upload debug symbols to sentry" |
| 88 | + |
| 89 | + def propertiesFile = "$reactRoot/android/sentry.properties"; |
| 90 | + if (config.flavorAware) { |
| 91 | + propertiesFile = "$reactRoot/android/sentry-$variant"+".properties" |
| 92 | + println "For $variant using: $propertiesFile" |
| 93 | + } else { |
| 94 | + environment("SENTRY_PROPERTIES", propertiesFile) |
| 95 | + } |
| 96 | + Properties sentryProps = new Properties(); |
| 97 | + try { |
| 98 | + sentryProps.load(new FileInputStream(propertiesFile)); |
| 99 | + } catch (FileNotFoundException e) { |
| 100 | + println "File not found: $propertiesFile" |
134 | 101 | } |
| 102 | + def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/sentry-cli-binary/bin/sentry-cli"); |
| 103 | + |
| 104 | + workingDir reactRoot |
135 | 105 |
|
136 | | - bundleTask.doLast { |
137 | | - cliTask.execute(); |
| 106 | + def args = [ |
| 107 | + cliExecutable |
| 108 | + ]; |
| 109 | + if (config.logLevel) { |
| 110 | + args.push("--log-level"); |
| 111 | + args.push(config.logLevel); |
138 | 112 | } |
139 | 113 |
|
140 | | - cliTask.dependsOn(bundleTask) |
| 114 | + if (config.flavorAware) { |
| 115 | + args.push("--url"); |
| 116 | + args.push(sentryProps.get("defaults.url")); |
| 117 | + args.push("--auth-token"); |
| 118 | + args.push(sentryProps.get("auth.token")); |
| 119 | + } |
| 120 | + |
| 121 | + args.push("react-native"); |
| 122 | + args.push("gradle"); |
| 123 | + args.push("--bundle"); |
| 124 | + args.push(bundleOutput); |
| 125 | + args.push("--sourcemap"); |
| 126 | + args.push(sourcemapOutput); |
| 127 | + args.push("--release"); |
| 128 | + args.push(releaseName); |
| 129 | + |
| 130 | + if (config.flavorAware) { |
| 131 | + args.push("--org"); |
| 132 | + args.push(sentryProps.get("defaults.org")); |
| 133 | + args.push("--project"); |
| 134 | + args.push(sentryProps.get("defaults.project")); |
| 135 | + } |
| 136 | + |
| 137 | + versionCodes.each { versionCode -> |
| 138 | + args.add("--dist"); |
| 139 | + args.add(versionCode); |
| 140 | + } |
| 141 | + |
| 142 | + if (config.logLevel) { |
| 143 | + println args |
| 144 | + } |
| 145 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 146 | + commandLine("cmd", "/c", *args) |
| 147 | + } else { |
| 148 | + commandLine(*args) |
| 149 | + } |
| 150 | + enabled true |
141 | 151 | } |
| 152 | + |
| 153 | + bundleTask.doLast { |
| 154 | + cliTask.execute(); |
| 155 | + } |
| 156 | + |
| 157 | + cliTask.dependsOn(bundleTask) |
142 | 158 | } |
143 | 159 | } |
0 commit comments