67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def run(command: list[str], cwd: Path | None = None) -> None:
|
|
subprocess.run(command, cwd=cwd, check=True)
|
|
|
|
|
|
def install_private_artifacts(maven_private_root: Path, maven_repo_local: str) -> int:
|
|
if not maven_private_root.exists():
|
|
raise SystemExit(f"missing private maven directory: {maven_private_root}")
|
|
|
|
install_count = 0
|
|
for version_dir in sorted(path for path in maven_private_root.glob("*/*") if path.is_dir()):
|
|
pom_candidates = sorted(version_dir.glob("*.pom"))
|
|
jar_candidates = sorted(
|
|
path
|
|
for path in version_dir.glob("*.jar")
|
|
if path.is_file() and not path.name.startswith("original-")
|
|
)
|
|
if not pom_candidates:
|
|
continue
|
|
|
|
pom_file = pom_candidates[0]
|
|
command = [
|
|
"mvn",
|
|
f"-Dmaven.repo.local={maven_repo_local}",
|
|
"install:install-file",
|
|
f"-DpomFile={pom_file}",
|
|
"-DgeneratePom=false",
|
|
]
|
|
|
|
if jar_candidates:
|
|
jar_file = jar_candidates[0]
|
|
print(f"install private maven artifact: {jar_file.name}", flush=True)
|
|
command.append(f"-Dfile={jar_file}")
|
|
else:
|
|
print(f"install private maven pom: {pom_file.name}", flush=True)
|
|
command.extend(
|
|
[
|
|
f"-Dfile={pom_file}",
|
|
"-Dpackaging=pom",
|
|
]
|
|
)
|
|
|
|
run(command)
|
|
install_count += 1
|
|
return install_count
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--source-root", type=Path, required=True)
|
|
parser.add_argument("--maven-repo-local", required=True)
|
|
args = parser.parse_args()
|
|
installed = install_private_artifacts(args.source_root, args.maven_repo_local)
|
|
print(f"installed private artifacts: {installed}", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|