Skip to content

Commit

Permalink
Merge pull request #459 from sschuberth/bom-str-fixes
Browse files Browse the repository at this point in the history
BOM string creation improvements
  • Loading branch information
nscuro authored Jul 15, 2024
2 parents 78d667e + 36f8190 commit 37f4cff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ public JsonNode toJsonNode() {
}
}

public String toJsonString() {
try {
public String toJsonString() throws GeneratorException {
return toJson(bom, true);
} catch (GeneratorException e) {
return "";
}
}

/**
* Creates a text representation of a CycloneDX BoM Document. This method calls {@link #toJsonString()} and will return
* an empty string if {@link #toJsonString()} throws an exception. It's preferred to call {@link #toJsonString()}
* directly so that exceptions can be caught.
*
* @return a String of the BoM
*/
@Override
public String toString() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public Document generate() throws ParserConfigurationException {
}


public String toXmlString() throws GeneratorException {
return toXML(bom, true);
}

/**
* Creates a text representation of a CycloneDX BoM Document. This method calls {@link #toXmlString()} and will return
* an empty string if {@link #toXmlString()} throws an exception. It's preferred to call {@link #toXmlString()}
Expand All @@ -135,10 +139,6 @@ public Document generate() throws ParserConfigurationException {
* @return a String of the BoM
* @since 1.1.0
*/
public String toXmlString() throws GeneratorException {
return toXML(bom, true);
}

@Override
public String toString() {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/cyclonedx/Issue214RegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private void performXmlTest(final Version pSpecVersion)
}

private void performJsonTest(final Version pSpecVersion)
throws IOException, ReflectiveOperationException
{
throws IOException, ReflectiveOperationException, GeneratorException {
final Bom inputBom = createIssue214Bom();
BomJsonGenerator generator = BomGeneratorFactory.createJson(pSpecVersion, inputBom);

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/cyclonedx/parse/BaseParseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.cyclonedx.parse;

import org.cyclonedx.exception.GeneratorException;
import org.cyclonedx.Format;
import org.cyclonedx.generators.BomGeneratorFactory;
import org.cyclonedx.parsers.BomParserFactory;
Expand Down Expand Up @@ -75,7 +76,7 @@ void generateBomXml(final String testName, final Bom bom) throws ParserConfigura
}
}

void generateBomJson(final String testName, final Bom bom) {
void generateBomJson(final String testName, final Bom bom) throws GeneratorException {
List<Version> jsonVersions = Arrays.stream(Version.values())
.filter(v -> v.getFormats().contains(Format.JSON))
.collect(Collectors.toList());
Expand Down

0 comments on commit 37f4cff

Please sign in to comment.