Skip to content

Commit

Permalink
Update to libcnb 0.12.0 and buildpack API 0.9 (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed May 2, 2023
1 parent becafb5 commit 94c9cef
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 137 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ edition = "2021"
publish = false

[workspace.dependencies]
libcnb = "0.11"
libcnb-test = "0.11"
libherokubuildpack = "0.11"
libcnb = "0.12"
libcnb-test = "0.12"
libherokubuildpack = "0.12"
toml = "0.7"
buildpacks-jvm-shared = { path = "buildpacks-jvm-shared" }
3 changes: 3 additions & 0 deletions buildpacks/jvm-function-invoker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Upgrade `libcnb` and `libherokubuildpack` to `0.12.0`. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))
* The buildpack now implements Buildpack API 0.9 instead of 0.8, and so requires `lifecycle` 0.15.x or newer. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))

## [0.6.7] 2023/01/19
* Update `sf-fx-runtime-java` from `1.1.2` to `1.1.3`.

Expand Down
2 changes: 1 addition & 1 deletion buildpacks/jvm-function-invoker/buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api = "0.8"
api = "0.9"

[buildpack]
id = "heroku/jvm-function-invoker"
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/jvm-function-invoker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Buildpack for JvmFunctionInvokerBuildpack {
.process(
ProcessBuilder::new(
process_type!("web"),
layers::opt::JVM_RUNTIME_SCRIPT_NAME,
["bash", layers::opt::JVM_RUNTIME_SCRIPT_NAME],
)
.default(true)
.build(),
Expand Down
3 changes: 3 additions & 0 deletions buildpacks/jvm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Upgrade `libcnb` and `libherokubuildpack` to `0.12.0`. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))
* The buildpack now implements Buildpack API 0.9 instead of 0.8, and so requires `lifecycle` 0.15.x or newer. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))

## [1.0.9] 2023/04/24

