@@ -637,91 +637,33 @@ task refreshModuleSizes {
637637
638638preBuild. dependsOn refreshModuleSizes
639639
640- // ---- maps layer size auto-capture (offline fallback) --------------------------
641- // Fetches the <size> from each map layer's .meta4 on the maps mirror and writes
642- // src/main/assets/maps_sizes.csv, so the Choose screen's OFFLINE fallback (MapsCatalog)
643- // is captured at package time instead of hand-maintained — same pattern as rootfs above.
644- // The file names follow roles/maps/defaults/main.yml; update the three data dates below
645- // when the role bumps them. Non-fatal: an incomplete fetch keeps the committed CSV.
646- task refreshMapsSizes {
640+ // ---- maps catalog refresh (release / manual) ----------------------------------
641+ // Regenerates src/main/assets/maps_catalog.csv (group,level,file,bytes,date) from the
642+ // maps mirror's .meta4 pointers via tools/build_maps_catalog.py -- the ONE builder for
643+ // this catalog (it replaced the old inline refreshMapsSizes fetch; no double build path).
644+ // Like the Kiwix catalog it does NOT run on every build: it runs on a RELEASE and on
645+ // demand (./gradlew refreshMapsCatalog), and the weekly publish-catalogs workflow runs
646+ // the same script to publish the CSV + manifest to Cloudflare. The committed CSV is the
647+ // offline floor -- MapsCatalog reads it for the Choose size AND the download file id.
648+ // Never fails the build: if python3 is missing or the fetch is blocked, the committed
649+ // CSV (last known) is kept.
650+ task refreshMapsCatalog {
647651 group = ' build setup'
648- description = ' Capture map layer sizes (.meta4) into assets/maps_sizes.csv for the offline fallback'
649- def csv = file(' src/main/assets/maps_sizes.csv' )
652+ description = ' Regenerate assets/maps_catalog.csv from the maps mirror .meta4 (release / manual)'
650653 doLast {
651- def base = ' https://iiab.switnet.org/maps/2/'
652- // Data dates from roles/maps/defaults/main.yml (maps_vector_data_date / maps_slow_data_date
653- // / maps_search_data_date). Keep in sync with the role.
654- def vectorDate = ' 2026-07-01'
655- def slowDate = ' 2025-12-10'
656- def searchDate = ' 2026-04-22'
657- // "group|level" -> mirror file name (whole-world pmtiles; search is a tarball).
658- def files = [
659- ' base|nat-z8' : " naturalearth-openmaptiles.${ slowDate} .z00-z08.pmtiles" ,
660- ' base|11' : " openstreetmap-openmaptiles.${ vectorDate} .z00-z11.pmtiles" ,
661- ' base|14' : " openstreetmap-openmaptiles.${ vectorDate} .z00-z14.pmtiles" ,
662- ' satellite|7' : " s2maps-sentinel2-2023.${ slowDate} .z00-z07.pmtiles" ,
663- ' satellite|9' : " s2maps-sentinel2-2023.${ slowDate} .z00-z09.pmtiles" ,
664- ' satellite|11' : " s2maps-sentinel2-2023.${ slowDate} .z00-z11.pmtiles" ,
665- ' satellite|13' : " s2maps-sentinel2-2023.${ slowDate} .z00-z13.pmtiles" ,
666- ' terrain|7' : " terrarium.${ slowDate} .z00-z07.pmtiles" ,
667- ' terrain|8' : " terrarium.${ slowDate} .z00-z08.pmtiles" ,
668- ' terrain|9' : " terrarium.${ slowDate} .z00-z09.pmtiles" ,
669- ' terrain|10' : " terrarium.${ slowDate} .z00-z10.pmtiles" ,
670- ' search|pop-1k-cities' : " static-search.${ searchDate} .pop-1k-cities.tar.gz" ,
671- ]
672- def sizePat = ~/ <size>(\d +)<\/ size>/
673- def fetched = [:]
674- files. each { k , fname ->
675- def url = " ${ base}${ fname} .meta4"
676- try {
677- def conn = (HttpURLConnection ) new URL (url). openConnection()
678- conn. setRequestProperty(' User-Agent' , ' iiab-android-build' )
679- conn. connectTimeout = 6000
680- conn. readTimeout = 6000
681- if (conn. responseCode != 200 ) {
682- logger. warn(" >> [maps sizes] HTTP ${ conn.responseCode} for ${ url} " )
683- conn. disconnect(); return
684- }
685- def body = conn. inputStream. getText(' UTF-8' )
686- conn. disconnect()
687- def m = sizePat. matcher(body)
688- if (m. find()) { fetched[k] = m. group(1 ) }
689- else { logger. warn(" >> [maps sizes] no <size> element in ${ url} " ) }
690- } catch (Exception e) {
691- logger. warn(" >> [maps sizes] fetch failed for ${ url} : ${ e.message} " )
692- }
693- }
694- if (fetched. size() != files. size()) {
695- logger. warn(" >> [maps sizes] incomplete fetch (${ fetched.size()} /${ files.size()} ); keeping existing ${ csv.name} (last known)." )
696- return
697- }
698- def existing = [:]
699- if (csv. exists()) {
700- csv. eachLine { line ->
701- line = line. trim()
702- if (line. isEmpty() || line. startsWith(' #' )) return
703- def p = line. split(' ,' )
704- if (p. length >= 3 ) existing[" ${ p[0].trim()} |${ p[1].trim()} " . toString()] = p[2 ]. trim()
705- }
706- }
707- if (existing == fetched) {
708- println " >> [maps sizes] up to date (${ fetched.size()} entries unchanged)."
709- return
710- }
711- def today = new Date (). format(' yyyy-MM-dd' )
712- def rows = files. keySet(). collect { k ->
713- def gl = k. split(' \\ |' , 2 )
714- " ${ gl[0]} ,${ gl[1]} ,${ fetched[k]} ,${ today} " . toString()
654+ try {
655+ def proc = [' python3' , ' tools/build_maps_catalog.py' ]. execute(null , projectDir)
656+ proc. consumeProcessOutput(System . out, System . err)
657+ proc. waitFor()
658+ if (proc. exitValue() != 0 ) logger. warn(" >> [maps catalog] generator exit ${ proc.exitValue()} ; kept existing CSV." )
659+ } catch (Exception e) {
660+ logger. warn(" >> [maps catalog] skipped (${ e.message} ); kept existing CSV." )
715661 }
716- if (! csv. parentFile. exists()) csv. parentFile. mkdirs()
717- csv. text = ' # group,level,bytes,fetched_date -- AUTO-GENERATED by the refreshMapsSizes Gradle task; do not edit by hand\n ' +
718- ' # Whole-world pmtiles from https://iiab.switnet.org/maps/2 (roles/maps/defaults dates).\n ' +
719- rows. join(' \n ' ) + ' \n '
720- println " >> [maps sizes] updated ${ rows.size()} entries in ${ csv.name} (${ today} )."
721662 }
722663}
723-
724- preBuild. dependsOn refreshMapsSizes
664+ tasks. matching { it. name == ' assembleRelease' || it. name == ' bundleRelease' }. configureEach {
665+ dependsOn refreshMapsCatalog
666+ }
725667
726668// ---- Kiwix ZIM catalog refresh (release-only) ---------------------------------
727669// Regenerates src/main/assets/kiwix_catalog.csv from the Kiwix directory listings via
0 commit comments