Skip to content

Commit

Permalink
style: Fix more Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Feb 4, 2025
1 parent 8a134a8 commit 89e3f82
Show file tree
Hide file tree
Showing 76 changed files with 316 additions and 386 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/java/org/jboss/sbomer/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class CLI implements QuarkusApplication {

@Override
@ActivateRequestContext
public int run(String... args) throws Exception {
public int run(String... args) {
CommandLine commandLine = new CommandLine(this, factory).setExecutionExceptionHandler(new ExceptionHandler())
.setExecutionStrategy(new RunOnlyCallable())
.setCommandName("sbomerctl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.jboss.sbomer.cli;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void filterComponents(List<Component> components) {
* </p>
*
* <p>
* At the same time it cleans up the main compontn available in the {@link Metadata#getComponent()}.
* At the same time it cleans up the main component available in the {@link Metadata#getComponent()}.
* </p>
*
* @param bom
Expand Down Expand Up @@ -293,11 +293,11 @@ private void adjustProperties(Bom bom) {
*
* <p>
* Adjusts any values in the main component as well as for each component found in the component list (recursively).
* See {@link SyftImageAdjuster#adjustPublisher(List)}.
* See {@link SyftImageAdjuster#adjustPublisher(Bom)}.
* </p>
*
* @param bom The manifest to adjust the properties of.
* @see SyftImageAdjuster#adjustPublisher(List)
* @see SyftImageAdjuster#adjustPublisher(Bom)
*/
private void adjustPublisher(Bom bom) {
log.info("Adjusting manifest publisher...");
Expand Down Expand Up @@ -331,12 +331,12 @@ private void adjustComponentPublisher(Component component) {
* Based on the metadata we got the output of Skopeo ({@code skopeo.json} file), adjust main component's purl and
* name.
*
* @param component
* @param bom
* @param workDir
*/
private void adjustNameAndPurl(Bom bom, Path workDir) {
String tag = null;
ContainerImageInspectOutput inspectData = null;
String tag;
ContainerImageInspectOutput inspectData;
final Component mainComponent = bom.getMetadata().getComponent();

try {
Expand Down Expand Up @@ -378,6 +378,7 @@ private void adjustNameAndPurl(Bom bom, Path workDir) {
}
}

// FIXME: This can be null here
String[] nameParts = name.split(("/"));

TreeMap<String, String> qualifiers = new TreeMap<>();
Expand Down Expand Up @@ -493,12 +494,12 @@ private void adjustProperties(List<Property> properties) {
boolean supportedProp = ALLOWED_PROPERTY_PREFIXES.stream()
.anyMatch(prefix -> prop.getName().startsWith(prefix));

if (!supportedProp) {
// log.debug(
// "Property '{}' with value '{}' is not on the supported properties list, removing...",
// prop.getName(),
// prop.getValue());
}
// if (!supportedProp) {
// log.debug(
// "Property '{}' with value '{}' is not on the supported properties list, removing...",
// prop.getName(),
// prop.getValue());
// }

return !supportedProp;
});
Expand Down Expand Up @@ -580,16 +581,15 @@ private String doCleanupPurl(String purl) throws MalformedPackageURLException {

// If we removed any qualifiers, we need to rebuild the purl
if (qualifiers.entrySet().removeIf(q -> !q.getKey().equals("arch") && !q.getKey().equals("epoch"))) {
String updatedPurl = new PackageURL(

// log.debug("Updating purl to: '{}'", updatedPurl);
return new PackageURL(
packageURL.getType(),
packageURL.getNamespace(),
packageURL.getName(),
packageURL.getVersion(),
qualifiers,
packageURL.getSubpath()).canonicalize();

// log.debug("Updating purl to: '{}'", updatedPurl);
return updatedPurl;
}
return packageURL.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected String toolVersion() {
}

@Override
public Integer call() throws Exception {
public Integer call() {
// Make sure there is no context
MDCUtils.removeContext();
MDCUtils.addBuildContext(parent.getBuildId());
Expand Down Expand Up @@ -313,7 +313,7 @@ protected void doClone(String url, String tag, Path path, boolean force) {
}

log.info("Cloning the repository to {}...", path);
try (Git git = Git.cloneRepository()
try (Git ignored = Git.cloneRepository()
.setDirectory(path.toFile())
.setURI(url)
.setBranch(tag)
Expand All @@ -333,7 +333,7 @@ protected void doClone(String url, String tag, Path path, boolean force) {

// Please note that this ignores the block size of a particular storage,
// and because of this, the number can be different compared to when
// an utility like `du` is being used to determine the size.
// a utility like `du` is being used to determine the size.
log.info("Directory size: {} MB", String.format("%.02f", (float) dirSize(path) / 1024));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public abstract class AbstractGenerateOperationCommand implements Callable<Integ
protected abstract GeneratorType generatorType();

@Override
public Integer call() throws Exception {
public Integer call() {
// Make sure there is no context
MDCUtils.removeContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import picocli.CommandLine.Option;
import picocli.CommandLine.ScopeType;

@Getter
public abstract class AbstractGradleGenerateCommand extends AbstractGenerateCommand {

@Getter
@Option(
names = { "--init-script" },
description = "Path to Gradle init script file that should be used for this run instead of the default one",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import picocli.CommandLine.Option;
import picocli.CommandLine.ScopeType;

@Getter
public abstract class AbstractMavenGenerateCommand extends AbstractGenerateCommand {

@Getter
@Option(
names = { "-s", "--settings" },
description = "Path to Maven settings.xml file that should be used for this run instead of the default one",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class AbstractProcessCommand implements Callable<Integer> {
protected PncService pncService;

@Override
public Integer call() throws Exception {
public Integer call() {
try {
// Make sure there is no context.
MDCUtils.removeContext();
Expand Down Expand Up @@ -67,7 +67,7 @@ public Integer call() throws Exception {
protected abstract ProcessorType getImplementationType();

/**
* Optionally adds a MDC context. The {@link MDCUtils} class can be used for this purpose.
* Optionally adds an MDC context. The {@link MDCUtils} class can be used for this purpose.
*/
protected void addContext() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected Path doGenerate() {
config);

// Get some metadata about the operation
String productName = "";
String productName;
String productMilestone = "";
DeliverableAnalyzerOperation operation = pncService.getDeliverableAnalyzerOperation(config.getOperationId());
if (operation.getProductMilestone() != null) {
Expand Down Expand Up @@ -254,8 +254,9 @@ protected Path doGenerate() {
}

// Find the parent to set the correct hierarchy, default to the main root dependency
for (String key : pathToDependencies.keySet()) {
Dependency dependency = pathToDependencies.get(key);
for (Map.Entry<String, Dependency> entry : pathToDependencies.entrySet()) {
String key = entry.getKey();
Dependency dependency = entry.getValue();
Optional<Dependency> maybeParent = findClosestParent(pathToDependencies, key);
Dependency parent = maybeParent.orElse(mainDependency);
parent.addDependency(dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import picocli.CommandLine.Option;
import picocli.CommandLine.ScopeType;

@Getter
@Command(
mixinStandardHelpOptions = true,
name = "generate",
Expand All @@ -33,18 +34,15 @@
GradleCycloneDxGenerateCommand.class, NodejsCycloneDxGenerateCommand.class })
public class GenerateCommand {

@Getter
@Option(names = { "-b", "--build-id" }, description = "Build identifier to generate the SBOM for", required = true)
String buildId;

@Getter
@Option(
names = { "-f", "--force" },
description = "If the workdir directory should be cleaned up in case it already exists. Default: ${DEFAULT-VALUE}",
scope = ScopeType.INHERIT)
boolean force = false;

@Getter
@Option(
names = { "--workdir" },
defaultValue = "workdir",
Expand All @@ -54,7 +52,6 @@ public class GenerateCommand {
scope = ScopeType.INHERIT)
Path workdir;

@Getter
@Option(
names = { "-o", "--output" },
defaultValue = "bom.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import picocli.CommandLine.Option;
import picocli.CommandLine.ScopeType;

@Getter
@Command(
mixinStandardHelpOptions = true,
name = "generate-operation",
Expand All @@ -32,7 +33,6 @@
subcommands = { CycloneDxGenerateOperationCommand.class })
public class GenerateOperationCommand {

@Getter
@Option(
names = { "-c", "--config", },
paramLabel = "FILE",
Expand All @@ -41,28 +41,24 @@ public class GenerateOperationCommand {
scope = ScopeType.INHERIT)
Path configPath;

@Getter
@Option(
names = { "--index" },
description = "Index to select the product configuration passed in the --config option. Starts from 0. If not provided SBOM will be generated for every product in the config serially.",
scope = ScopeType.INHERIT)
Integer index;

@Getter
@Option(
names = { "-op", "--operation-id" },
description = "Operation identifier to generate the SBOM for",
required = true)
String operationId;

@Getter
@Option(
names = { "-f", "--force" },
description = "If the workdir directory should be cleaned up in case it already exists. Default: ${DEFAULT-VALUE}",
scope = ScopeType.INHERIT)
boolean force = false;

@Getter
@Option(
names = { "--workdir" },
defaultValue = "workdir",
Expand All @@ -72,7 +68,6 @@ public class GenerateOperationCommand {
scope = ScopeType.INHERIT)
Path workdir;

@Getter
@Option(
names = { "-o", "--output" },
defaultValue = "bom.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected GeneratorType generatorType() {
}

private void configureProcessEnvironmentVariable(String buildCmdOptions, Map<String, String> environment) {
// If there is an hint about the major Gradle version required, use it.
// If there is a hint about the major Gradle version required, use it.
Optional<Integer> gradleMajorVersion = extractGradleMajorVersion(buildCmdOptions);
if (gradleMajorVersion.isEmpty() || gradleMajorVersion.get() >= 5) {
environment.put(GRADLE_PLUGIN_VERSION_ENV_VARIABLE, toolVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;

@Getter
@Command(
mixinStandardHelpOptions = true,
name = "process",
Expand All @@ -30,7 +31,6 @@
subcommandsRepeatable = true)
public class ProcessCommand {

@Getter
@ParentCommand
AbstractGenerateCommand parent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractAdjustCommand implements Callable<Integer> {
AdjustCommand parent;

@Override
public Integer call() throws Exception {
public Integer call() {
try {
// Make sure there is no context.
MDCUtils.removeContext();
Expand All @@ -60,7 +60,7 @@ public Integer call() throws Exception {
}

/**
* Optionally adds a MDC context. The {@link MDCUtils} class can be used for this purpose.
* Optionally adds an MDC context. The {@link MDCUtils} class can be used for this purpose.
*/
protected void addContext() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import picocli.CommandLine.Option;
import picocli.CommandLine.ScopeType;

@Getter
@Command(
mixinStandardHelpOptions = true,
name = "adjust",
Expand All @@ -34,7 +35,6 @@
subcommandsRepeatable = true)
public class AdjustCommand {

@Getter
@Option(
names = { "-p", "--path" },
required = true,
Expand All @@ -44,7 +44,6 @@ public class AdjustCommand {
scope = ScopeType.INHERIT)
Path path;

@Getter
@Option(
names = { "-o", "--output" },
defaultValue = "bom.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class GenerateCommand implements Callable<Integer> {
* generation process did not finish successfully
*/
@Override
public Integer call() throws Exception {
public Integer call() {

if (configPath == null) {
log.info("Configuration path is null, cannot do any generation.");
Expand Down
Loading

0 comments on commit 89e3f82

Please sign in to comment.