This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-19644 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 59d58eda1934ec0ec2f1f9c95a4b71c407e15831 Author: Andrea Cosentino <[email protected]> AuthorDate: Thu Sep 28 15:14:36 2023 +0200 CAMEL-19644 - camel-jbang - Add command to generate SBOM report Signed-off-by: Andrea Cosentino <[email protected]> --- .../dsl/jbang/core/commands/CamelJBangMain.java | 3 +- .../dsl/jbang/core/commands/SBOMGenerator.java | 62 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java index 78310fa8e6a..7f0f22e1007 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java @@ -150,7 +150,8 @@ public class CamelJBangMain implements Callable<Integer> { .addSubcommand("version", new CommandLine(new VersionCommand(main)) .addSubcommand("get", new CommandLine(new VersionGet(main))) .addSubcommand("set", new CommandLine(new VersionSet(main))) - .addSubcommand("list", new CommandLine(new VersionList(main)))); + .addSubcommand("list", new CommandLine(new VersionList(main)))) + .addSubcommand("sbom", new CommandLine(new SBOMGenerator(main))); commandLine.getCommandSpec().versionProvider(() -> { CamelCatalog catalog = new DefaultCamelCatalog(); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/SBOMGenerator.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/SBOMGenerator.java new file mode 100644 index 00000000000..89329aa5c35 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/SBOMGenerator.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.camel.dsl.jbang.core.commands; + +import java.util.concurrent.TimeUnit; + +import picocli.CommandLine; + [email protected](name = "sbom", + description = "Generate a CycloneDX SBOM for a specific Maven project") +public class SBOMGenerator extends CamelCommand { + + @CommandLine.Option(names = { "--output-directory" }, description = "Directory where the SBOM will be saved", + defaultValue = ".") + protected String outputDirectory; + + @CommandLine.Option(names = { "--output-name" }, description = "Output name of the SBOM file", + defaultValue = "sbom") + protected String outputName; + + @CommandLine.Option(names = { "--plugin-version" }, description = "The CycloneDX Maven Plugin version", + defaultValue = "2.7.9") + protected String pluginVersion = "2.7.9"; + + public SBOMGenerator(CamelJBangMain main) { + super(main); + } + + @Override + public Integer doCall() throws Exception { + Integer answer = null; + Process p = Runtime.getRuntime() + .exec("mvn org.cyclonedx:cyclonedx-maven-plugin:" + pluginVersion + ":makeAggregateBom -DoutputDirectory=" + + outputDirectory + + " -DoutputName=" + + outputName, + null, + null); + boolean done = p.waitFor(60, TimeUnit.SECONDS); + if (!done) { + answer = 1; + } + if (p.exitValue() != 0) { + answer = p.exitValue(); + } + return answer; + } +}
