Skip to content

Commit f4fae4b

Browse files
committed
cleanup, make purl sonatype expects
Signed-off-by: djcrabhat <djcrabhat@sosimplerecords.com>
1 parent c62b87d commit f4fae4b

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/RedHatSBomGenerator.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.github.packageurl.MalformedPackageURLException;
2424
import com.github.packageurl.PackageURL;
25+
import com.google.common.base.Splitter;
2526
import org.cyclonedx.model.Bom;
2627
import org.cyclonedx.model.Component;
2728
import org.cyclonedx.model.LicenseChoice;
@@ -48,7 +49,7 @@ public class RedHatSBomGenerator extends UnixSBomGenerator
4849
private static final String SOFTWARE_DETAIL_CMD = "yum info";
4950
private static final String SOFTWARE_LIST_CMD = "yum list installed";
5051

51-
private String purlNamespace = "rhel";
52+
private String purlNamespace = null;
5253

5354
private ProcessBuilder processBuilder = new ProcessBuilder();
5455

@@ -97,10 +98,10 @@ public Bom generateSBom() {
9798
try {
9899
String downloadUrl = getPackageDownloadUrl(software);
99100
if (downloadUrl != null) {
100-
detailMap.put("download_url", downloadUrl);
101+
detailMap.put("Download-Url", downloadUrl);
101102
}
102103
} catch(SBomException e){
103-
logger.debug("Error getting download_url", e);
104+
logger.debug("Error getting Download-Url", e);
104105
}
105106
component = createComponents(software, detailMap, license, group,
106107
version, purl, detailMap.get("Priority"));
@@ -144,15 +145,15 @@ public String getLicenseFileName(String software, String version)
144145

145146

146147
public PackageURL getPurl(String software, String version) throws MalformedPackageURLException {
147-
List<String> parts = Splitter.on('.').splitToList(software);
148+
List<String> parts = Splitter.on('.').splitToList(software);
148149

149-
if (parts.length == 0) {
150+
if (parts.size() == 0) {
150151
return this.getPurl(software, version, null, null);
151152
}
152-
if (parts.length == 1) {
153-
return this.getPurl(parts[0], version, null, null);
153+
if (parts.size() == 1) {
154+
return this.getPurl(parts.get(0), version, null, null);
154155
} else {
155-
return this.getPurl(parts[0], version, parts[1], null);
156+
return this.getPurl(parts.get(0), version, parts.get(1), null);
156157
}
157158
}
158159

@@ -166,7 +167,7 @@ public PackageURL getPurl(String software, String version, String arch, String d
166167
qualifiers.put("distro", distro);
167168
}
168169
return new PackageURL(
169-
PackageURL.StandardTypes.RPM, purlNamespace.toLowerCase(), software, version, qualifiers, null);
170+
PackageURL.StandardTypes.RPM, purlNamespace, software, version, qualifiers, null);
170171
}
171172

172173

src/main/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/UnixSBomGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public List<ExternalReference> buildExternalReferences(Map<String, String> detai
9191
bugs.setType(ExternalReference.Type.ISSUE_TRACKER);
9292
refs.add(bugs);
9393
}
94+
if (detailMap.containsKey("Download-Url")){
95+
ExternalReference docs = new ExternalReference();
96+
docs.setUrl(detailMap.get("Download-Url"));
97+
docs.setType(ExternalReference.Type.DISTRIBUTION);
98+
refs.add(docs);
99+
}
94100

95101
return refs;
96102
}

src/test/java/org/cyclonedx/contrib/com/lmco/efoss/unix/sbom/generator/RedHatSBomGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void getPurlTest()
119119
TestUtils.logTestStart(methodName, watcher.getLogger());
120120

121121
String expectedUrl = "https://rhui3.us-west-2.aws.ce.redhat.com/pulp/repos/content/dist/rhel/rhui/server/7/7Server/x86_64/os/Packages/z/zip-3.0-11.el7.x86_64.rpm";
122-
String expected = "pkg:rpm/rhel/zip@3.0-11.el7?arch=x64_86";
122+
String expected = "pkg:rpm/zip@3.0-11.el7?arch=x64_86";
123123

124124
AutoCloseable openMocks = null;
125125

0 commit comments

Comments
 (0)