Skip to content

Commit

Permalink
Do not require jdk when system.properties is missing (#546)
Browse files Browse the repository at this point in the history
Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
  • Loading branch information
Malax and heroku-linguist[bot] authored Jul 31, 2023
1 parent f06a1d8 commit 9bbbf6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 3 additions & 1 deletion buildpacks/jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* This buildpack now requires that an OpenJDK version is specified in `system.properties` when the buildpack is used standalone (no other buildpack adds `jdk` to the build plan `require`s). Users that use this buildpack in a standalone fashion can add a `system.properties` file to their application with the following contents to restore the old behavior of installing the most recent OpenJDK 8 release: `java.runtime.version=8`. ([#546](https://github.com/heroku/buildpacks-jvm/pull/546))

## [1.1.2] - 2023-07-24

* Default version for **OpenJDK 8** is now `1.8.0_382`. ([#543](https://github.com/heroku/buildpacks-jvm/pull/543))
Expand Down Expand Up @@ -227,4 +229,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[unreleased]: https://github.com/heroku/buildpacks-jvm/compare/v1.1.2...HEAD
[1.1.2]: https://github.com/heroku/buildpacks-jvm/compare/v1.1.1...v1.1.2
[1.1.1]: https://github.com/heroku/buildpacks-jvm/releases/tag/v1.1.1
[1.1.1]: https://github.com/heroku/buildpacks-jvm/releases/tag/v1.1.1
32 changes: 23 additions & 9 deletions buildpacks/jvm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,29 @@ impl Buildpack for OpenJdkBuildpack {
type Metadata = OpenJdkBuildpackMetadata;
type Error = OpenJdkBuildpackError;

fn detect(&self, _context: DetectContext<Self>) -> libcnb::Result<DetectResult, Self::Error> {
DetectResultBuilder::pass()
.build_plan(
BuildPlanBuilder::new()
.provides("jdk")
.requires("jdk")
.build(),
)
.build()
fn detect(&self, context: DetectContext<Self>) -> libcnb::Result<DetectResult, Self::Error> {
// This buildpack is first and foremost a buildpack that is designed for composing with
// other buildpacks, usually with JVM build tools such as Maven or Gradle. To enable
// other buildpacks to conditionally require the installation of OpenJDK, the detect of this
// buildpack wil fail if no other buildpack requires "jdk".
//
// Some users might want to install OpenJDK without using another buildpack, which wouldn't
// work with this buildpack since "jdk" would not be required in the build plan.
// To enable this use-case, this buildpack will require "jdk" (itself) if the app contains
// a system.properties file with a Java version. This is currently the way to define the
// OpenJDK version on Heroku.
let app_specifies_jvm_version = read_system_properties(&context.app_dir)
.map(|properties| properties.contains_key("java.runtime.version"))
.map_err(OpenJdkBuildpackError::ReadVersionStringError)?;

let build_plan = if app_specifies_jvm_version {
BuildPlanBuilder::new().provides("jdk").requires("jdk")
} else {
BuildPlanBuilder::new().provides("jdk")
}
.build();

DetectResultBuilder::pass().build_plan(build_plan).build()
}

fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
Expand Down

0 comments on commit 9bbbf6a

Please sign in to comment.