Skip to content

Commit 407ff3d

Browse files
committed
feat: add fallback for google maven
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 867c8ac commit 407ff3d

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

services/apps/packages_worker/src/maven/__tests__/registry.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ describe('resolveRegistryBaseUrl', () => {
1515
)
1616
})
1717

18-
it('returns Maven Central for bare com.google.android (legacy SDK stubs on Central)', () => {
19-
expect(resolveRegistryBaseUrl('com.google.android')).toBe('https://repo1.maven.org/maven2')
18+
it('returns Google Maven for bare com.google.android (legacy Android SDK stubs)', () => {
19+
expect(resolveRegistryBaseUrl('com.google.android')).toBe(
20+
'https://dl.google.com/dl/android/maven2',
21+
)
2022
})
2123

2224
it('returns Google Maven for android.arch (pre-AndroidX Architecture Components)', () => {

services/apps/packages_worker/src/maven/registry.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* metadata.xml / POM fetch logic works — only the base URL changes.
1212
*/
1313

14-
const MAVEN_CENTRAL_BASE_URL = 'https://repo1.maven.org/maven2'
14+
export const MAVEN_CENTRAL_BASE_URL = 'https://repo1.maven.org/maven2'
1515

1616
interface RegistryEntry {
1717
prefix: string
@@ -25,10 +25,10 @@ const ALTERNATIVE_REGISTRIES: RegistryEntry[] = [
2525
baseUrl: 'https://dl.google.com/dl/android/maven2',
2626
pageUrl: (g, a) => `https://maven.google.com/web/index.html#${g}:${a}`,
2727
},
28-
// com.google.android (bare, no sub-namespace) are legacy SDK stubs on Maven Central —
29-
// only sub-namespaces like com.google.android.gms.* live on Google Maven.
28+
// com.google.android — all artifacts (bare namespace and sub-namespaces like
29+
// com.google.android.gms.*) are on Google Maven, not Maven Central.
3030
{
31-
prefix: 'com.google.android.',
31+
prefix: 'com.google.android',
3232
baseUrl: 'https://dl.google.com/dl/android/maven2',
3333
pageUrl: (g, a) => `https://maven.google.com/web/index.html#${g}:${a}`,
3434
},
@@ -154,6 +154,16 @@ export function resolveRegistryBaseUrl(groupId: string): string {
154154
return process.env.MAVEN_FETCHER_BASE_URL ?? MAVEN_CENTRAL_BASE_URL
155155
}
156156

157+
/**
158+
* Returns true when the given groupId maps to a non-Central registry.
159+
* Used in the enrichment loop to decide whether a Central fallback lookup is worth trying
160+
* (e.g. com.google.firebase:firebase-admin is a server-side Java SDK on Central, while
161+
* most com.google.firebase artifacts are Android SDKs on Google Maven).
162+
*/
163+
export function isAlternativeRegistry(groupId: string): boolean {
164+
return findEntry(groupId) !== undefined
165+
}
166+
157167
/**
158168
* Returns a human-browsable URL for the given artifact in its authoritative registry.
159169
*/

services/apps/packages_worker/src/maven/runMavenEnrichmentLoop.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import { getMavenConfig } from '../config'
1818
import { extractArtifact, getPomCacheStats, normalizeScmUrl } from './extract'
1919
import { isMavenFetchError, resolveVersionsList } from './metadata'
2020
import { isPrerelease, parseRepoUrl } from './normalize'
21-
import { resolveRegistryBaseUrl, resolveRegistryPageUrl } from './registry'
21+
import {
22+
MAVEN_CENTRAL_BASE_URL,
23+
isAlternativeRegistry,
24+
resolveRegistryBaseUrl,
25+
resolveRegistryPageUrl,
26+
} from './registry'
2227

2328
const log = getServiceChildLogger('maven')
2429

@@ -115,10 +120,25 @@ async function processCriticalPackage(qx: QueryExecutor, pkg: PackageRow, forceF
115120
return { status: 'skipped' }
116121
}
117122

118-
const baseUrl = resolveRegistryBaseUrl(groupId)
123+
let baseUrl = resolveRegistryBaseUrl(groupId)
119124

120125
// Phase 1: lightweight metadata fetch to get the current upstream version.
121-
const metadata = await resolveVersionsList(groupId, artifactId, baseUrl)
126+
let metadata = await resolveVersionsList(groupId, artifactId, baseUrl)
127+
128+
// If the primary (non-Central) registry returned NOT_FOUND, try Maven Central as a
129+
// fallback. This handles artifacts that share a namespace with non-Central packages but
130+
// are themselves published on Central — e.g. com.google.firebase:firebase-admin is the
131+
// server-side Java SDK on Central, while most com.google.firebase artifacts are Android
132+
// SDKs on Google Maven.
133+
if (isMavenFetchError(metadata) && metadata.kind === 'NOT_FOUND' && isAlternativeRegistry(groupId)) {
134+
const centralUrl = process.env.MAVEN_FETCHER_BASE_URL ?? MAVEN_CENTRAL_BASE_URL
135+
const centralMetadata = await resolveVersionsList(groupId, artifactId, centralUrl)
136+
if (!isMavenFetchError(centralMetadata)) {
137+
log.info({ groupId, artifactId }, 'Not found in primary registry — resolved via Maven Central fallback')
138+
baseUrl = centralUrl
139+
metadata = centralMetadata
140+
}
141+
}
122142

123143
if (isMavenFetchError(metadata)) {
124144
if (metadata.kind === 'NOT_FOUND') {

0 commit comments

Comments
 (0)