Skip to content
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 the view of package curations #369

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/kotlin/model/OrtApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Issue
import org.ossreviewtoolkit.model.LicenseSource
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.RepositoryProvenance
Expand Down Expand Up @@ -109,6 +110,8 @@ class OrtApi(

fun getCuratedPackageOrProject(id: Identifier): CuratedPackage? = result.getPackageOrProject(id)

fun getUncuratedPackageOrProject(id: Identifier): Package? = result.getUncuratedPackageOrProject(id)

fun getEvaluatorRun(): EvaluatorRun? = result.evaluator

fun getEvaluatorStats(): EvaluatorStats =
Expand Down
65 changes: 32 additions & 33 deletions src/main/kotlin/ui/dependencies/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.ossreviewtoolkit.model.Hash
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Issue
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageCurationData
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.RemoteArtifact
Expand Down Expand Up @@ -359,35 +360,29 @@ fun PackageDetails(item: DependencyTreePackage) {
Text(text = "${item.id.name} ${item.id.version}", style = MaterialTheme.typography.h4)

Column(modifier = Modifier.verticalScroll(scrollState).padding(top = 15.dp)) {
if (item.pkg == null) {
Text("No package information found.")
IdentifierSection(item.curatedPackage.metadata)

Divider(modifier = Modifier.padding(vertical = 10.dp))
} else {
IdentifierSection(item.pkg.metadata)

Divider(modifier = Modifier.padding(vertical = 10.dp))
Divider(modifier = Modifier.padding(vertical = 10.dp))

CopyrightSection(item.pkg.metadata, item.resolvedLicense)
CopyrightSection(item.curatedPackage.metadata, item.resolvedLicense)

Divider(modifier = Modifier.padding(vertical = 10.dp))
Divider(modifier = Modifier.padding(vertical = 10.dp))

LicenseSection(item.pkg.metadata, item.resolvedLicense)
LicenseSection(item.curatedPackage.metadata, item.resolvedLicense)

Divider(modifier = Modifier.padding(vertical = 10.dp))
Divider(modifier = Modifier.padding(vertical = 10.dp))

DescriptionSection(item.pkg.metadata.description)
DescriptionSection(item.curatedPackage.metadata.description)

Divider(modifier = Modifier.padding(vertical = 10.dp))
Divider(modifier = Modifier.padding(vertical = 10.dp))

PackageProvenanceSection(item.pkg.metadata)
PackageProvenanceSection(item.curatedPackage.metadata)

Divider(modifier = Modifier.padding(vertical = 10.dp))
Divider(modifier = Modifier.padding(vertical = 10.dp))

CurationSection(item.pkg)
CurationSection(item.uncuratedPackage, item.curatedPackage.curations)

Divider(modifier = Modifier.padding(vertical = 10.dp))
}
Divider(modifier = Modifier.padding(vertical = 10.dp))

IssuesSection(item.issues)

Expand All @@ -396,7 +391,7 @@ fun PackageDetails(item: DependencyTreePackage) {
// TODO: Add vulnerability section.

Row(verticalAlignment = Alignment.CenterVertically) {
val homepageUrl = item.pkg?.metadata?.homepageUrl.orEmpty()
val homepageUrl = item.curatedPackage?.metadata?.homepageUrl.orEmpty()
if (homepageUrl.isNotBlank()) {
WebLink("Homepage", homepageUrl)
}
Expand Down Expand Up @@ -461,7 +456,8 @@ private fun PackageDetailsPreview() {
PackageDetails(
DependencyTreePackage(
id = pkg.metadata.id,
pkg = pkg,
uncuratedPackage = pkg.metadata,
curatedPackage = pkg,
linkage = PackageLinkage.STATIC,
issues = listOf(issue),
resolvedLicense = resolvedLicense
Expand Down Expand Up @@ -619,9 +615,10 @@ fun RepositoryColumn(vcs: VcsInfo, expanded: Boolean) {
}

@Composable
fun CurationSection(curatedPackage: CuratedPackage) {
fun CurationSection(uncuratedPackage: Package, curations: List<PackageCurationData>) {
Expandable(header = {
val noOrSize = if (curatedPackage.curations.isEmpty()) "No" else curatedPackage.curations.size
val noOrSize = if (curations.isEmpty()) "No" else curations.size

CaptionedText(
caption = "CURATIONS",
text = "$noOrSize curation(s) were applied to this package."
Expand All @@ -631,56 +628,58 @@ fun CurationSection(curatedPackage: CuratedPackage) {
modifier = Modifier.padding(top = 5.dp),
verticalArrangement = Arrangement.spacedBy(2.dp)
) {
curatedPackage.curations.forEach { curation ->
curations.fold(uncuratedPackage.toCuratedPackage()) { base, curation ->
Divider(thickness = 0.5.dp)

ProvideTextStyle(MaterialTheme.typography.overline) {
Text("Comment: ${curation.comment.toStringOrDash()}")

curation.purl?.let { purl ->
Text("PURL: ${curatedPackage.metadata.purl} -> $purl")
Text("PURL: ${base.metadata.purl} -> $purl")
}

curation.cpe?.let { cpe ->
Text("CPE: ${curatedPackage.metadata.cpe} -> $cpe")
Text("CPE: ${base.metadata.cpe} -> $cpe")
}

curation.authors?.let { authors ->
Text("Authors: ${curatedPackage.metadata.authors} -> $authors")
Text("Authors: ${base.metadata.authors} -> $authors")
}

curation.concludedLicense?.let { concludedLicense ->
Text("Concluded license: ${curatedPackage.metadata.concludedLicense} -> $concludedLicense")
Text("Concluded license: ${base.metadata.concludedLicense} -> $concludedLicense")
}

curation.description?.let { description ->
Text("Description: ${curatedPackage.metadata.description} -> $description")
Text("Description: ${base.metadata.description} -> $description")
}

curation.homepageUrl?.let { homepageUrl ->
Text("Homepage: ${curatedPackage.metadata.homepageUrl} -> $homepageUrl")
Text("Homepage: ${base.metadata.homepageUrl} -> $homepageUrl")
}

curation.binaryArtifact?.let { binaryArtifact ->
Text("Binary artifact: ${curatedPackage.metadata.binaryArtifact} -> $binaryArtifact")
Text("Binary artifact: ${base.metadata.binaryArtifact} -> $binaryArtifact")
}

curation.vcs?.let { vcs ->
Text("VCS: ${curatedPackage.metadata.vcs} -> $vcs")
Text("VCS: ${base.metadata.vcs} -> $vcs")
}

curation.isMetadataOnly?.let { isMetadataOnly ->
Text("Is metadata only: ${curatedPackage.metadata.isMetadataOnly} -> $isMetadataOnly")
Text("Is metadata only: ${base.metadata.isMetadataOnly} -> $isMetadataOnly")
}

curation.isModified?.let { isModified ->
Text("Is modified: ${curatedPackage.metadata.isModified} -> $isModified")
Text("Is modified: ${base.metadata.isModified} -> $isModified")
}

if (curation.declaredLicenseMapping.isNotEmpty()) {
Text("Declared license mapping: ${curation.declaredLicenseMapping}")
}
}

curation.apply(base)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/ui/dependencies/DependenciesState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue
import org.ossreviewtoolkit.model.CuratedPackage
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Issue
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.Scope
Expand Down Expand Up @@ -97,7 +98,8 @@ class DependencyTreeScope(val project: Project, val scope: Scope) : DependencyTr

class DependencyTreePackage(
val id: Identifier,
val pkg: CuratedPackage?,
val uncuratedPackage: Package,
val curatedPackage: CuratedPackage,
val linkage: PackageLinkage,
val issues: List<Issue>,
val resolvedLicense: ResolvedLicenseInfo?
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/ui/dependencies/DependenciesViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ class DependenciesViewModel(private val ortModel: OrtModel) : ViewModel() {
key = project.id.toCoordinates(),
children = children
)
} ?: api.getCuratedPackage(id)?.let { pkg ->
} ?: api.getCuratedPackage(id)?.let { curatedPackage ->
val uncuratedPackage = checkNotNull(api.getUncuratedPackageOrProject(id)) {
"There must be an uncurated package if there is a curated one."
}

TreeNode(
value = DependencyTreePackage(
id = id,
pkg = pkg,
uncuratedPackage = uncuratedPackage,
curatedPackage = curatedPackage,
linkage = linkage,
issues = issues,
resolvedLicense = resolvedLicenses.getValue(id)
Expand Down