Skip to content

Commit d2f3e39

Browse files
authored
chore: use correct method for finding missing versions of java PURLs (#1156)
Signed-off-by: Ben Selwyn-Smith <[email protected]>
1 parent 6785ac4 commit d2f3e39

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/macaron/repo_finder/repo_finder_java.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,17 @@ def find_repo(self, purl: PackageURL) -> tuple[str, RepoFinderInfo]:
5151
artifact = purl.name
5252
version = purl.version or ""
5353

54+
outcome = RepoFinderInfo.FOUND
5455
if not version:
55-
logger.debug("Version missing for maven artifact: %s:%s", group, artifact)
56-
# TODO add support for Java artifacts without a version
57-
return "", RepoFinderInfo.NO_VERSION_PROVIDED
56+
# TODO: consider using a Maven specific method for finding missing versions.
57+
logger.info("Version missing for maven artifact: %s:%s", group, artifact)
58+
latest_purl, outcome = DepsDevRepoFinder().get_latest_version(purl)
59+
if not latest_purl or not latest_purl.version:
60+
logger.debug("Could not find version for artifact: %s:%s", purl.namespace, purl.name)
61+
return "", RepoFinderInfo.NO_VERSION_PROVIDED
62+
group = latest_purl.namespace or ""
63+
artifact = latest_purl.name
64+
version = latest_purl.version
5865

5966
# Perform the following in a loop:
6067
# - Create URLs for the current artifact POM
@@ -64,19 +71,8 @@ def find_repo(self, purl: PackageURL) -> tuple[str, RepoFinderInfo]:
6471
# - Repeat
6572
limit = defaults.getint("repofinder.java", "parent_limit", fallback=10)
6673
initial_limit = limit
67-
last_outcome = RepoFinderInfo.FOUND
74+
last_outcome = outcome
6875
check_parents = defaults.getboolean("repofinder.java", "find_parents")
69-
70-
if not version:
71-
logger.info("Version missing for maven artifact: %s:%s", group, artifact)
72-
latest_purl, outcome = DepsDevRepoFinder().get_latest_version(purl)
73-
if not latest_purl or not latest_purl.version:
74-
logger.debug("Could not find version for artifact: %s:%s", purl.namespace, purl.name)
75-
return "", outcome
76-
group = latest_purl.namespace or ""
77-
artifact = latest_purl.name
78-
version = latest_purl.version
79-
8076
while group and artifact and version and limit > 0:
8177
# Create the URLs for retrieving the artifact's POM.
8278
group = group.replace(".", "/")

tests/integration/cases/repo_finder_remote_calls/repo_finder.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ def test_repo_finder() -> int:
9999
return os.EX_UNAVAILABLE
100100

101101
# Test Java package that has no version.
102-
match, outcome = find_repo(PackageURL.from_string("pkg:maven/io.vertx/vertx-auth-common"))
103-
if not match or outcome != RepoFinderInfo.FOUND:
102+
# Disabling the latest version check ensures that only the missing version is retrieved, preventing the fallback
103+
# functionality of using the non-Java method to find the version and repository.
104+
match, outcome = find_repo(
105+
PackageURL.from_string("pkg:maven/io.vertx/vertx-auth-common"), check_latest_version=False
106+
)
107+
if not match or outcome != RepoFinderInfo.FOUND_FROM_PARENT:
104108
return os.EX_UNAVAILABLE
105109

106110
return os.EX_OK

0 commit comments

Comments
 (0)