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">
|
<component name="MaterialThemeProjectNewConfig">
|
||||||
<option name="metadata">
|
<option name="metadata">
|
||||||
<MTProjectMetadataState>
|
<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>
|
</MTProjectMetadataState>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
52
.idea/workspace.xml
generated
52
.idea/workspace.xml
generated
@@ -4,17 +4,10 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e0212954-3a5f-444b-b399-906a623c79bb" name="Changes" comment="">
|
<list default="true" id="e0212954-3a5f-444b-b399-906a623c79bb" name="Changes" comment="pommer initial">
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pommer.py" beforeDir="false" afterPath="$PROJECT_DIR$/pommer.py" 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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -31,9 +24,9 @@
|
|||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo"><![CDATA[{
|
<component name="ProjectColorInfo">{
|
||||||
"associatedIndex": 7
|
"associatedIndex": 7
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="ProjectId" id="2wrWQd8M0NI8PKga2NQkPeHjx8C" />
|
<component name="ProjectId" id="2wrWQd8M0NI8PKga2NQkPeHjx8C" />
|
||||||
<component name="ProjectLevelVcsManager">
|
<component name="ProjectLevelVcsManager">
|
||||||
<ConfirmationsSetting value="2" id="Add" />
|
<ConfirmationsSetting value="2" id="Add" />
|
||||||
@@ -42,16 +35,16 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"git-widget-placeholder": "master"
|
"git-widget-placeholder": "master"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
<set>
|
<set>
|
||||||
@@ -67,6 +60,19 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1746800157319</updated>
|
<updated>1746800157319</updated>
|
||||||
</task>
|
</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 />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="pommer initial" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="pommer initial" />
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
131
pommer.py
131
pommer.py
@@ -1,47 +1,7 @@
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import argparse
|
||||||
def install_maven(maven_version="3.9.6"):
|
import os
|
||||||
"""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):
|
def analyze_pom(pom_path):
|
||||||
"""Detect required tools from pom.xml"""
|
"""Detect required tools from pom.xml"""
|
||||||
@@ -63,41 +23,76 @@ def analyze_pom(pom_path):
|
|||||||
|
|
||||||
return requirements
|
return requirements
|
||||||
|
|
||||||
def optimize_build(pom_path):
|
def generate_gitea_actions(pom_path, requirements):
|
||||||
"""Apply build optimizations based on project type"""
|
"""Generate Gitea Actions workflow file"""
|
||||||
optimizations = [
|
workflow_dir = Path(".gitea/workflows")
|
||||||
"-T 1C", # Parallel builds (1 thread per core)
|
workflow_dir.mkdir(parents=True, exist_ok=True)
|
||||||
"-Ddependency.cache=true",
|
|
||||||
"-Dmaven.artifact.threads=8"
|
|
||||||
]
|
|
||||||
|
|
||||||
if "kotlin" in pom_path.read_text():
|
workflow_file = workflow_dir / "build.yml"
|
||||||
optimizations.append("-Dkotlin.compiler.incremental=true")
|
|
||||||
|
|
||||||
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():
|
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('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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
pom_path = Path(args.pom_path)
|
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)
|
requirements = analyze_pom(pom_path)
|
||||||
|
generate_gitea_actions(pom_path, requirements)
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user