pommer initial

This commit is contained in:
rattatwinko
2025-05-09 16:39:31 +02:00
commit 274a63aa14
10 changed files with 244 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="NonAsciiCharacters" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyBroadExceptionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N806" />
<option value="N803" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyTypeCheckerInspection" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
.idea/material_theme_project_new.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="2eeb01f7:196b566bded:-7ff2" />
</MTProjectMetadataState>
</option>
</component>
</project>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9 (pommer)" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pommer.iml" filepath="$PROJECT_DIR$/.idea/pommer.iml" />
</modules>
</component>
</project>

14
.idea/pommer.iml generated Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (pommer)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">
<option name="removeUnused" value="true" />
<option name="modifyBaseFiles" value="true" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

72
.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="e0212954-3a5f-444b-b399-906a623c79bb" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/pommer.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pommer.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 7
}]]></component>
<component name="ProjectId" id="2wrWQd8M0NI8PKga2NQkPeHjx8C" />
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "master"
}
}]]></component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-python-sdk-2ee2454479a3-9cdd278e9d02-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-251.25410.122" />
</set>
</attachedChunks>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e0212954-3a5f-444b-b399-906a623c79bb" name="Changes" comment="" />
<created>1746800157319</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1746800157319</updated>
</task>
<servers />
</component>
</project>

103
pommer.py Normal file
View File

@@ -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()

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
pathlib
argparse
pycopy-xml.etree.elementtree