This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 3aa5a96dd fixes(#5439): Build should enforce a required jdk version
3aa5a96dd is described below

commit 3aa5a96dd80b092a2319bf38247f76f0cdae9596
Author: Thomas Diesler <tdies...@redhat.com>
AuthorDate: Tue Apr 30 12:56:23 2024 +0200

    fixes(#5439): Build should enforce a required jdk version
---
 cmd/util/check_jdk_version/main.go                 | 49 ++++++++++++++++++++++
 .../ROOT/pages/contributing/developers.adoc        |  2 +
 script/Makefile                                    |  5 ++-
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/cmd/util/check_jdk_version/main.go 
b/cmd/util/check_jdk_version/main.go
new file mode 100644
index 000000000..2b6061027
--- /dev/null
+++ b/cmd/util/check_jdk_version/main.go
@@ -0,0 +1,49 @@
+package main
+
+import (
+       "fmt"
+       "os/exec"
+       "regexp"
+       "strconv"
+       "strings"
+)
+
+func main() {
+
+       cmd := exec.Command("mvn", "-version")
+       output, err := cmd.CombinedOutput()
+       if err != nil {
+               _ = fmt.Sprintf("Error: %v\n", err)
+               return
+       }
+
+       for _, ln := range strings.Split(string(output), "\n") {
+               switch {
+               case strings.Contains(ln, "Apache Maven"):
+                       fmt.Printf("%v\n", ln)
+                       versionRegex := regexp.MustCompile(`Apache Maven 
([1-9]+)(\.([0-9]+)){2,3}`)
+                       matches := versionRegex.FindStringSubmatch(ln)
+                       if len(matches) < 2 {
+                               _ = fmt.Sprintf("Unable to determine Apache 
Maven version: %s\n", ln)
+                               return
+                       }
+               case strings.Contains(ln, "Java version"):
+                       fmt.Printf("%v\n", ln)
+                       versionRegex := regexp.MustCompile(`version: 
([1-9]+)(\.([0-9]+)){2,3}`)
+                       matches := versionRegex.FindStringSubmatch(ln)
+                       if len(matches) < 2 {
+                               _ = fmt.Sprintf("Unable to determine Java 
version: %s\n", ln)
+                               return
+                       }
+                       majorVersion, err := strconv.Atoi(matches[1])
+                       if err != nil {
+                               _ = fmt.Sprintf("Error parsing Java version: %s 
- %v\n", ln, err)
+                               return
+                       }
+                       if majorVersion < 17 {
+                               _ = fmt.Sprintf("JDK version is below 17: 
%s\n", ln)
+                               return
+                       }
+               }
+       }
+}
diff --git a/docs/modules/ROOT/pages/contributing/developers.adoc 
b/docs/modules/ROOT/pages/contributing/developers.adoc
index f1a772cae..567e8640e 100644
--- a/docs/modules/ROOT/pages/contributing/developers.adoc
+++ b/docs/modules/ROOT/pages/contributing/developers.adoc
@@ -24,6 +24,8 @@ In order to build the project, you need to comply with the 
following requirement
 
 * **Go version 1.16+**: needed to compile and test the project. Refer to the 
https://golang.org/[Go website] for the installation.
 * **GNU Make**: used to define composite build actions. This should be already 
installed or available as a package if you have a good OS 
(https://www.gnu.org/software/make/).
+* **JDK version 17+**: the build requires JDK version 17 or above. This 
corresponds to the JDK version of the integration base image.
+* **Maven version 3.8+**: the build requires Maven 3.8 or above. This 
corresponds to the version defined in the `build/Dockerfile`.
 * **MinGW**: needed to compile the project on Windows. Refer to the 
https://www.mingw-w64.org/[MinGW website] for the installation.
 * **Windows Subsystem for Linux (WSL)**: for running Linux binary executables 
natively on Windows. Refer to 
https://docs.microsoft.com/en-us/windows/wsl/install[WSL Website] for 
installation. Alternatively, you can use https://www.cygwin.com/[Cygwin] or 
https://www.educative.io/edpresso/how-to-install-git-bash-in-windows[Git Bash].
 
diff --git a/script/Makefile b/script/Makefile
index 8d4cdd499..6547765f5 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -230,7 +230,10 @@ build-platform: build build-kamel-platform
 
 ci-build: clean codegen set-version check-licenses dir-licenses build-kamel 
cross-compile
 
-do-build: gotestfmt-install
+check_jdk_version:
+       @go run ./cmd/util/check_jdk_version
+
+do-build: gotestfmt-install check_jdk_version
 ifeq ($(DO_TEST_PREBUILD),true)
 TEST_PREBUILD = build
 else

Reply via email to