From 274a63aa14543ae3561eb214395ccd0dee7136fb Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Fri, 9 May 2025 16:39:31 +0200 Subject: [PATCH] pommer initial --- .idea/inspectionProfiles/Project_Default.xml | 16 +++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/material_theme_project_new.xml | 10 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/pommer.iml | 14 +++ .idea/vcs.xml | 6 + .idea/workspace.xml | 72 ++++++++++++ pommer.py | 103 ++++++++++++++++++ requirements.txt | 3 + 10 files changed, 244 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/material_theme_project_new.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pommer.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 pommer.py create mode 100644 requirements.txt diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..40903d6 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..0f6f4b2 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c2e9843 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0baa1d9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pommer.iml b/.idea/pommer.iml new file mode 100644 index 0000000..439ff25 --- /dev/null +++ b/.idea/pommer.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4e114e2 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1746800157319 + + + + \ No newline at end of file diff --git a/pommer.py b/pommer.py new file mode 100644 index 0000000..64b71db --- /dev/null +++ b/pommer.py @@ -0,0 +1,103 @@ +import xml.etree.ElementTree as ET +import os +import subprocess +import sys +import argparse +from pathlib import Path + +def install_maven(maven_version="3.9.6"): + """Install Maven dynamically if not found""" + try: + subprocess.run(["mvn", "--version"], check=True, capture_output=True) + print("✓ Maven already installed") + except (subprocess.CalledProcessError, FileNotFoundError): + print("⏳ Installing Maven...") + maven_url = f"https://archive.apache.org/dist/maven/maven-3/{maven_version}/binaries/apache-maven-{maven_version}-bin.tar.gz" + install_cmds = [ + f"curl -sL {maven_url} | tar xz -C /opt", + f"ln -s /opt/apache-maven-{maven_version}/bin/mvn /usr/local/bin/mvn", + "rm -rf /tmp/*" + ] + for cmd in install_cmds: + subprocess.run(cmd, shell=True, check=True) + print("✓ Maven installed") + +def install_java(java_version="21"): + """Install JDK dynamically if not found""" + try: + jdk_check = subprocess.run(["java", "--version"], capture_output=True, text=True) + if f" {java_version}" in jdk_check.stdout: + print(f"✓ JDK {java_version} already installed") + return + except FileNotFoundError: + pass + + print(f"⏳ Installing JDK {java_version}...") + subprocess.run([ + "apt-get", "update", "-qq" + ], check=True) + + subprocess.run([ + "apt-get", "install", "-qq", "-y", + f"temurin-{java_version}-jdk" + ], check=True) + print(f"✓ JDK {java_version} installed") + +def analyze_pom(pom_path): + """Detect required tools from pom.xml""" + tree = ET.parse(pom_path) + root = tree.getroot() + ns = {'mvn': 'http://maven.apache.org/POM/4.0.0'} + + requirements = { + 'java_version': root.findtext('mvn:properties/mvn:java.version', namespaces=ns, default="21"), + 'kotlin_version': root.findtext('mvn:properties/mvn:kotlin.version', namespaces=ns), + 'needs_docker': False + } + + # Check for docker-maven-plugin + for plugin in root.findall('.//mvn:plugin', namespaces=ns): + if 'docker' in plugin.findtext('mvn:artifactId', namespaces=ns, default=""): + requirements['needs_docker'] = True + break + + return requirements + +def optimize_build(pom_path): + """Apply build optimizations based on project type""" + optimizations = [ + "-T 1C", # Parallel builds (1 thread per core) + "-Ddependency.cache=true", + "-Dmaven.artifact.threads=8" + ] + + if "kotlin" in pom_path.read_text(): + optimizations.append("-Dkotlin.compiler.incremental=true") + + return " ".join(optimizations) + +def main(): + parser = argparse.ArgumentParser(description='Smart Maven project builder') + parser.add_argument('pom_path', type=str, help='Path to pom.xml') + parser.add_argument('--skip-install', action='store_true', help='Skip dependency installation') + args = parser.parse_args() + + pom_path = Path(args.pom_path) + requirements = analyze_pom(pom_path) + + if not args.skip_install: + install_java(requirements['java_version']) + install_maven() + + build_cmd = f"mvn -B {optimize_build(pom_path)} clean package" + print(f"🚀 Build command: {build_cmd}") + + try: + subprocess.run(build_cmd, shell=True, check=True) + print("✅ Build succeeded!") + except subprocess.CalledProcessError as e: + print(f"❌ Build failed: {e}") + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d1abf50 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pathlib +argparse +pycopy-xml.etree.elementtree