Skip to content

Commit

Permalink
Release 2024-02-15 (#715)
Browse files Browse the repository at this point in the history
* Updated the maintained versions to match the documentation

* Update test_deprecations.py

updated the versions in the test

* Update runtime.py

added version 7 again for extended support

* Update test_deprecations.py

added some test cases

* Added support for Java 17 and 21 (#713)

* added java support for 17 and 21

* added more logs to debug issue

* added exception handling if key is not found

* removed extra log line

* Added support for java 11

* Updated doc

* Fix: argument of type 'NoneType' is not iterable

* fix if java version  is different than 17 or 21

* added log line

* added log line for debugging purpose

* added log line for debugging purpose

* added log line for debugging purpose - 1

* added log line for debugging purpose

* added log line for debug

* added log line for debug - 1

* added log line for debug - 1

* added log line for debug - 1

* added log line for debug - 1

* added log line for debug - 1

* pass build path

* removed extra logs

* java version is an integer not string

---------

Co-authored-by: Yornik Heyl <yornik@yornik.nl>
Co-authored-by: Joey den Broeder <34917186+jeohist@users.noreply.github.com>
Co-authored-by: Yornik Heyl <yornik.heyl@mendix.com>
Co-authored-by: mukund-padale <75060177+mukund-padale@users.noreply.github.com>
  • Loading branch information
5 people authored Feb 15, 2024
1 parent b150f95 commit 10dd1ba
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
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"))

0 comments on commit 10dd1ba

Please sign in to comment.