-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(maven): return coordinates-only Package
on parsePackage
exception
#8471
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import io.kotest.matchers.collections.beEmpty | |
import io.kotest.matchers.collections.containExactly | ||
import io.kotest.matchers.collections.haveSize | ||
import io.kotest.matchers.nulls.beNull | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.kotest.matchers.should | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.contain | ||
|
@@ -46,7 +47,9 @@ import org.ossreviewtoolkit.model.Identifier | |
import org.ossreviewtoolkit.model.Issue | ||
import org.ossreviewtoolkit.model.Package | ||
import org.ossreviewtoolkit.model.PackageLinkage | ||
import org.ossreviewtoolkit.model.RemoteArtifact | ||
import org.ossreviewtoolkit.model.Severity | ||
import org.ossreviewtoolkit.model.VcsInfo | ||
|
||
class MavenDependencyHandlerTest : WordSpec({ | ||
beforeSpec { | ||
|
@@ -204,7 +207,7 @@ class MavenDependencyHandlerTest : WordSpec({ | |
handler.linkageFor(dependency) shouldBe PackageLinkage.PROJECT_DYNAMIC | ||
} | ||
|
||
"handle an exception from MavenSupport" { | ||
"return coordinates-only Package when an exception is raised from MavenSupport" { | ||
val exception = ProjectBuildingException( | ||
"BrokenProject", "Cannot parse pom.", | ||
IOException("General failure when reading hard disk.") | ||
|
@@ -219,7 +222,24 @@ class MavenDependencyHandlerTest : WordSpec({ | |
every { dependency.repositories } returns repos | ||
every { handler.support.parsePackage(artifact, repos) } throws exception | ||
|
||
handler.createPackage(dependency, issues) should beNull() | ||
val pkg = handler.createPackage(dependency, issues) | ||
pkg.shouldNotBeNull() | ||
|
||
with(pkg.id) { | ||
type shouldBe "Maven" | ||
namespace shouldBe artifact.groupId | ||
name shouldBe artifact.artifactId | ||
version shouldBe artifact.version | ||
} | ||
Comment on lines
+228
to
+233
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe nest this in the below? |
||
|
||
with(pkg) { | ||
binaryArtifact shouldBe RemoteArtifact.EMPTY | ||
declaredLicenses should beEmpty() | ||
description shouldBe "" | ||
homepageUrl shouldBe "" | ||
Comment on lines
+238
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
sourceArtifact shouldBe RemoteArtifact.EMPTY | ||
vcs shouldBe VcsInfo.EMPTY | ||
} | ||
|
||
issues should haveSize(1) | ||
with(issues[0]) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we shouldn't be able to at least get the binary artifact here... I mean, apparently software with a dependency on
opensymphony:quartz:1.6.0
does build, so the binary can be retrieved, and we should be able to get its coordinates here.Maybe instead of this fallback here, can we narrow down which part of
parsePackage()
fails, and try to get other data from it on a more fine-granular basis?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Maven call (MavenSupport.kt#698 => MavenSupport.kt#715) raises
ProjectBuildingException
. Not sure if it's reasonable to break the contract ofparsePackage
rethrowing these. Same goes forrequestRemoteArtifact
inMavenDependencyHandler
(given that it is a private method).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked the exception and it doesn't seem like there's much to extract from it, except for the fact that the cause is
ArtifactResolutionException
. This could be used to make a conditional that tries to fetch the binary, I guess?Another way would be to try and fetch the remote artifact before the POM, but it's probably a bad idea given how rare the case of POMless dependency is.