@@ -41,24 +41,30 @@ configure(project) {
4141
4242/* ===FUNCTIONS=== */
4343
44- private Provider<String > getScriptExt () {
45- ext. lazyOsName. map { it. toLowerCase(Locale . ROOT ). contains(' windows' ) ? ' .bat' : ' .sh' }
46- }
47-
48- private Provider<String > getMavenVersion () {
49- ext. lazyVersion. map { it. endsWith(' -alpha' ) ? " ${ it} -SNAPSHOT" : it }
50- }
44+ import groovy.transform.Memoized
5145
46+ @Memoized
5247private Provider<String > getProjectId () {
5348 ext. lazyProjectId. map { it ?: { throw new InvalidUserDataException (' id in "zip-content/module.prop" is empty or not set.' ) }() }
5449}
5550
51+ @Memoized
52+ private Provider<String > getScriptExt () {
53+ ext. lazyOsName. map { it. toLowerCase(Locale . ROOT ). contains(' windows' ) ? ' .bat' : ' .sh' }
54+ }
55+
56+ @Memoized
5657private Provider<String > getGitCommitHash () {
5758 providers. exec {
5859 commandLine ' git' , ' rev-parse' , ' --short=8' , ' HEAD'
5960 }. standardOutput. asText. map{ it. trim() }. orElse(' unknown' )
6061}
6162
63+ @Memoized
64+ private Provider<String > getMavenVersion () {
65+ ext. lazyVersion. map { it. endsWith(' -alpha' ) ? " ${ it} -SNAPSHOT" : it }
66+ }
67+
6268private Provider<String > getZipName (String variant = ' *' ) {
6369 ext. lazyVersion. flatMap { v ->
6470 getProjectId(). zip(getGitCommitHash()) { id , hash ->
@@ -181,7 +187,7 @@ tasks.register('cleanRecoveryOutput', Delete) {
181187
182188tasks. named(' clean' ) {
183189 group = ' - Cleanup'
184- dependsOn tasks . named( ' cleanRecoveryOutput' )
190+ dependsOn ' cleanRecoveryOutput'
185191}
186192
187193tasks. register(' cleanCache' , Delete ) {
@@ -190,10 +196,26 @@ tasks.register('cleanCache', Delete) {
190196 delete layout. projectDirectory. dir(' cache' )
191197}
192198
199+ tasks. register(' cleanPubTmpFiles' , Delete ) {
200+ group = ' - Cleanup'
201+ dependsOn ' cleanGeneratePomFileForMavenPublication'
202+
203+ delete layout. buildDirectory. dir(' tmp/publishMavenPublicationToMavenLocal' )
204+ delete layout. buildDirectory. dir(' tmp/generatedChecksums' )
205+
206+ doLast {
207+ [' publications/maven' , ' publications' , ' tmp' ]. each {
208+ if (layout. buildDirectory. dir(it). get(). asFile?. delete()) {
209+ logger. info " Removed empty temporary folder: ${ -> it} "
210+ }
211+ }
212+ }
213+ }
214+
193215tasks. register(' distClean' ) {
194216 group = ' - Cleanup'
195217 description = ' Cleans all build outputs, local caches, and removes all untracked/ignored files via Git.'
196- dependsOn tasks . named( ' clean' ), tasks . named( ' cleanCache' )
218+ dependsOn ' clean' , ' cleanCache' , ' cleanPubTmpFiles '
197219
198220 doLast {
199221 if (layout. projectDirectory. dir(' .git' ). asFile. exists()) {
@@ -268,7 +290,7 @@ tasks.register('buildOtaOSS', Exec) {
268290tasks. named(' assemble' ) {
269291 group = null
270292 description = ' Alias of "buildOtaOSS" task.'
271- dependsOn tasks . named( ' buildOtaOSS' )
293+ dependsOn ' buildOtaOSS'
272294}
273295
274296tasks. named(' build' ) {
@@ -277,20 +299,23 @@ tasks.named('build') {
277299}
278300
279301tasks. register(' installTest' , Exec ) {
280- notCompatibleWithConfigurationCache(' Not yet compatible with CC.' )
281302 group = ' verification'
282303 description = ' Test the flashable zip in a simulated Android recovery environment on your PC.'
283304
284305 doNotTrackState(' Force task execution by disabling up-to-date checks.' )
285306 mustRunAfter buildOta, buildOtaOSS
286307
287- doFirst {
288- environment LIVE_SETUP_ALLOWED : ' false' /* Live setup doesn't work when executed through Gradle */
289- environment NO_PAUSE : ' 1'
290- environment BB_GLOBBING : ' 1'
291- executable " ${ projectDir} /recovery-simulator/recovery" + getScriptExt()
292- args " ${ projectDir} /output/*.zip"
293- }
308+ workingDir = layout. projectDirectory
309+ executable = " ${ -> layout.projectDirectory.dir('recovery-simulator').file("recovery${ getScriptExt().get() }") } "
310+
311+ final Provider<RegularFile > outFilesProv = layout. buildDirectory. file(' *.zip' )
312+ argumentProviders. add({ [outFilesProv. get(). asFile. absolutePath] } as CommandLineArgumentProvider )
313+
314+ environment([
315+ ' LIVE_SETUP_ALLOWED' : ' false' , /* Live setup doesn't work when executed through Gradle */
316+ ' NO_PAUSE' : ' 1' ,
317+ ' BB_GLOBBING' : ' 1'
318+ ])
294319}
295320
296321tasks. register(' test' ) {
@@ -310,8 +335,7 @@ tasks.named('wrapper') {
310335
311336/* === PUBLISHING === */
312337
313- final Closure<String > getMemoizedZipName = { getZipName(). get() }. memoize()
314- final Provider<FileTree > zipFilesTree = layout. buildDirectory. map { dir -> dir. asFileTree. matching { include getMemoizedZipName() } }
338+ final Provider<FileTree > zipFilesTree = getZipName(). map { name -> layout. buildDirectory. asFileTree. matching { include name } }
315339
316340/* abstract class DynamicArtifactSource implements ValueSource<Integer, DynamicArtifactParams> {
317341 private static final List<String> artifactTypes = ['oss', 'full'].asImmutable()
@@ -327,8 +351,8 @@ final Provider<FileTree> zipFilesTree = layout.buildDirectory.map { dir -> dir.a
327351 parameters.zipFiles.files.each { foundFile ->
328352 String type = artifactTypes.find { foundFile.name.contains("-${it}-") } ?: { throw new GradleException("Publishing failed: File ${foundFile.name} is missing a valid build type.") }()
329353 if(!seen.add(type)) throw new GradleException("Publishing failed: The type '${type}' already exists.")
330- String currClsf = (type == 'oss' ? null : type)
331- mavenPub.artifact(foundFile) { extension = 'zip'; classifier = currClsf ; builtBy 'collectArtifacts' }
354+ String clsf = (type == 'oss' ? null : type)
355+ mavenPub.artifact(foundFile) { extension = 'zip'; classifier = clsf ; builtBy 'collectArtifacts' }
332356 }
333357 if(seen.isEmpty()) throw new GradleException("Publishing failed: No artifact found. Check if build tasks were executed.")
334358 seen.size()
@@ -342,33 +366,39 @@ final Provider<Integer> artifactsProcessor = providers.of(DynamicArtifactSource)
342366import java.security.MessageDigest
343367import java.security.DigestInputStream
344368
345- File generateChecksum (targetFile , algorithm ) {
346- final MessageDigest md = MessageDigest . getInstance(algorithm . toUpperCase(). replace(' SHA256' , ' SHA-256' ). replace(' SHA1' , ' SHA-1' ))
369+ File generateChecksum (targetFile , hashExt , checksumsDir ) {
370+ final MessageDigest md = MessageDigest . getInstance(hashExt . toUpperCase(). replace(' SHA256' , ' SHA-256' ). replace(' SHA1' , ' SHA-1' ))
347371 final byte [] buffer = new byte [65536 ]
348372 targetFile. withInputStream {
349373 final DigestInputStream dis = new DigestInputStream (it, md)
350374 while (dis. read(buffer) != -1 ) { }
351375 }
352- final File chksumFile = file( " ${ targetFile.absolutePath } .${ algorithm } " )
376+ final File chksumFile = new File (checksumsDir, " ${ targetFile.name } .${ hashExt } " )
353377 chksumFile. text = md. digest(). encodeHex(). toString()
354378
355379 chksumFile
356380}
357381
358382Integer processArtifacts (parameters , mavenPub ) {
383+ final Directory tmpDir = layout. buildDirectory. dir(' tmp' ). get()
384+ final File checksumsDir = tmpDir. dir(' generatedChecksums' ). asFile
385+ checksumsDir?. deleteDir()
386+ checksumsDir. mkdirs()
387+ tmpDir. asFile?. deleteOnExit()
388+
359389 final List<String > artifactTypes = [' oss' , ' full' ]. asImmutable()
360390 final HashSet<String > seen = []
361391 final boolean isLocal = gradle. startParameter. taskNames. any { it == ' publishToMavenLocal' || it. endsWith(' :publishToMavenLocal' ) }
362392 parameters. zipFiles. files. each { foundFile ->
363393 final String type = artifactTypes. find { foundFile. name. contains(" -${ it} -" ) } ?: { throw new GradleException (" Publishing failed: File ${ foundFile.name} is missing a valid build type." ) }()
364394 if (! seen. add(type)) throw new GradleException (" Publishing failed: The type '${ type} ' already exists." )
365- final String currClsf = (type == ' oss' ? null : type)
366- mavenPub. artifact(foundFile) { extension = ' zip' ; classifier = currClsf ; builtBy ' collectArtifacts' }
395+ final String clsf = (type == ' oss' ? null : type)
396+ mavenPub. artifact(foundFile) { extension = ' zip' ; classifier = clsf ; builtBy ' collectArtifacts' }
367397 if (isLocal) {
368398 [' sha256' , ' sha1' , ' md5' ]. each { hashExt ->
369399 final File existChksumFile = file(" ${ foundFile.absolutePath} .${ hashExt} " )
370- final File chksumFile = existChksumFile. exists() ? existChksumFile : generateChecksum(foundFile, hashExt)
371- mavenPub. artifact(chksumFile) { extension = " zip.${ hashExt} " ; classifier = currClsf ; builtBy ' collectArtifacts' }
400+ final File chksumFile = existChksumFile. exists() ? existChksumFile : generateChecksum(foundFile, hashExt, checksumsDir )
401+ mavenPub. artifact(chksumFile) { extension = " zip.${ hashExt} " ; classifier = clsf ; builtBy ' collectArtifacts' }
372402 }
373403 }
374404 }
@@ -417,6 +447,10 @@ tasks.register('showPublishedArtifacts') {
417447 }
418448}
419449
450+ tasks. named(' publishToMavenLocal' ) {
451+ finalizedBy ' cleanPubTmpFiles'
452+ }
453+
420454tasks. withType(GenerateMavenPom ). configureEach {
421455 dependsOn ' collectArtifacts'
422456}
@@ -431,7 +465,7 @@ tasks.withType(GenerateMavenPom).configureEach {
431465
432466/* ===HEADER=== */
433467
434- abstract class HeaderPrinter implements ValueSource<Boolean , HeaderParams > {
468+ abstract class HeaderPrinter implements ValueSource<String , HeaderParams > {
435469 private static final log = Logging . getLogger(HeaderPrinter )
436470
437471 interface HeaderParams extends ValueSourceParameters {
@@ -441,13 +475,13 @@ abstract class HeaderPrinter implements ValueSource<Boolean, HeaderParams> {
441475 }
442476
443477 @Override
444- Boolean obtain () {
478+ String obtain () {
445479 log. lifecycle ' =' * 36
446480 log. lifecycle " Project: ${ parameters.projectName.get()} "
447481 log. lifecycle " Version: ${ parameters.version.get()} "
448482 log. lifecycle " OS: ${ parameters.osName.get()} "
449483 log. lifecycle ' =' * 36
450- true
484+ ' '
451485 }
452486}
453487
@@ -458,5 +492,5 @@ def headerTrigger = providers.of(HeaderPrinter) {
458492}
459493
460494gradle. taskGraph. whenReady {
461- { headerTrigger. get() }
495+ logger . info " ${ -> headerTrigger.get()} "
462496}
0 commit comments