pommer new
This commit is contained in:
4
.idea/material_theme_project_new.xml
generated
4
.idea/material_theme_project_new.xml
generated
@@ -3,7 +3,9 @@
|
||||
<component name="MaterialThemeProjectNewConfig">
|
||||
<option name="metadata">
|
||||
<MTProjectMetadataState>
|
||||
<option name="userId" value="2eeb01f7:196b566bded:-7ff2" />
|
||||
<option name="migrated" value="true" />
|
||||
<option name="pristineConfig" value="false" />
|
||||
<option name="userId" value="-482e1190:19649c22859:-7ffe" />
|
||||
</MTProjectMetadataState>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
52
.idea/workspace.xml
generated
52
.idea/workspace.xml
generated
@@ -4,17 +4,10 @@
|
||||
<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 default="true" id="e0212954-3a5f-444b-b399-906a623c79bb" name="Changes" comment="pommer initial">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pommer.py" beforeDir="false" afterPath="$PROJECT_DIR$/pommer.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -31,9 +24,9 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 7
|
||||
}]]></component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 7
|
||||
}</component>
|
||||
<component name="ProjectId" id="2wrWQd8M0NI8PKga2NQkPeHjx8C" />
|
||||
<component name="ProjectLevelVcsManager">
|
||||
<ConfirmationsSetting value="2" id="Add" />
|
||||
@@ -42,16 +35,16 @@
|
||||
<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 name="PropertiesComponent">{
|
||||
"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>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
@@ -67,6 +60,19 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1746800157319</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="pommer initial">
|
||||
<option name="closed" value="true" />
|
||||
<created>1746801575112</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1746801575112</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="pommer initial" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="pommer initial" />
|
||||
</component>
|
||||
</project>
|
||||
131
pommer.py
131
pommer.py
@@ -1,47 +1,7 @@
|
||||
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")
|
||||
import argparse
|
||||
import os
|
||||
|
||||
def analyze_pom(pom_path):
|
||||
"""Detect required tools from pom.xml"""
|
||||
@@ -63,41 +23,76 @@ def analyze_pom(pom_path):
|
||||
|
||||
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"
|
||||
]
|
||||
def generate_gitea_actions(pom_path, requirements):
|
||||
"""Generate Gitea Actions workflow file"""
|
||||
workflow_dir = Path(".gitea/workflows")
|
||||
workflow_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if "kotlin" in pom_path.read_text():
|
||||
optimizations.append("-Dkotlin.compiler.incremental=true")
|
||||
workflow_file = workflow_dir / "build.yml"
|
||||
|
||||
return " ".join(optimizations)
|
||||
java_version = requirements['java_version']
|
||||
kotlin_version = requirements['kotlin_version']
|
||||
needs_docker = requirements['needs_docker']
|
||||
|
||||
# Base Maven command with optimizations
|
||||
maven_cmd = "mvn -B -T 1C -Ddependency.cache=true -Dmaven.artifact.threads=8"
|
||||
if kotlin_version:
|
||||
maven_cmd += " -Dkotlin.compiler.incremental=true"
|
||||
|
||||
content = f"""name: Java CI with Maven
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK {java_version}
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '{java_version}'
|
||||
distribution: 'temurin'
|
||||
cache: 'maven'
|
||||
|
||||
- name: Install Maven
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y maven
|
||||
mvn --version
|
||||
"""
|
||||
|
||||
if needs_docker:
|
||||
content += """
|
||||
- name: Set up Docker
|
||||
run: |
|
||||
sudo apt-get install -y docker.io
|
||||
sudo systemctl start docker
|
||||
"""
|
||||
|
||||
content += f"""
|
||||
- name: Build with Maven
|
||||
run: {maven_cmd} clean package
|
||||
"""
|
||||
|
||||
with open(workflow_file, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
print(f"✓ Generated Gitea Actions workflow at {workflow_file}")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Smart Maven project builder')
|
||||
parser = argparse.ArgumentParser(description='Generate Gitea Actions workflow for Maven project')
|
||||
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)
|
||||
if not pom_path.exists():
|
||||
print(f"❌ Error: {pom_path} does not exist")
|
||||
return
|
||||
|
||||
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)
|
||||
generate_gitea_actions(pom_path, requirements)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user