Skip to content

Commit

Permalink
print package name if a license is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneemann committed May 14, 2024
1 parent 9555157 commit 2c2ffed
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions generate_sbom
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,29 @@ sub spdx_license_mapping {
}

sub map_license {
my ($license, $license_mapping) = @_;
my ($license, $license_mapping, $pkg) = @_;
if ( $license =~ /\sor\s/i ) {
my @licenses_or;
foreach my $l (split(/\sor\s/i, $license)) {
push(@licenses_or, map_license($l, $license_mapping));
push(@licenses_or, map_license($l, $license_mapping, $pkg));
}
$license = join(' OR ', @licenses_or);
} elsif ( $license =~ /\swith\s/i ) {
my @licenses_with;
foreach my $l (split(/\swith\s/i, $license)) {
push(@licenses_with, map_license($l, $license_mapping));
push(@licenses_with, map_license($l, $license_mapping, $pkg));
}
$license = join(' WITH ', @licenses_with);
} elsif ( $license =~ /\sand\s/i ) {
my @licenses_and;
foreach my $l (split(/\sand\s/i, $license)) {
push(@licenses_and, map_license($l, $license_mapping));
push(@licenses_and, map_license($l, $license_mapping, $pkg));
}
$license = join(' AND ', @licenses_and);
} elsif (defined $license_mapping->{$license}) {
$license = $license_mapping->{$license};
} else {
warn("SPDX-License-Mapping: License not found in mapping: $license\n");
warn("SPDX-License-Mapping: License for $pkg not found in mapping: $license\n");
$license = "NOASSERTION";
}
if ( $license =~ /NOASSERTION/) {
Expand Down Expand Up @@ -684,8 +684,8 @@ sub spdx_encode_pkg {
my $license = $p->{'LICENSE'};
if ($license) {
$license =~ s/ and / AND /g;
if (keys %$license_mapping) {
$spdx->{'licenseConcluded'} = map_license($license, $license_mapping);
if (%$license_mapping) {
$spdx->{'licenseConcluded'} = map_license($license, $license_mapping, $p->{'NAME'});
} else {
$spdx->{'licenseConcluded'} = $license;
}
Expand Down

0 comments on commit 2c2ffed

Please sign in to comment.