@@ -416,23 +416,32 @@ static String getShortenedAssetPath(File file) {
416
416
return file. getPath()
417
417
.replaceFirst(' ^.*?resources.(assets.immersiveengineering.)?' , ' ' ) // remove start
418
418
.replaceAll(' [/\\\\ ]+' , ' _' ) // replace slashes with underscores
419
+ .replaceAll(' .png+' , ' ' ) // trim the ending
419
420
}
420
421
421
422
for (dir in project. sourceSets. main. resources. srcDirs) {
422
423
fileTree(dir : dir, includes : pngPatterns). each { file ->
423
- tasks. register(" optimizePng_" + getShortenedAssetPath(file), Exec ) {
424
+ def path = getShortenedAssetPath(file);
425
+ tasks. register(" optimizePng_" + path, Exec ) {
424
426
executable " optipng"
425
- args " -q" , " -o7" , " -zm1-9" , " -strip" , " all" , file
426
- // It'd be awesome if we could do logging here, but routing standardOutput to a ByteArrayOutputStream
427
- // doesn't work...
428
- // Todo: try with file output!
427
+ args " -q" , " -log" , " optipng_${ path} .log" , " -o7" , " -zm1-9" , " -strip" , " all" , file
429
428
}
430
429
}
431
430
}
432
431
task optimizePng {
433
432
for (dir in project. sourceSets. main. resources. srcDirs) {
434
433
fileTree(dir : dir, includes : pngPatterns). each { file ->
435
- dependsOn " optimizePng_" + getShortenedAssetPath(file)
434
+ def path = getShortenedAssetPath(file);
435
+ dependsOn " optimizePng_${ path} "
436
+ doLast {
437
+ def logfile = new File (" optipng_${ path} .log" )
438
+ if (logfile. exists()) {
439
+ def decrease = logfile. text. trim(). find(' [\\ d\\ .]+% decrease' )
440
+ if (decrease)
441
+ println " ${ file.name} optimized:\n\t ${ decrease} in size"
442
+ logfile. delete()
443
+ }
444
+ }
436
445
}
437
446
}
438
447
}
0 commit comments