@@ -4,7 +4,6 @@ import okhttp3.*
44import org.gradle.api.Plugin
55import org.gradle.api.Project
66import org.gradle.api.tasks.StopActionException
7- import org.gradle.api.tasks.StopExecutionException
87
98import static groovy.io.FileType.FILES
109
@@ -20,29 +19,33 @@ class UploadSymbolsPluginExtension {
2019
2120class UploadSymbolsPlugin implements Plugin<Project > {
2221 void apply (Project project ) {
23- OkHttpClient client = null
24- Request request = null
2522 def ext = project. extensions. create(' countly' , UploadSymbolsPluginExtension )
2623 project. tasks. register(' uploadJavaSymbols' ) {
2724 group = " countly"
2825 description = " Upload Java minification mapping file mapping.txt to Countly server"
29- doFirst {
30- if (! ext. app_key) {
31- logger. error(" Please specify your app key in countly block." )
32- throw new StopExecutionException (" Please specify your app key in countly block." )
33- }
34- if (! ext. server) {
35- logger. error(" Please specify your server in countly block." )
36- throw new StopExecutionException (" Please specify your server in countly block." )
37- }
38- String buildVersion = project. android. defaultConfig. versionName
39- String url = ext. server;
40- String path = " i/crash_symbols/upload_symbol" ;
26+
27+ // Resolve project/extension values at configuration time to avoid
28+ // capturing non-serializable Project reference in task actions
29+ def buildVersion = project. android. defaultConfig. versionName
30+ def appKey = ext. app_key
31+ def serverUrl = ext. server
32+ def noteJava = ext. noteJava
33+ def mappingFilePath = " ${ project.buildDir} /${ ext.mappingFile} "
34+
35+ if (! appKey || ! serverUrl) {
36+ logger. warn(" [Countly] uploadJavaSymbols: 'app_key' or 'server' is empty. " +
37+ " Make sure the countly block is configured before this task is realized. " +
38+ " Disabling task." )
39+ enabled = false
40+ }
41+
42+ doLast {
43+ String url = serverUrl
44+ String path = " i/crash_symbols/upload_symbol"
4145 // Ensure there is exactly one "/" between the base URL and the path
42- url = url. endsWith(" /" ) ? url + path : url + " /" + path;
43- def filePath = " $project . buildDir /$ext . mappingFile "
44- logger. debug(" uploadJavaSymbols, Version name:[ {} ], Upload symbol url:[ {} ], Mapping file path:[ {} ]" , buildVersion, url, filePath)
45- File file = new File (filePath)
46+ url = url. endsWith(" /" ) ? url + path : url + " /" + path
47+ logger. debug(" uploadJavaSymbols, Version name:[ {} ], Upload symbol url:[ {} ], Mapping file path:[ {} ]" , buildVersion, url, mappingFilePath)
48+ File file = new File (mappingFilePath)
4649 if (! file. exists()) {
4750 logger. error(" Mapping file not found" )
4851 throw new StopActionException (" Mapping file not found" )
@@ -52,25 +55,19 @@ class UploadSymbolsPlugin implements Plugin<Project> {
5255 .addFormDataPart(" symbols" , file. getName(),
5356 RequestBody . create(MediaType . parse(" text/plain" ), file))
5457 .addFormDataPart(" platform" , " android" )
55- .addFormDataPart(" app_key" , ext . app_key )
58+ .addFormDataPart(" app_key" , appKey )
5659 .addFormDataPart(" build" , buildVersion)
57- .addFormDataPart(" note" , ext . noteJava)
60+ .addFormDataPart(" note" , noteJava)
5861 .build()
59- request = new Request.Builder (). url(url). post(formBody). build()
60- }
61- doLast {
62- if (request == null ) {
63- logger. error(" Request not constructed" )
64- throw new StopActionException (" Something happened while constructing the request. Please try again." )
65- }
62+ Request request = new Request.Builder (). url(url). post(formBody). build()
6663
6764 if (request. body() != null ) {
6865 logger. debug(" uploadJavaSymbols, Generated request: {}" , request. body(). toString())
6966 } else {
7067 logger. error(" uploadJavaSymbols, Request body is null which should not be the case" )
7168 }
7269
73- client = new OkHttpClient ()
70+ OkHttpClient client = new OkHttpClient ()
7471 Response response = client. newCall(request). execute()
7572
7673 if (response. code() != 200 ) {
@@ -88,28 +85,43 @@ class UploadSymbolsPlugin implements Plugin<Project> {
8885 project. tasks. register(' uploadNativeSymbols' ) {
8986 group = " countly"
9087 description = " Upload breakpad symbols folder to Countly server"
91- doFirst {
92- String buildVersion = project. android. defaultConfig. versionName
93- String url = " ${ ext.server} /i/crash_symbols/upload_symbol"
94- String breakpadVersion = " $ext . dumpSymsPath /dump_syms --version" . execute(). getText(). trim()
88+
89+ // Resolve project/extension values at configuration time to avoid
90+ // capturing non-serializable Project reference in task actions
91+ def buildVersion = project. android. defaultConfig. versionName
92+ def appKey = ext. app_key
93+ def serverUrl = ext. server
94+ def noteNative = ext. noteNative
95+ def dumpSymsPath = ext. dumpSymsPath
96+ def objectsDirPath = " ${ project.buildDir} /${ ext.nativeObjectFilesDir} "
97+ def countlyDirStr = " ${ project.buildDir} /intermediates/countly"
98+
99+ if (! appKey || ! serverUrl) {
100+ logger. warn(" [Countly] uploadNativeSymbols: 'app_key' or 'server' is empty. " +
101+ " Make sure the countly block is configured before this task is realized. " +
102+ " Disabling task." )
103+ enabled = false
104+ }
105+
106+ doLast {
107+ String url = " ${ serverUrl} /i/crash_symbols/upload_symbol"
108+ String breakpadVersion = " $dumpSymsPath /dump_syms --version" . execute(). getText(). trim()
95109
96110 if (! (breakpadVersion =~ / ^\d +\.\d +\+ cly$/ )) {
97111 breakpadVersion = " 0.1+bpd"
98112 }
99113
100- def objectsDir = new File (" $project . buildDir /$ext . nativeObjectFilesDir " )
101- def countlyDirStr = " $project . buildDir /intermediates/countly"
102- def countlyDir = new File (" $countlyDirStr " )
114+ def objectsDir = new File (objectsDirPath)
115+ def countlyDir = new File (countlyDirStr)
103116 logger. debug(" uploadNativeSymbols, Version name:[ {} ], Upload symbol url:[ {} ], objectsDir:[ {} ], countlyDirStr:[ {} ], countlyDir:[ {} ], breakpadVersion:[ {} ]" , buildVersion, url, objectsDir, countlyDirStr, countlyDir, breakpadVersion)
104117
105118 countlyDir. deleteDir()
106119 countlyDir. mkdirs()
107- // println "objectsDir=$objectsDir"
108120 def filterObjectFiles = ~/ .*\. so$/
109121 def i = 0
110122 def processFile = {
111123 i = i + 1
112- def cmd = " $e xt . dumpSymsPath /dump_syms $it "
124+ def cmd = " $dumpSymsPath /dump_syms $it "
113125 println cmd
114126 def proc = cmd. execute()
115127 def outputStream = new StringBuffer ()
@@ -131,23 +143,23 @@ class UploadSymbolsPlugin implements Plugin<Project> {
131143 }
132144 objectsDir. traverse type : FILES , visit : processFile, nameFilter : filterObjectFiles
133145 def tarFileName = " $countlyDirStr /symbols.tar.gz"
134- project. ant. tar(destfile : tarFileName, basedir : " $countlyDirStr " , includes : " symbols/**" , compression : " gzip" )
146+ // Use standalone AntBuilder instead of project.ant for configuration cache compatibility
147+ new groovy.ant.AntBuilder (). tar(destfile : tarFileName, basedir : " $countlyDirStr " , includes : " symbols/**" , compression : " gzip" )
135148 File file = new File (tarFileName)
136149 RequestBody formBody = new MultipartBody.Builder ()
137150 .setType(MultipartBody . FORM )
138151 .addFormDataPart(" symbols" , file. getName(),
139152 RequestBody . create(MediaType . parse(" text/plain" ), file))
140153 .addFormDataPart(" platform" , " android_native" )
141- .addFormDataPart(" app_key" , ext . app_key )
154+ .addFormDataPart(" app_key" , appKey )
142155 .addFormDataPart(" build" , buildVersion)
143- .addFormDataPart(" note" , ext . noteNative)
156+ .addFormDataPart(" note" , noteNative)
144157 .addFormDataPart(" sym_tool_ver" , breakpadVersion)
145158 .build()
146- request = new Request.Builder (). url(url). post(formBody). build()
159+ Request request = new Request.Builder (). url(url). post(formBody). build()
147160 logger. debug(" uploadNativeSymbols, Generated request: {}" , request. body(). toString())
148- }
149- doLast {
150- client = new OkHttpClient ()
161+
162+ OkHttpClient client = new OkHttpClient ()
151163 Response response = client. newCall(request). execute()
152164
153165 if (response. code() != 200 ) {
0 commit comments