From 16f821304427692b6f691a188fb73a3d00bf3dec Mon Sep 17 00:00:00 2001 From: rohansen856 Date: Mon, 26 Jan 2026 03:25:49 +0530 Subject: [PATCH 1/4] feat: added template for java binary builder Signed-off-by: rohansen856 --- builders/binary/java_binary_builder.py | 108 +++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 builders/binary/java_binary_builder.py diff --git a/builders/binary/java_binary_builder.py b/builders/binary/java_binary_builder.py new file mode 100644 index 0000000..a999916 --- /dev/null +++ b/builders/binary/java_binary_builder.py @@ -0,0 +1,108 @@ +# Copyright Contributors to the Mainframe Software Hub for Linux Project. +# SPDX-License-Identifier: Apache-2.0 + +import os +import subprocess +from monitoring.logger import Logger +from builders.plugins.plugin_interface import ArtifactBuilder + + +class JavaBinaryBuilder(ArtifactBuilder): + def __init__(self): + self.logger = Logger() + + def build(self, repo_path: str, repo_gh_name: str, artifact: dict) -> str: + repo_name = os.path.basename(repo_path) + version = artifact.get("version", "1.0") + + output_path = f"{repo_path}/build/{repo_gh_name}_{version}.jar" + + docker_image = artifact.get("docker_image", "maven:3.9-eclipse-temurin-17") + + try: + os.makedirs("build", exist_ok=True) + + self.logger.info(f"Building Java artifact for {repo_gh_name}") + + pom_path = os.path.join(repo_path, "pom.xml") + gradle_path = os.path.join(repo_path, "build.gradle") + gradle_kts_path = os.path.join(repo_path, "build.gradle.kts") + + is_maven = os.path.exists(pom_path) + is_gradle = os.path.exists(gradle_path) or os.path.exists(gradle_kts_path) + + if not is_maven and not is_gradle: + raise RuntimeError( + f"No supported Java build file found in {repo_path}. " + f"Expected pom.xml or build.gradle(.kts)." + ) + + if is_maven: + cmd = ["mvn", "-DskipTests", "clean", "package"] + + expected_build_dir = os.path.join(repo_path, "target") + + else: + cmd = ["gradle", "clean", "build", "-x", "test"] + + expected_build_dir = os.path.join(repo_path, "build", "libs") + + subprocess.run( + [ + "docker", "run", "--rm", + "-v", f"{repo_path}:{repo_path}", + "-v", f"{repo_path}:/app", + "-w", "/app", + docker_image, + ] + cmd, + check=True + ) + + jar_candidates = [] + if os.path.isdir(expected_build_dir): + for f in os.listdir(expected_build_dir): + if f.endswith(".jar"): + jar_candidates.append(os.path.join(expected_build_dir, f)) + + if not jar_candidates: + raise RuntimeError( + f"No JAR produced. Looked in: {expected_build_dir}. " + f"TODO: Confirm build output paths / packaging." + ) + + chosen_jar = jar_candidates[0] + + subprocess.run(["cp", chosen_jar, output_path], check=True) + + self.logger.info(f"Built Java artifact at {output_path}") + return output_path + + except subprocess.CalledProcessError as e: + self.logger.error(f"Failed to build Java artifact for {repo_name}: {str(e)}") + raise + + def publish(self, artifact_path: str, repo_gh_name: str, artifact: dict) -> None: + from lib.checksum import generate_checksum + + checksum = generate_checksum(artifact_path) + version = artifact.get("version", "1.0") + + self.logger.info(f"Publishing {artifact_path} with checksum {checksum} for {repo_gh_name}") + + try: + subprocess.run( + [ + "gh", "release", "create", f"v{version}", + "--title", f"Version {version}", + "--generate-notes", + artifact_path, + f"{artifact_path}.sha256", + ], + cwd=os.path.dirname(artifact_path), + check=True + ) + self.logger.info(f"Published {artifact_path} to GitHub Releases") + + except subprocess.CalledProcessError as e: + self.logger.error(f"Failed to publish {artifact_path}: {str(e)}") + raise From 21d58b9eb5ba79c0981fe9d0f937e99a77b2b36c Mon Sep 17 00:00:00 2001 From: rohansen856 Date: Tue, 27 Jan 2026 21:49:45 +0530 Subject: [PATCH 2/4] feat: updated codebase to add map for build systems Signed-off-by: rohansen856 --- builders/binary/java_binary_builder.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/builders/binary/java_binary_builder.py b/builders/binary/java_binary_builder.py index a999916..e5e627e 100644 --- a/builders/binary/java_binary_builder.py +++ b/builders/binary/java_binary_builder.py @@ -6,6 +6,28 @@ from monitoring.logger import Logger from builders.plugins.plugin_interface import ArtifactBuilder +BUILD_SYSTEMS = { + "maven": { + "files": ["pom.xml"], + "command": ["mvn", "-DskipTests", "clean", "package"], + "build_dir": "target", + "docker_image": "maven:3.9-eclipse-temurin-17", + }, + "gradle": { + "files": ["build.gradle", "build.gradle.kts"], + "command": ["gradle", "clean", "build", "-x", "test"], + "build_dir": os.path.join("build", "libs"), + "docker_image": "gradle:8.7-jdk17", + }, +} + + +def detect_build_system(repo_path: str): + for system, config in BUILD_SYSTEMS.items(): + for f in config["files"]: + if os.path.exists(os.path.join(repo_path, f)): + return system, config + return None, None class JavaBinaryBuilder(ArtifactBuilder): def __init__(self): From 68aff83ca92de975c40520600593c77146e1abd8 Mon Sep 17 00:00:00 2001 From: rohansen856 Date: Tue, 27 Jan 2026 21:51:50 +0530 Subject: [PATCH 3/4] refactor: updated build function according to reviews Signed-off-by: rohansen856 --- builders/binary/java_binary_builder.py | 95 +++++++------------------- 1 file changed, 25 insertions(+), 70 deletions(-) diff --git a/builders/binary/java_binary_builder.py b/builders/binary/java_binary_builder.py index e5e627e..2568b7d 100644 --- a/builders/binary/java_binary_builder.py +++ b/builders/binary/java_binary_builder.py @@ -21,7 +21,6 @@ }, } - def detect_build_system(repo_path: str): for system, config in BUILD_SYSTEMS.items(): for f in config["files"]: @@ -34,40 +33,25 @@ def __init__(self): self.logger = Logger() def build(self, repo_path: str, repo_gh_name: str, artifact: dict) -> str: - repo_name = os.path.basename(repo_path) version = artifact.get("version", "1.0") + output_dir = os.path.join(repo_path, "build") + output_path = os.path.join(output_dir, f"{repo_gh_name}_{version}_s390x.jar") - output_path = f"{repo_path}/build/{repo_gh_name}_{version}.jar" - - docker_image = artifact.get("docker_image", "maven:3.9-eclipse-temurin-17") - - try: - os.makedirs("build", exist_ok=True) - - self.logger.info(f"Building Java artifact for {repo_gh_name}") - - pom_path = os.path.join(repo_path, "pom.xml") - gradle_path = os.path.join(repo_path, "build.gradle") - gradle_kts_path = os.path.join(repo_path, "build.gradle.kts") - - is_maven = os.path.exists(pom_path) - is_gradle = os.path.exists(gradle_path) or os.path.exists(gradle_kts_path) + os.makedirs(output_dir, exist_ok=True) - if not is_maven and not is_gradle: - raise RuntimeError( - f"No supported Java build file found in {repo_path}. " - f"Expected pom.xml or build.gradle(.kts)." - ) - - if is_maven: - cmd = ["mvn", "-DskipTests", "clean", "package"] - - expected_build_dir = os.path.join(repo_path, "target") + system, config = detect_build_system(repo_path) + if not system: + raise RuntimeError( + f"No supported Java build file found in {repo_path}. " + f"Expected one of: {', '.join(sum([v['files'] for v in BUILD_SYSTEMS.values()], []))}" + ) - else: - cmd = ["gradle", "clean", "build", "-x", "test"] + docker_image = artifact.get("docker_image", config["docker_image"]) + cmd = config["command"] + build_dir = os.path.join(repo_path, config["build_dir"]) - expected_build_dir = os.path.join(repo_path, "build", "libs") + try: + self.logger.info(f"Building Java artifact using {system} for {repo_gh_name}") subprocess.run( [ @@ -80,51 +64,22 @@ def build(self, repo_path: str, repo_gh_name: str, artifact: dict) -> str: check=True ) - jar_candidates = [] - if os.path.isdir(expected_build_dir): - for f in os.listdir(expected_build_dir): - if f.endswith(".jar"): - jar_candidates.append(os.path.join(expected_build_dir, f)) - - if not jar_candidates: - raise RuntimeError( - f"No JAR produced. Looked in: {expected_build_dir}. " - f"TODO: Confirm build output paths / packaging." - ) + jars = [ + os.path.join(build_dir, f) + for f in os.listdir(build_dir) + if f.endswith(".jar") + and not f.endswith("-sources.jar") + and not f.endswith("-javadoc.jar") + ] - chosen_jar = jar_candidates[0] + if not jars: + raise RuntimeError(f"No runnable JAR found in {build_dir}") - subprocess.run(["cp", chosen_jar, output_path], check=True) + subprocess.run(["cp", jars[0], output_path], check=True) self.logger.info(f"Built Java artifact at {output_path}") return output_path except subprocess.CalledProcessError as e: - self.logger.error(f"Failed to build Java artifact for {repo_name}: {str(e)}") - raise - - def publish(self, artifact_path: str, repo_gh_name: str, artifact: dict) -> None: - from lib.checksum import generate_checksum - - checksum = generate_checksum(artifact_path) - version = artifact.get("version", "1.0") - - self.logger.info(f"Publishing {artifact_path} with checksum {checksum} for {repo_gh_name}") - - try: - subprocess.run( - [ - "gh", "release", "create", f"v{version}", - "--title", f"Version {version}", - "--generate-notes", - artifact_path, - f"{artifact_path}.sha256", - ], - cwd=os.path.dirname(artifact_path), - check=True - ) - self.logger.info(f"Published {artifact_path} to GitHub Releases") - - except subprocess.CalledProcessError as e: - self.logger.error(f"Failed to publish {artifact_path}: {str(e)}") + self.logger.error(f"Failed to build Java artifact for {repo_gh_name}: {str(e)}") raise From be27d5ec2db5065283ab40703d8d8729312503fc Mon Sep 17 00:00:00 2001 From: rohansen856 Date: Tue, 27 Jan 2026 22:13:20 +0530 Subject: [PATCH 4/4] chore: added publish method to jaava builder Signed-off-by: rohansen856 --- builders/binary/java_binary_builder.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/builders/binary/java_binary_builder.py b/builders/binary/java_binary_builder.py index 2568b7d..6d940c9 100644 --- a/builders/binary/java_binary_builder.py +++ b/builders/binary/java_binary_builder.py @@ -83,3 +83,32 @@ def build(self, repo_path: str, repo_gh_name: str, artifact: dict) -> str: except subprocess.CalledProcessError as e: self.logger.error(f"Failed to build Java artifact for {repo_gh_name}: {str(e)}") raise + + def publish(self, artifact_path: str, repo_gh_name: str, artifact: dict): + from lib.checksum import generate_checksum + + checksum = generate_checksum(artifact_path) + version = artifact.get("version", "1.0") + + self.logger.info( + f"Publishing {artifact_path} with checksum {checksum} for {repo_gh_name}" + ) + + try: + subprocess.run( + [ + "gh", "release", "create", + f"v{version}", + "--title", f"Version {version}", + "--generate-notes", + artifact_path, + f"{artifact_path}.sha256", + ], + cwd=os.path.dirname(artifact_path), + check=True + ) + self.logger.info(f"Published {artifact_path} to GitHub Releases") + + except subprocess.CalledProcessError as e: + self.logger.error(f"Failed to publish {artifact_path}: {str(e)}") + raise