-
-
Notifications
You must be signed in to change notification settings - Fork 72
feat: Add missing provides mapping to Dependency to comply with CycloneDX 1.6 spec #599
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
Open
vibe13
wants to merge
2
commits into
CycloneDX:master
Choose a base branch
from
vibe13:add_provides_mapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.cyclonedx.CycloneDxSchema; | ||
import org.cyclonedx.model.BomReference; | ||
import org.cyclonedx.model.Dependency; | ||
import org.cyclonedx.model.DependencyList; | ||
|
||
|
@@ -97,6 +98,13 @@ private void writeJSONDependenciesWithGenerator(final JsonGenerator generator, f | |
} | ||
} | ||
generator.writeEndArray(); | ||
if (CollectionUtils.isNotEmpty(dependency.getProvides())) { | ||
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. Not sure if this works, better to check with the generator test to confirm |
||
generator.writeArrayFieldStart("provides"); | ||
for (BomReference subDependency : dependency.getProvides()) { | ||
generator.writeString(subDependency.getRef()); | ||
} | ||
generator.writeEndArray(); | ||
} | ||
generator.writeEndObject(); | ||
} | ||
} | ||
|
@@ -134,6 +142,11 @@ private void writeXMLDependency(final Dependency dependency, final ToXmlGenerato | |
generator.writeString(dependency.getRef()); | ||
generator.setNextIsAttribute(false); | ||
|
||
// Write provides | ||
if (CollectionUtils.isNotEmpty(dependency.getProvides())) { | ||
writeXMLProvides(dependency, generator); | ||
} | ||
|
||
if (CollectionUtils.isNotEmpty(dependency.getDependencies())) { | ||
for (Dependency subDependency : dependency.getDependencies()) { | ||
// You got Shay'd | ||
|
@@ -142,12 +155,31 @@ private void writeXMLDependency(final Dependency dependency, final ToXmlGenerato | |
} | ||
|
||
if (CollectionUtils.isNotEmpty(dependency.getDependencies())) { | ||
generator.writeEndArray(); | ||
} | ||
generator.writeEndArray(); | ||
} | ||
|
||
generator.writeEndObject(); | ||
} | ||
|
||
private void writeXMLProvides(final Dependency dependency, final ToXmlGenerator generator) | ||
throws IOException, XMLStreamException | ||
{ | ||
QName qName = new QName("provides"); | ||
generator.setNextName(qName); | ||
generator.writeFieldName(qName.getLocalPart()); | ||
generator.writeStartArray(); | ||
|
||
for (BomReference ref : dependency.getProvides()) { | ||
generator.writeStartObject(); | ||
generator.setNextIsAttribute(true); | ||
generator.writeFieldName("ref"); | ||
generator.writeString(ref.getRef()); | ||
generator.setNextIsAttribute(false); | ||
generator.writeEndObject(); | ||
} | ||
generator.writeEndArray(); | ||
} | ||
|
||
private void processNamespace(final ToXmlGenerator toXmlGenerator, final String dependencies) | ||
throws XMLStreamException, IOException | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ | |
] | ||
} | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ dependencies { | |
dependencies { | ||
ref: "library-c" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ | |
<dependency ref="library-c"/> | ||
</dependency> | ||
</dependencies> | ||
</bom> | ||
</bom> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json", | ||
"bomFormat": "CycloneDX", | ||
"specVersion": "1.6", | ||
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79", | ||
"version": 1, | ||
"components": [ | ||
{ | ||
"bom-ref": "library-a", | ||
"type": "library", | ||
"name": "library-a", | ||
"version": "1.0.0" | ||
}, | ||
{ | ||
"bom-ref": "library-b", | ||
"type": "library", | ||
"name": "library-b", | ||
"version": "1.0.0" | ||
}, | ||
{ | ||
"bom-ref": "library-c", | ||
"type": "library", | ||
"name": "library-c", | ||
"version": "1.0.0" | ||
}, | ||
{ | ||
"bom-ref": "library-d", | ||
"type": "library", | ||
"name": "library-d", | ||
"version": "1.0.0" | ||
} | ||
], | ||
"dependencies": [ | ||
{ | ||
"ref": "library-a", | ||
"dependsOn": [] | ||
}, | ||
{ | ||
"ref": "library-b", | ||
"dependsOn": [ | ||
"library-c" | ||
] | ||
}, | ||
{ | ||
"ref": "library-c", | ||
"provides": [ | ||
"library-d" | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Tests for both Generators and Parses should be included (for XML and JSON)