* Default version for **OpenJDK 8** is now `1.8.0_372`. ([#459](https://github.com/heroku/buildpacks-jvm/pull/459))
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/jvm/buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api = "0.8"
api = "0.9"

[buildpack]
id = "heroku/jvm"
Expand Down
3 changes: 3 additions & 0 deletions buildpacks/maven/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Upgrade `libcnb` and `libherokubuildpack` to `0.12.0`. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))
* The buildpack now implements Buildpack API 0.9 instead of 0.8, and so requires `lifecycle` 0.15.x or newer. ([#463](https://github.com/heroku/buildpacks-jvm/pull/463))

## [1.0.3] 2022/09/28

* Upgrade `libcnb` and `libherokubuildpack` to `0.11.0`. ([#371](https://github.com/heroku/buildpacks-jvm/pull/371))
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/maven/buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api = "0.8"
api = "0.9"

[buildpack]
id = "heroku/maven"
Expand Down
26 changes: 16 additions & 10 deletions buildpacks/maven/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,30 @@ pub(crate) fn default_app_process<P: AsRef<Path>>(
(Some(Framework::SpringBoot), Some(main_jar_file_path)) => Some(
ProcessBuilder::new(
process_type!("web"),
format!(
"java -Dserver.port=$PORT $JAVA_OPTS -jar {}",
main_jar_file_path.to_string_lossy()
),
[
"bash",
"-c",
&format!(
"java -Dserver.port=$PORT $JAVA_OPTS -jar {}",
main_jar_file_path.to_string_lossy()
),
],
)
.direct(false)
.default(true)
.build(),
),
(Some(Framework::WildflySwarm), Some(main_jar_file_path)) => Some(
ProcessBuilder::new(
process_type!("web"),
format!(
"java -Dswarm.http.port=$PORT $JAVA_OPTS -jar {}",
main_jar_file_path.to_string_lossy()
),
[
"bash",
"-c",
&format!(
"java -Dswarm.http.port=$PORT $JAVA_OPTS -jar {}",
main_jar_file_path.to_string_lossy()
),
],
)
.direct(false)
.default(true)
.build(),
),
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/sbt/buildpack.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api = "0.8"
api = "0.9"

[buildpack]
id = "heroku/sbt"
Expand Down
109 changes: 15 additions & 94 deletions buildpacks/sbt/src/build_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::errors::ScalaBuildpackError;
use crate::errors::ScalaBuildpackError::{
CouldNotConvertEnvironmentValueIntoString, CouldNotParseBooleanFromEnvironment,
CouldNotParseBooleanFromProperty, CouldNotParseListConfigurationFromEnvironment,
CouldNotParseListConfigurationFromProperty, CouldNotParseListConfigurationFromSbtOptsFile,
CouldNotReadSbtOptsFile, InvalidSbtPropertiesFile, MissingDeclaredSbtVersion,
MissingSbtBuildPropertiesFile, SbtPropertiesFileReadError, SbtVersionNotInSemverFormat,
UnsupportedSbtVersion,
CouldNotParseBooleanFromEnvironment, CouldNotParseBooleanFromProperty,
CouldNotParseListConfigurationFromEnvironment, CouldNotParseListConfigurationFromProperty,
CouldNotParseListConfigurationFromSbtOptsFile, CouldNotReadSbtOptsFile,
InvalidSbtPropertiesFile, MissingDeclaredSbtVersion, MissingSbtBuildPropertiesFile,
SbtPropertiesFileReadError, SbtVersionNotInSemverFormat, UnsupportedSbtVersion,
};
use libcnb::Env;
use semver::{Version, VersionReq};
Expand All @@ -32,7 +31,7 @@ pub(crate) fn create_build_config<P: Into<PathBuf>>(
let sbt_opts_file = app_dir.join(".sbtopts");
let properties = read_system_properties(&app_dir);
Ok(BuildConfiguration {
sbt_project: read_string_config("sbt.project", &properties, "SBT_PROJECT", env)?,
sbt_project: read_string_config("sbt.project", &properties, "SBT_PROJECT", env),
sbt_pre_tasks: read_string_list_config("sbt.pre-tasks", &properties, "SBT_PRE_TASKS", env)?,
sbt_tasks: read_string_list_config("sbt.tasks", &properties, "SBT_TASKS", env)?,
sbt_clean: read_boolean_config("sbt.clean", &properties, "SBT_CLEAN", env)?,
Expand All @@ -58,19 +57,11 @@ fn read_string_config(
system_properties: &HashMap<String, String>,
environment_variable_name: &str,
env: &Env,
) -> Result<Option<String>, ScalaBuildpackError> {
if let Some(value) = system_properties.get(property_name) {
return Ok(Some(value.clone()));
}

if let Some(value) = env.get(environment_variable_name) {
let value = value.into_string().map_err(|e| {
CouldNotConvertEnvironmentValueIntoString(environment_variable_name.to_string(), e)
})?;
return Ok(Some(value));
}

Ok(None)
) -> Option<String> {
system_properties
.get(property_name)
.cloned()
.or(env.get_string_lossy(environment_variable_name))
}

fn read_boolean_config(
Expand All @@ -86,10 +77,7 @@ fn read_boolean_config(
.map_err(|e| CouldNotParseBooleanFromProperty(property_name.to_string(), e));
}

if let Some(value) = env.get(environment_variable_name) {
let value = value.into_string().map_err(|e| {
CouldNotConvertEnvironmentValueIntoString(environment_variable_name.to_string(), e)
})?;
if let Some(value) = env.get_string_lossy(environment_variable_name) {
return value.parse::<bool>().map(Some).map_err(|e| {
CouldNotParseBooleanFromEnvironment(environment_variable_name.to_string(), e)
});
Expand All @@ -110,10 +98,7 @@ fn read_string_list_config(
.map_err(|e| CouldNotParseListConfigurationFromProperty(property_name.to_string(), e));
}

if let Some(value) = env.get(environment_variable_name) {
let value = value.into_string().map_err(|e| {
CouldNotConvertEnvironmentValueIntoString(environment_variable_name.to_string(), e)
})?;
if let Some(value) = env.get_string_lossy(environment_variable_name) {
return shell_words::split(&value).map(Some).map_err(|e| {
CouldNotParseListConfigurationFromEnvironment(environment_variable_name.to_string(), e)
});
Expand All @@ -137,10 +122,7 @@ fn read_sbt_opts(
configured = true;
}

if let Some(value) = env.get("SBT_OPTS") {
let value = value
.into_string()
.map_err(|e| CouldNotConvertEnvironmentValueIntoString("SBT_OPTS".to_string(), e))?;
if let Some(value) = env.get_string_lossy("SBT_OPTS") {
let mut opts = shell_words::split(&value).map_err(|e| {
CouldNotParseListConfigurationFromEnvironment("SBT_OPTS".to_string(), e)
})?;
Expand Down Expand Up @@ -204,10 +186,9 @@ mod create_build_config_tests {
MissingSbtBuildPropertiesFile, UnsupportedSbtVersion, Version,
};
use crate::errors::ScalaBuildpackError;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::fs::{create_dir, write};
use std::io::BufWriter;
use std::os::unix::ffi::OsStrExt;
use tempfile::{tempdir, TempDir};

macro_rules! assert_err {
Expand Down Expand Up @@ -236,11 +217,6 @@ mod create_build_config_tests {
java_properties::write(writer, &properties).unwrap();
}

fn invalid_unicode_os_string() -> OsString {
let invalid_unicode_sequence = [0x66, 0x6f, 0x80, 0x6f];
OsStr::from_bytes(&invalid_unicode_sequence[..]).to_os_string()
}

#[test]
fn create_build_config_raises_error_if_project_is_missing_the_sbt_build_properties_file() {
let app_dir = tempdir().unwrap();
Expand Down Expand Up @@ -385,17 +361,6 @@ mod create_build_config_tests {
assert_eq!(config.sbt_project, Some(String::from("testProjectName")));
}

#[test]
fn create_build_config_raises_error_when_sbt_project_is_configured_from_environment_with_non_unicode_bytes(
) {
let app_dir = tempdir().unwrap();
let mut env = Env::new();
set_sbt_version(&app_dir, "1.8.2");
env.insert("SBT_PROJECT", invalid_unicode_os_string());
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotConvertEnvironmentValueIntoString(name, _) if name == "SBT_PROJECT");
}

#[test]
fn create_build_config_when_sbt_pre_tasks_is_not_configured() {
let app_dir = tempdir().unwrap();
Expand Down Expand Up @@ -462,17 +427,6 @@ mod create_build_config_tests {
assert_err!(err, ScalaBuildpackError::CouldNotParseListConfigurationFromEnvironment(name, _) if name == "SBT_PRE_TASKS");
}

#[test]
fn create_build_config_raises_error_when_sbt_pre_tasks_environment_variable_contains_non_unicode_bytes(
) {
let app_dir = tempdir().unwrap();
let mut env = Env::new();
env.insert("SBT_PRE_TASKS", invalid_unicode_os_string());
set_sbt_version(&app_dir, "1.8.2");
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotConvertEnvironmentValueIntoString(name, _) if name == "SBT_PRE_TASKS");
}

#[test]
fn create_build_config_when_sbt_clean_is_not_configured() {
let app_dir = tempdir().unwrap();
Expand Down Expand Up @@ -524,17 +478,6 @@ mod create_build_config_tests {
assert_err!(err, ScalaBuildpackError::CouldNotParseBooleanFromEnvironment(name, _) if name == "SBT_CLEAN");
}

#[test]
fn create_build_config_when_sbt_clean_is_configured_from_env_and_value_contains_non_unicode_bytes(
) {
let app_dir = tempdir().unwrap();
let mut env = Env::new();
env.insert("SBT_CLEAN", invalid_unicode_os_string());
set_sbt_version(&app_dir, "1.8.2");
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotConvertEnvironmentValueIntoString(name, _) if name == "SBT_CLEAN");
}

#[test]
fn create_build_config_when_sbt_clean_prefers_system_property_over_env() {
let app_dir = tempdir().unwrap();
Expand Down Expand Up @@ -609,17 +552,6 @@ mod create_build_config_tests {
assert_err!(err, ScalaBuildpackError::CouldNotParseListConfigurationFromEnvironment(name, _) if name == "SBT_TASKS");
}

#[test]
fn create_build_config_raises_error_when_sbt_tasks_environment_variable_contains_non_unicode_bytes(
) {
let app_dir = tempdir().unwrap();
let mut env = Env::new();
env.insert("SBT_TASKS", invalid_unicode_os_string());
set_sbt_version(&app_dir, "1.8.2");
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotConvertEnvironmentValueIntoString(name, _) if name == "SBT_TASKS");
}

#[test]
fn create_build_config_when_sbt_opts_is_not_configured() {
let app_dir = tempdir().unwrap();
Expand Down Expand Up @@ -690,15 +622,4 @@ mod create_build_config_tests {
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotParseListConfigurationFromEnvironment(name, _) if name == "SBT_OPTS");
}

#[test]
fn create_build_config_raises_error_when_sbt_opts_environment_variable_contains_non_unicode_bytes(
) {
let app_dir = tempdir().unwrap();
let mut env = Env::new();
env.insert("SBT_OPTS", invalid_unicode_os_string());
set_sbt_version(&app_dir, "1.8.2");
let err = create_build_config(app_dir.path(), &env).unwrap_err();
assert_err!(err, ScalaBuildpackError::CouldNotConvertEnvironmentValueIntoString(name, _) if name == "SBT_OPTS");
}
}
Loading

0 comments on commit 94c9cef

Please sign in to comment.