Skip to content

Commit

Permalink
Use unified Heroku buildpack output style
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed Nov 22, 2024
1 parent 8232a8d commit a192e60
Show file tree
Hide file tree
Showing 16 changed files with 785 additions and 216 deletions.
2 changes: 1 addition & 1 deletion buildpacks/gradle/src/gradle_command/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn start(
) -> Result<(), GradleCommandError<()>> {
let output = Command::new(gradle_wrapper_executable_path)
.args([
// Fixes an issue when when running under Apple Rosetta emulation
// Fixes an issue when running under Apple Rosetta emulation
"-Djdk.lang.Process.launchMechanism=vfork",
"--daemon",
GRADLE_TASK_NAME_HEROKU_START_DAEMON,
Expand Down
36 changes: 25 additions & 11 deletions buildpacks/gradle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::gradle_command::GradleCommandError;
use crate::layers::gradle_home::handle_gradle_home_layer;
use crate::GradleBuildpackError::{GradleBuildIoError, GradleBuildUnexpectedStatusError};
use buildpacks_jvm_shared as shared;
use buildpacks_jvm_shared::output::{
print_buildpack_name, print_section, print_subsection, track_timing,
};
#[cfg(test)]
use buildpacks_jvm_shared_test as _;
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
Expand Down Expand Up @@ -75,7 +78,8 @@ impl Buildpack for GradleBuildpack {
}

fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
log_header("Gradle Buildpack");
print_buildpack_name("Heroku Gradle Buildpack");

let buildpack_config = GradleBuildpackConfig::from(&context);

let gradle_wrapper_executable_path = Some(context.app_dir.join("gradlew"))
Expand All @@ -88,16 +92,26 @@ impl Buildpack for GradleBuildpack {
let mut gradle_env = Env::from_current();
handle_gradle_home_layer(&context, &mut gradle_env)?;

log_header("Starting Gradle Daemon");
gradle_command::start_daemon(&gradle_wrapper_executable_path, &gradle_env)
.map_err(GradleBuildpackError::StartGradleDaemonError)?;

let project_tasks = gradle_command::tasks(&context.app_dir, &gradle_env)
.map_err(|command_error| command_error.map_parse_error(|_| ()))
.map_err(GradleBuildpackError::GetTasksError)?;

let dependency_report = gradle_command::dependency_report(&context.app_dir, &gradle_env)
.map_err(GradleBuildpackError::GetDependencyReportError)?;
print_section("Running Gradle build");

track_timing(|| {
print_subsection("Starting Gradle daemon");
gradle_command::start_daemon(&gradle_wrapper_executable_path, &gradle_env)
.map_err(GradleBuildpackError::StartGradleDaemonError)
})?;

let project_tasks = track_timing(|| {
print_subsection("Querying tasks");
gradle_command::tasks(&context.app_dir, &gradle_env)
.map_err(|command_error| command_error.map_parse_error(|_| ()))
.map_err(GradleBuildpackError::GetTasksError)
})?;

let dependency_report = track_timing(|| {
print_subsection("Querying dependency report");
gradle_command::dependency_report(&context.app_dir, &gradle_env)
.map_err(GradleBuildpackError::GetDependencyReportError)
})?;

let task_name = buildpack_config
.gradle_task
Expand Down
4 changes: 4 additions & 0 deletions buildpacks/jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Buildpack output changed to a new format. ([#000](https://github.com/heroku/buildpacks-jvm/pull/000))

## [6.0.3] - 2024-09-26

### Added
Expand Down
55 changes: 30 additions & 25 deletions buildpacks/jvm/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::openjdk_artifact::HerokuOpenJdkVersionRequirement;
use crate::{OpenJdkArtifactRequirementParseError, OpenJdkBuildpackError};
use crate::openjdk_artifact::{
HerokuOpenJdkVersionRequirement, OpenJdkArtifactRequirementParseError,
};
use crate::version_resolver::VersionResolveError;
use crate::OpenJdkBuildpackError;
use buildpacks_jvm_shared::log::{log_please_try_again, log_please_try_again_error};
use buildpacks_jvm_shared::system_properties::ReadSystemPropertiesError;
use indoc::formatdoc;
Expand All @@ -8,19 +11,6 @@ use libherokubuildpack::log::log_error;
#[allow(clippy::too_many_lines)]
pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
match error {
OpenJdkBuildpackError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::UnknownDistribution(distribution)) => log_error(
format!("Unsupported distribution: {distribution}"),
formatdoc! {"
Please check your system.properties file to ensure the java.runtime.version
string does not contain an unsupported distribution prefix.
You can also remove the system.properties file from your application to install
the default OpenJDK version.
Thanks,
Heroku
"},
),
OpenJdkBuildpackError::CannotCreateOpenJdkTempDir(error) => log_please_try_again_error(
"Unexpected IO error",
"Could not create temporary directory for the OpenJDK download due to an unexpected I/O error.",
Expand Down Expand Up @@ -112,15 +102,6 @@ pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
Details: {error}
", error = error },
),
OpenJdkBuildpackError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::OpenJdkVersionParseError(error)) => log_error(
"Invalid OpenJDK version selector",
formatdoc! {"
The OpenJDK version selector you specified in your system.properties file is invalid.
Please specify a valid version selector in your system.properties file.
Details: {error}
", error = error },
),
OpenJdkBuildpackError::OpenJdkTarballChecksumError { expected, actual } => log_please_try_again(
"Corrupted OpenJDK download",
formatdoc! {"
Expand All @@ -129,6 +110,30 @@ pub(crate) fn on_error_jvm_buildpack(error: OpenJdkBuildpackError) {
Expected: {expected}
Actual: {actual}
", expected = hex::encode(expected), actual = hex::encode(actual) }
)
),
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::UnknownDistribution(distribution))) => log_error(
format!("Unsupported distribution: {distribution}"),
formatdoc! {"
Please check your system.properties file to ensure the java.runtime.version
string does not contain an unsupported distribution prefix.
You can also remove the system.properties file from your application to install
the default OpenJDK version.
Thanks,
Heroku
"}),
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::ReadSystemPropertiesError(error)) => {
log_error(
"Invalid OpenJDK version selector",
formatdoc! {"
The OpenJDK version selector you specified in your system.properties file is invalid.
Please specify a valid version selector in your system.properties file.
Details: {error:?}
", error = error },
);
}
OpenJdkBuildpackError::ResolveVersionError(VersionResolveError::OpenJdkArtifactRequirementParseError(OpenJdkArtifactRequirementParseError::OpenJdkVersionParseError(_))) => {}
}
}
Loading

0 comments on commit a192e60

Please sign in to comment.