54 lines
2.6 KiB
Python
54 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Register the six supplied legacy JARs in a dedicated Maven repository."""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
|
|
os.umask(0o077)
|
|
run = Path(sys.argv[1]).resolve()
|
|
source = run / 'source'
|
|
repo = Path.home() / '.local/share/syly2-build/m2'
|
|
base = Path.home() / '.local/opt/syly2-build'
|
|
env = dict(os.environ, JAVA_HOME=str(base / 'corretto-8.512.09.1'))
|
|
env['PATH'] = env['JAVA_HOME'] + '/bin:' + env['PATH']
|
|
mvn = base / 'apache-maven-3.9.11/bin/mvn'
|
|
artifacts = [
|
|
('com.oracle', 'ojdbc14', '10.2.0.4.0', 'jar/ojdbc14/ojdbc14/10.2.0.4.0/ojdbc14-10.2.0.4.0.jar'),
|
|
*[('com.ckfinder', name, '2.4', f'jar/ckfinder/ckfinder/{name}/2.4/{name}-2.4.jar') for name in [
|
|
'CKFinder-updateByAlexander', 'CKFinderPlugin-FileEditor',
|
|
'CKFinderPlugin-ImageResize', 'CKFinderPlugin-Watermark',
|
|
]],
|
|
('com.artofsolving', 'jodconverter', '3.0-beta-4', 'src/main/webapp/WEB-INF/lib/jodconverter-3.0-beta-4.jar'),
|
|
]
|
|
evidence = []
|
|
poms = run / 'artifacts/local-poms'
|
|
poms.mkdir(exist_ok=True)
|
|
for group, artifact, version, relative in artifacts:
|
|
jar = source / relative
|
|
original_pom = jar.with_suffix('.pom')
|
|
if original_pom.is_file():
|
|
pom = original_pom
|
|
else:
|
|
project = ET.Element('project', xmlns='http://maven.apache.org/POM/4.0.0')
|
|
for tag, text in [('modelVersion', '4.0.0'), ('groupId', group), ('artifactId', artifact), ('version', version), ('packaging', 'jar')]:
|
|
ET.SubElement(project, tag).text = text
|
|
pom = poms / f'{artifact}-{version}.pom'
|
|
ET.ElementTree(project).write(pom, encoding='utf-8', xml_declaration=True)
|
|
log = run / 'logs' / f'install-{artifact}.log'
|
|
with log.open('w') as output:
|
|
result = subprocess.run([
|
|
str(mvn), '-B', '-ntp', f'-Dmaven.repo.local={repo}',
|
|
'org.apache.maven.plugins:maven-install-plugin:3.1.4:install-file',
|
|
f'-Dfile={jar}', f'-DpomFile={pom}',
|
|
f'-DgroupId={group}', f'-DartifactId={artifact}', f'-Dversion={version}', '-Dpackaging=jar',
|
|
], cwd=run, env=env, stdout=output, stderr=subprocess.STDOUT, timeout=300)
|
|
if result.returncode:
|
|
raise RuntimeError(f'Installation failed: {artifact}; see {log}')
|
|
evidence.append({'coordinates': f'{group}:{artifact}:{version}', 'source': relative, 'sha256': hashlib.sha256(jar.read_bytes()).hexdigest()})
|
|
print('Installed', evidence[-1]['coordinates'], flush=True)
|
|
(run / 'artifacts/private-libs.json').write_text(json.dumps(evidence, indent=2) + '\n')
|