Skip to content

Commit

Permalink
Improve Code and remove duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Alzate <aalzate@sonatype.com>
  • Loading branch information
mr-zepol committed Apr 22, 2024
1 parent 0ea84a6 commit fa6b721
Show file tree
Hide file tree
Showing 26 changed files with 469 additions and 1,538 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@
<version>5.10.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
81 changes: 0 additions & 81 deletions src/main/java/org/cyclonedx/BomGeneratorFactory.java

This file was deleted.

52 changes: 52 additions & 0 deletions src/main/java/org/cyclonedx/generators/AbstractBomGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.cyclonedx.generators;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.cyclonedx.CycloneDxSchema;
import org.cyclonedx.Version;
import org.cyclonedx.model.Bom;
import org.cyclonedx.util.serializer.InputTypeSerializer;
import org.cyclonedx.util.serializer.LifecycleSerializer;
import org.cyclonedx.util.serializer.MetadataSerializer;
import org.cyclonedx.util.serializer.OutputTypeSerializer;

public abstract class AbstractBomGenerator extends CycloneDxSchema
{
protected ObjectMapper mapper;

protected final Version version;

protected final Bom bom;

public AbstractBomGenerator(final Version version, final Bom bom) {
this.mapper = new ObjectMapper();
this.version = version;
this.bom = bom;
}

/**
* Returns the version of the CycloneDX schema used by this instance
* @return a CycloneDxSchemaVersion enum
*/
public Version getSchemaVersion() {
return version;
}

protected void setupObjectMapper(boolean isXml) {
SimpleModule lifecycleModule = new SimpleModule();
lifecycleModule.addSerializer(new LifecycleSerializer(isXml));
mapper.registerModule(lifecycleModule);

SimpleModule metadataModule = new SimpleModule();
metadataModule.addSerializer(new MetadataSerializer(isXml, getSchemaVersion()));
mapper.registerModule(metadataModule);

SimpleModule inputTypeModule = new SimpleModule();
inputTypeModule.addSerializer(new InputTypeSerializer(isXml));
mapper.registerModule(inputTypeModule);

SimpleModule outputTypeModule = new SimpleModule();
outputTypeModule.addSerializer(new OutputTypeSerializer(isXml));
mapper.registerModule(outputTypeModule);
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/cyclonedx/generators/BomGeneratorFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* This file is part of CycloneDX Core (Java).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.cyclonedx.generators;

import org.cyclonedx.Version;
import org.cyclonedx.generators.xml.BomXmlGenerator;
import org.cyclonedx.model.Bom;
import org.cyclonedx.generators.json.BomJsonGenerator;

public class BomGeneratorFactory {

public static BomXmlGenerator createXml(Version version, Bom bom) {
return new BomXmlGenerator(bom, version);
}

public static BomJsonGenerator createJson(Version version, Bom bom) {
return new BomJsonGenerator(bom, version);
}
}

This file was deleted.

Loading

0 comments on commit fa6b721

Please sign in to comment.