Skip to content

Commit a5d32d5

Browse files
include source verification so include packages that are currently missing (#10170)
Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
1 parent 5965063 commit a5d32d5

File tree

2 files changed

+364
-20
lines changed

2 files changed

+364
-20
lines changed

build.gradle

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -475,37 +475,72 @@ configure(allprojects - project(':platform')) {
475475
}
476476

477477
task resolveSourceArtifacts {
478+
group = 'verification'
478479
description = 'Resolves source artifacts for all configurations so they can be included in dependency verification metadata'
479480
doLast {
480-
def componentIds = [] as Set
481-
allprojects { proj ->
482-
proj.configurations.matching { it.canBeResolved }.each { config ->
481+
def componentIds = new HashSet()
482+
def unresolvedConfigs = 0
483+
484+
def collectComponentIds = { configs, String label ->
485+
configs.matching { it.canBeResolved }.each { config ->
483486
try {
484-
config.resolvedConfiguration.resolvedArtifacts.each { artifact ->
485-
componentIds.add(artifact.id.componentIdentifier)
487+
config.incoming.resolutionResult.allComponents.each { component ->
488+
componentIds.add(component.id)
486489
}
487490
} catch (Exception e) {
488-
logger.info("Could not resolve config ${proj.path}:${config.name}: ${e.message}")
491+
unresolvedConfigs++
492+
logger.info("Could not resolve ${label} '${config.name}': ${e.message}")
489493
}
490494
}
491495
}
492-
// Filter to only external module components
496+
497+
allprojects.each { proj ->
498+
collectComponentIds(proj.configurations, "${proj.path} config")
499+
collectComponentIds(proj.buildscript.configurations, "${proj.path} buildscript config")
500+
}
501+
502+
if (unresolvedConfigs > 0) {
503+
logger.warn("${unresolvedConfigs} configurations could not be resolved (run with --info for details)")
504+
}
505+
493506
def externalIds = componentIds.findAll { it instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier }
494507
logger.lifecycle("Resolving sources for ${externalIds.size()} external dependencies...")
495-
def result = dependencies.createArtifactResolutionQuery()
496-
.forComponents(externalIds)
497-
.withArtifacts(JvmLibrary, SourcesArtifact)
498-
.execute()
499-
def resolved = 0
500-
result.resolvedComponents.each { component ->
501-
component.getArtifacts(SourcesArtifact).each { source ->
502-
if (source instanceof ResolvedArtifactResult) {
503-
source.file // trigger download
504-
resolved++
508+
509+
// Populated by resolveSources across both project and buildscript repository calls
510+
def resolvedComponentIds = new HashSet()
511+
def resolveSources = { depHandler, componentIdsToResolve, String label ->
512+
def sizeBefore = resolvedComponentIds.size()
513+
def result = depHandler.createArtifactResolutionQuery()
514+
.forComponents(componentIdsToResolve)
515+
.withArtifacts(JvmLibrary, SourcesArtifact)
516+
.execute()
517+
result.resolvedComponents.each { component ->
518+
component.getArtifacts(SourcesArtifact).each { source ->
519+
if (source instanceof ResolvedArtifactResult) {
520+
source.file // access .file to trigger download and register with verification metadata
521+
resolvedComponentIds.add(component.id)
522+
} else {
523+
logger.warn("Could not download sources for ${component.id}: ${source}")
524+
}
505525
}
506526
}
527+
def count = resolvedComponentIds.size() - sizeBefore
528+
logger.lifecycle("Resolved sources for ${count} components from ${label}")
529+
}
530+
531+
resolveSources(dependencies, externalIds, "project repositories")
532+
533+
// Retry unresolved sources using buildscript repositories (includes Gradle Plugin Portal)
534+
def unresolvedIds = externalIds.findAll { !resolvedComponentIds.contains(it) }
535+
if (!unresolvedIds.isEmpty()) {
536+
resolveSources(buildscript.dependencies, unresolvedIds, "buildscript repositories")
537+
}
538+
539+
def finalUnresolved = externalIds.size() - resolvedComponentIds.size()
540+
if (finalUnresolved > 0) {
541+
logger.warn("${finalUnresolved} dependencies have no published source artifacts")
507542
}
508-
logger.lifecycle("Resolved ${resolved} source artifacts")
543+
logger.lifecycle("Total: sources resolved for ${resolvedComponentIds.size()}/${externalIds.size()} components")
509544
}
510545
}
511546

0 commit comments

Comments
 (0)