17
17
package androidx.build.testConfiguration
18
18
19
19
import androidx.build.dependencyTracker.ProjectSubset
20
- import androidx.build.renameApkForTesting
21
- import com.android.build.api.variant.BuiltArtifact
22
20
import com.android.build.api.variant.BuiltArtifacts
23
21
import com.android.build.api.variant.BuiltArtifactsLoader
24
22
import java.io.File
@@ -78,18 +76,6 @@ abstract class GenerateMediaTestConfigurationTask : DefaultTask() {
78
76
@get:Input
79
77
abstract val affectedModuleDetectorSubset: Property <ProjectSubset >
80
78
81
- @get:Input
82
- abstract val clientToTPath: Property <String >
83
-
84
- @get:Input
85
- abstract val clientPreviousPath: Property <String >
86
-
87
- @get:Input
88
- abstract val serviceToTPath: Property <String >
89
-
90
- @get:Input
91
- abstract val servicePreviousPath: Property <String >
92
-
93
79
@get:Input
94
80
abstract val minSdk: Property <Int >
95
81
@@ -117,39 +103,60 @@ abstract class GenerateMediaTestConfigurationTask : DefaultTask() {
117
103
@get:OutputFile
118
104
abstract val jsonClientToTServiceToTServiceTests: RegularFileProperty
119
105
106
+ @get:OutputFile
107
+ abstract val previousClientApk: RegularFileProperty
108
+
109
+ @get:OutputFile
110
+ abstract val totClientApk: RegularFileProperty
111
+
112
+ @get:OutputFile
113
+ abstract val previousServiceApk: RegularFileProperty
114
+
115
+ @get:OutputFile
116
+ abstract val totServiceApk: RegularFileProperty
117
+
120
118
@TaskAction
121
119
fun generateAndroidTestZip () {
122
- val clientToTApk = resolveApk(clientToTFolder, clientToTLoader)
123
- val clientPreviousApk = resolveApk(clientPreviousFolder, clientPreviousLoader )
124
- val serviceToTApk = resolveApk(serviceToTFolder, serviceToTLoader)
125
- val servicePreviousApk = resolveApk (
126
- servicePreviousFolder, servicePreviousLoader
120
+ val clientToTApk = totClientApk.get().asFile
121
+ val clientToTSha256 = copyApkAndGetSha256(clientToTFolder, clientToTLoader, clientToTApk )
122
+ val clientPreviousApk = previousClientApk.get().asFile
123
+ val clientPreviousSha256 = copyApkAndGetSha256 (
124
+ clientPreviousFolder, clientPreviousLoader, clientPreviousApk
127
125
)
126
+ val serviceToTApk = totServiceApk.get().asFile
127
+ val serviceToTSha256 = copyApkAndGetSha256(
128
+ serviceToTFolder, serviceToTLoader, serviceToTApk
129
+ )
130
+ val servicePreviousApk = previousServiceApk.get().asFile
131
+ val servicePreviousSha256 = copyApkAndGetSha256(
132
+ servicePreviousFolder, servicePreviousLoader, servicePreviousApk
133
+ )
134
+
128
135
writeConfigFileContent(
129
- clientApk = clientToTApk,
130
- serviceApk = serviceToTApk,
131
- clientPath = clientToTPath.get() ,
132
- servicePath = serviceToTPath.get() ,
136
+ clientApkName = clientToTApk.name ,
137
+ serviceApkName = serviceToTApk.name ,
138
+ clientApkSha256 = clientToTSha256 ,
139
+ serviceApkSha256 = serviceToTSha256 ,
133
140
jsonClientOutputFile = jsonClientToTServiceToTClientTests,
134
141
jsonServiceOutputFile = jsonClientToTServiceToTServiceTests,
135
142
isClientPrevious = false ,
136
143
isServicePrevious = false
137
144
)
138
145
writeConfigFileContent(
139
- clientApk = clientToTApk,
140
- serviceApk = servicePreviousApk,
141
- clientPath = clientToTPath.get() ,
142
- servicePath = servicePreviousPath.get() ,
146
+ clientApkName = clientToTApk.name ,
147
+ serviceApkName = servicePreviousApk.name ,
148
+ clientApkSha256 = clientToTSha256 ,
149
+ serviceApkSha256 = servicePreviousSha256 ,
143
150
jsonClientOutputFile = jsonClientToTServicePreviousClientTests,
144
151
jsonServiceOutputFile = jsonClientToTServicePreviousServiceTests,
145
152
isClientPrevious = false ,
146
153
isServicePrevious = true
147
154
)
148
155
writeConfigFileContent(
149
- clientApk = clientPreviousApk,
150
- serviceApk = serviceToTApk,
151
- clientPath = clientPreviousPath.get() ,
152
- servicePath = serviceToTPath.get() ,
156
+ clientApkName = clientPreviousApk.name ,
157
+ serviceApkName = serviceToTApk.name ,
158
+ clientApkSha256 = clientPreviousSha256 ,
159
+ serviceApkSha256 = serviceToTSha256 ,
153
160
jsonClientOutputFile = jsonClientPreviousServiceToTClientTests,
154
161
jsonServiceOutputFile = jsonClientPreviousServiceToTServiceTests,
155
162
isClientPrevious = true ,
@@ -165,26 +172,27 @@ abstract class GenerateMediaTestConfigurationTask : DefaultTask() {
165
172
? : throw RuntimeException (" Cannot load required APK for task: $name " )
166
173
}
167
174
168
- private fun BuiltArtifact.resolveName (path : String ): String {
169
- return outputFile.substringAfterLast(" /" ).renameApkForTesting(path)
175
+ private fun copyApkAndGetSha256 (
176
+ apkFolder : DirectoryProperty ,
177
+ apkLoader : Property <BuiltArtifactsLoader >,
178
+ destination : File
179
+ ): String {
180
+ val artifacts = apkLoader.get().load(apkFolder.get())
181
+ ? : throw RuntimeException (" Cannot load required APK for task: $name " )
182
+ File (artifacts.elements.single().outputFile).copyTo(destination, overwrite = true )
183
+ return sha256(destination)
170
184
}
171
185
172
186
private fun writeConfigFileContent (
173
- clientApk : BuiltArtifacts ,
174
- serviceApk : BuiltArtifacts ,
175
- clientPath : String ,
176
- servicePath : String ,
187
+ clientApkName : String ,
188
+ serviceApkName : String ,
189
+ clientApkSha256 : String ,
190
+ serviceApkSha256 : String ,
177
191
jsonClientOutputFile : RegularFileProperty ,
178
192
jsonServiceOutputFile : RegularFileProperty ,
179
193
isClientPrevious : Boolean ,
180
194
isServicePrevious : Boolean ,
181
195
) {
182
- val clientBuiltArtifact = clientApk.elements.single()
183
- val serviceBuiltArtifact = serviceApk.elements.single()
184
- val clientApkName = clientBuiltArtifact.resolveName(clientPath)
185
- val clientApkSha256 = sha256(File (clientBuiltArtifact.outputFile))
186
- val serviceApkName = serviceBuiltArtifact.resolveName(servicePath)
187
- val serviceApkSha256 = sha256(File (serviceBuiltArtifact.outputFile))
188
196
createOrFail(jsonClientOutputFile).writeText(
189
197
buildMediaJson(
190
198
configName = jsonClientOutputFile.asFile.get().name,
0 commit comments