Skip to content

Commit

Permalink
Rebase and update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed Sep 30, 2024
1 parent fbff0f8 commit 2231080
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 75 deletions.
301 changes: 236 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions buildpacks/maven/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub(crate) fn on_error_maven_buildpack(error: MavenBuildpackError) {
"Creating temporary directory for SBOM files failed",
error,
),
MavenBuildpackError::CannotReadMavenSbomFile(error) => log_please_try_again_error(
"Reading Maven SBOM failed",
"Failed to read SBOM produced by Maven.",
error,
),
MavenBuildpackError::MavenTarballDecompressError(error) => log_please_try_again_error(
"Maven download failed",
"Could not download Maven distribution.",
Expand Down
9 changes: 6 additions & 3 deletions buildpacks/maven/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum MavenBuildpackError {
CannotSetMavenWrapperExecutableBit(std::io::Error),
DefaultAppProcessError(DefaultAppProcessError),
CannotCreateTemporarySbomDirectory(std::io::Error),
CannotReadMavenSbomFile(std::io::Error),
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -261,6 +262,7 @@ impl Buildpack for MavenBuildpack {
maven_options.iter().chain(&internal_maven_options).chain(
[
format!("-DoutputDirectory={}", sbom_dir.to_string_lossy()),
String::from("-DschemaVersion=1.4"),
String::from("org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom"),
]
.iter(),
Expand All @@ -273,9 +275,10 @@ impl Buildpack for MavenBuildpack {

let mut build_result_builder = BuildResultBuilder::new();

build_result_builder = build_result_builder.launch_sbom(
Sbom::from_path(SbomFormat::CycloneDxJson, sbom_dir.join("bom.json")).unwrap(),
);
let launch_sbom = Sbom::from_path(SbomFormat::CycloneDxJson, sbom_dir.join("bom.json"))
.map_err(MavenBuildpackError::CannotReadMavenSbomFile)?;

build_result_builder = build_result_builder.launch_sbom(launch_sbom);

if let Some(process) = framework::default_app_process(&context.app_dir)
.map_err(MavenBuildpackError::DefaultAppProcessError)?
Expand Down
6 changes: 3 additions & 3 deletions buildpacks/maven/tests/integration/sbom.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::default_config;
use crate::default_build_config;
use libcnb::data::buildpack_id;
use libcnb::data::sbom::SbomFormat;
use libcnb_test::{SbomType, TestRunner};
Expand All @@ -7,7 +7,7 @@ use serde_cyclonedx::cyclonedx::v_1_4::{Component, CycloneDx, HashAlg};
#[test]
#[ignore = "integration test"]
pub(crate) fn sbom() {
TestRunner::default().build(default_config(), |context| {
TestRunner::default().build(default_build_config("test-apps/simple-http-service"), |context| {
context.download_sbom_files(|sbom_files| {
let sbom_path = sbom_files.path_for(
buildpack_id!("heroku/maven"),
Expand All @@ -24,7 +24,7 @@ pub(crate) fn sbom() {
.collect::<Result<Vec<SimpleSbomComponent>, _>>();

assert_eq!(sbom_simple_components, Ok(vec![
SimpleSbomComponent { purl: String::from("pkg:maven/io.undertow/[email protected].5.Final?type=jar"), sha256_hash: String::from("6a74380bc67a6b4a63eef12b882a076662fc1bb831c3dc4688ca2026ea7f9754"), main_license_id: String::from("Apache-2.0") },
SimpleSbomComponent { purl: String::from("pkg:maven/io.undertow/[email protected].12.Final?type=jar"), sha256_hash: String::from("3da2764c7a487e9bf196c9d28c95277648e0c510aa7449e17027b99a1052a53e"), main_license_id: String::from("Apache-2.0") },
SimpleSbomComponent { purl: String::from("pkg:maven/org.jboss.logging/[email protected]?type=jar"), sha256_hash: String::from("0b324cca4d550060e51e70cc0045a6cce62f264278ec1f5082aafeb670fcac49"), main_license_id: String::from("Apache-2.0") },
SimpleSbomComponent { purl: String::from("pkg:maven/org.jboss.xnio/[email protected]?type=jar"), sha256_hash: String::from("701988bea1c7426d0cdbbd94c02141031cfe3001a470750e2d25b6ac166b7873"), main_license_id: String::from("Apache-2.0") },
SimpleSbomComponent { purl: String::from("pkg:maven/org.wildfly.common/[email protected]?type=jar"), sha256_hash: String::from("9fda3caf8bd528dec56ebc70daf78f5a9ff5d0bfcea8b3e41ab7ae838747e46a"), main_license_id: String::from("Apache-2.0") },
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/sbt/test-apps/heroku-scala-getting-started
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
allow-unwrap-in-tests = true
doc-valid-idents = ["OpenJDK", ".."]
doc-valid-idents = ["OpenJDK", "CycloneDX", ".."]

0 comments on commit 2231080

Please sign in to comment.