Skip to content

Commit

Permalink
fix(MavenSupport): Also use the list of repos for the artifact cache key
Browse files Browse the repository at this point in the history
Previously, the cache for the remote artifacts only used the artifact
coordinates as the cache key. But if the list of repos to query changes,
there may be another match for the same artifact in another repo. Thus,
also take the list of repos into account for the cache key.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Feb 21, 2023
1 parent ae43b4a commit 65be79a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions analyzer/src/main/kotlin/managers/utils/MavenSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,6 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
repositories: List<RemoteRepository>,
useReposFromDependencies: Boolean
): RemoteArtifact {
remoteArtifactCache.read(artifact.toString())?.let {
logger.debug { "Reading remote artifact for '$artifact' from disk cache." }
return yamlMapper.readValue(it)
}

val allRepositories = if (useReposFromDependencies) {
val repoSystem = containerLookup<RepositorySystem>()

Expand All @@ -513,6 +508,13 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
repositories
}

val cacheKey = "$artifact@$allRepositories"

remoteArtifactCache.read(cacheKey)?.let {
logger.debug { "Reading remote artifact for '$artifact' from disk cache." }
return yamlMapper.readValue(it)
}

// Filter out local repositories, as remote artifacts should never point to files on the local disk.
val remoteRepositories = allRepositories.filterNot {
// Some (Linux) file URIs do not start with "file://" but look like "file:/opt/android-sdk-linux".
Expand Down Expand Up @@ -630,7 +632,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {

return RemoteArtifact(info.downloadUrl, hash).also {
logger.debug { "Writing remote artifact for '$artifact' to disk cache." }
remoteArtifactCache.write(artifact.toString(), yamlMapper.writeValueAsString(it))
remoteArtifactCache.write(cacheKey, yamlMapper.writeValueAsString(it))
}
} else {
logger.debug {
Expand All @@ -647,7 +649,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {

return RemoteArtifact.EMPTY.also {
logger.debug { "Writing empty remote artifact for '$artifact' to disk cache." }
remoteArtifactCache.write(artifact.toString(), yamlMapper.writeValueAsString(it))
remoteArtifactCache.write(cacheKey, yamlMapper.writeValueAsString(it))
}
}

Expand Down

0 comments on commit 65be79a

Please sign in to comment.