Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2024-02-15 #715

Merged
merged 8 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ This buildpack provides the [Adoptium](https://adoptium.net/) JDK and JRE.

### Java Version

The buildpack will automatically determine the Java version to use based on the runtime version of the app being deployed. The default Java version is 8. For Mendix 8 and above, the default Java version is 11.
The buildpack will automatically determine the Java version from metadata(it will have JavaVersion as json attribute). The default Java version is 8. For Mendix 8 and above, the default Java version is 11.
Metadata JavaVersion attribute will have these values "11", "17" or in the future "21".

We do not recommend overriding the Java version for the buildpack. However, for cases where this is required, the `JAVA_VERSION` variable can be used to override the version number.

Expand Down
20 changes: 15 additions & 5 deletions buildpack/core/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@

import certifi
from buildpack import util
from buildpack.core import runtime
from lib.m2ee.version import MXVersion
from lib.m2ee.util import strtobool

BASE_PATH = os.getcwd()

JAVA_VERSION_OVERRIDE_KEY = "JAVA_VERSION"
DEFAULT_GC_COLLECTOR = "Serial"
SUPPORTED_GC_COLLECTORS = ["Serial", "G1"]


def get_java_major_version(runtime_version):
def get_java_major_version(runtime_version, build_path=BASE_PATH):
result = 8
if os.getenv(JAVA_VERSION_OVERRIDE_KEY):
return _get_major_version(os.getenv(JAVA_VERSION_OVERRIDE_KEY))
if runtime_version >= MXVersion("8.0.0"):
result = 11
return _get_major_version(result)

result = runtime.get_metadata_value("JavaVersion", build_path)
if result is None:
result = 11 # default version for mx 8 or above
elif 17 == result:
result = 17
elif 21 == result:
result = 21
else:
result = 11
major_version = _get_major_version(result)
logging.info("get_java_major_version : major_version - %s", str(major_version))
return major_version

def _get_major_version(version):
# Java 8
Expand Down
12 changes: 4 additions & 8 deletions buildpack/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ def is_version_maintained(version):
return True
if version.major == 8 and version.minor == 18:
return True
if version.major == 9 and version.minor == 6:
return True
if version.major == 9 and version.minor == 12:
return True
if version.major == 9 and version.minor == 18:
return True
if version.major == 9 and version.minor == 24:
return True
if version.major == 10 and version.minor == 6:
return True
return False


Expand Down Expand Up @@ -104,7 +100,7 @@ def get_metadata_value(key, build_path=BASE_PATH):
with open(file_name) as file_handle:
data = json.loads(file_handle.read())
return data[key]
except IOError:
except (IOError, KeyError):
return None


Expand All @@ -113,7 +109,7 @@ def get_runtime_version(build_path=BASE_PATH):
if result is None:
logging.debug(
"Cannot retrieve runtime version %s from metadata file, "
"falling back to project file",
"falling back to project file ",
result,
)
mpr = util.get_mpr_file_from_dir(build_path)
Expand Down
2 changes: 1 addition & 1 deletion buildpack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def cleanup_dependency_cache(cached_dir, dependency_list):
)

runtime_version = runtime.get_runtime_version(BUILD_DIR)
JAVA_VERSION = java.get_java_major_version(runtime_version)
JAVA_VERSION = java.get_java_major_version(runtime_version, BUILD_DIR)

try:
preflight_check(runtime_version)
Expand Down
2 changes: 2 additions & 0 deletions dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ dependencies:
version:
- "8": 8u392
- "11": 11.0.21
- "17": 17.0.9
- "21": 21.0.2
logs:
mendix-logfilter:
artifact: logs/mendix-logfilter-{{version}}.tar.gz
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def test_mx8_not_maintained(self):
assert not runtime.is_version_maintained(MXVersion("8.17"))

def test_mx9_maintained(self):
assert runtime.is_version_maintained(MXVersion("9.6.9"))
assert runtime.is_version_maintained(MXVersion("9.12.1"))
assert runtime.is_version_maintained(MXVersion("9.18.3"))
assert runtime.is_version_maintained(MXVersion("9.24.0"))

def test_mx9_not_maintained(self):
assert not runtime.is_version_maintained(MXVersion("9.16"))
assert not runtime.is_version_maintained(MXVersion("9.18"))
assert not runtime.is_version_maintained(MXVersion("9.6.9"))
assert not runtime.is_version_maintained(MXVersion("9.12.1"))

def test_mx10_maintained(self):
assert runtime.is_version_maintained(MXVersion("10.6.1"))

def test_mx10_not_maintained(self):
assert not runtime.is_version_maintained(MXVersion("10.5.1"))
Loading