|
17 | 17 | from typing import Any, Dict, List, Union, Tuple, Optional
|
18 | 18 | from urllib import request
|
19 | 19 |
|
20 |
| -SUB_VERSION = 1 |
21 |
| -RELEASE_NOTES = """- Fixed the library version in the pom #3 (thanks to @gavlyukovskiy for spotting this)""" |
| 20 | +SUB_VERSION = 2 |
| 21 | +RELEASE_NOTES = """- Fixed the library version in the pom #3 again (thanks to @gavlyukovskiy, @dpsoft and @krzysztofslusarski for spotting the bug)""" |
22 | 22 |
|
23 | 23 | HELP = """
|
24 | 24 | Usage:
|
|
47 | 47 |
|
48 | 48 | def prepare_poms(release: str, platform: str, snapshot: bool = True) -> Tuple[str, str]:
|
49 | 49 | """ Prepare the POMs for the given release and platform """
|
50 |
| - folder = f"{CACHE_DIR}/pom-{release}-{platform}" |
| 50 | + folder = CURRENT_DIR |
51 | 51 | os.makedirs(folder, exist_ok=True)
|
52 |
| - for pom in ["pom.xml", "pom_all.xml"]: |
53 |
| - pom_file = f"{CURRENT_DIR}/{pom}" |
54 |
| - dest_pom = f"{folder}/{pom}" |
| 52 | + suffix = f"-{release}-{platform}{'-SNAPSHOT' if snapshot else ''}" |
| 53 | + for pom in ["pom", "pom_all"]: |
| 54 | + pom_file = f"{CURRENT_DIR}/{pom}.xml" |
| 55 | + dest_pom = f"{folder}/{pom}{suffix}.xml" |
55 | 56 | with open(pom_file) as f:
|
56 | 57 | pom_content = f.read()
|
57 |
| - suffix = "-SNAPSHOT" if snapshot else "" |
58 |
| - pom_content = re.sub(r"<version>.*</version>", f"<version>{release}-{SUB_VERSION}-{platform}{suffix}</version>", pom_content, count = 1) |
| 58 | + p_suffix = "-SNAPSHOT" if snapshot else "" |
| 59 | + pom_content = re.sub(r"<version>.*</version>", f"<version>{release}-{SUB_VERSION}-{platform}{p_suffix}</version>", pom_content, count = 1) |
59 | 60 | pom_content = re.sub(r"<project.vversion>.*</project.vversion>", f"<project.vversion>{release}</project.vversion>", pom_content, count = 1)
|
60 | 61 | pom_content = re.sub(r"<project.subversion>.*</project.subversion>", f"<project.subversion>{SUB_VERSION}</project.subversion>", pom_content, count = 1)
|
61 | 62 | pom_content = re.sub(r"<project.platform>.*</project.platform>", f"<project.platform>{platform}</project.platform>", pom_content, count = 1)
|
62 |
| - pom_content = re.sub(r"<project.suffix>.*</project.suffix>", f"<project.suffix>{suffix}</project.suffix>", pom_content, count = 1) |
63 |
| - pom_content = pom_content.replace("${basedir}", "${basedir}/../..") |
| 63 | + pom_content = re.sub(r"<project.suffix>.*</project.suffix>", f"<project.suffix>{p_suffix}</project.suffix>", pom_content, count = 1) |
64 | 64 | with open(dest_pom, "w") as f2:
|
65 | 65 | f2.write(pom_content)
|
66 |
| - return f"{folder}/pom.xml", f"{folder}/pom_all.xml" |
| 66 | + return f"{folder}/pom{suffix}.xml", f"{folder}/pom_all{suffix}.xml" |
67 | 67 |
|
68 | 68 |
|
| 69 | +class PreparedPOMs: |
| 70 | + |
| 71 | + def __init__(self, release: str, platform: str, snapshot: bool = True): |
| 72 | + self.release = release |
| 73 | + self.platform = platform |
| 74 | + self.snapshot = snapshot |
| 75 | + |
| 76 | + def __enter__(self): |
| 77 | + self.pom, self.pom_all = prepare_poms(self.release, self.platform, self.snapshot) |
| 78 | + return self |
| 79 | + |
| 80 | + def __exit__(self, *args): |
| 81 | + os.remove(self.pom) |
| 82 | + os.remove(self.pom_all) |
| 83 | + |
69 | 84 |
|
70 | 85 | def execute(args: Union[List[str], str]):
|
71 | 86 | subprocess.check_call(args, cwd=CURRENT_DIR, shell=isinstance(args, str), stdout=subprocess.DEVNULL)
|
@@ -172,11 +187,11 @@ def build_release(release: str):
|
172 | 187 | release_file = f"ap-loader-{release}-{SUB_VERSION}-{platform}-full.jar"
|
173 | 188 | dest_release_file = f"{release_folder}/ap-loader-{release}-{SUB_VERSION}-{platform}.jar"
|
174 | 189 | print(f"Build release for {platform}")
|
175 |
| - execute(f"mvn -Dproject.vversion={release} -Dproject.subrelease={SUB_VERSION} -Dproject.platform={platform} package assembly:single") |
| 190 | + execute(f"mvn -Dproject.vversion={release} -Dproject.subversion={SUB_VERSION} -Dproject.platform={platform} package assembly:single") |
176 | 191 | shutil.copy(f"{CURRENT_DIR}/target/{release_file}", dest_release_file)
|
177 | 192 | all_target = release_target_file(release, "all")
|
178 | 193 | print("Build release for all")
|
179 |
| - execute(f"mvn -Dproject.vversion={release} -Dproject.subrelease={SUB_VERSION} -Dproject.platform=all package assembly:single -f pom_all.xml") |
| 194 | + execute(f"mvn -Dproject.vversion={release} -Dproject.subversion={SUB_VERSION} -Dproject.platform=all package assembly:single -f pom_all.xml") |
180 | 195 | shutil.copy(f"{CURRENT_DIR}/target/ap-loader-{release}-{SUB_VERSION}-all-full.jar", all_target)
|
181 | 196 |
|
182 | 197 |
|
@@ -293,17 +308,18 @@ def test_release(release: str):
|
293 | 308 |
|
294 | 309 | def deploy_maven_platform(release: str, platform: str, snapshot: bool):
|
295 | 310 | print(f"Deploy {release}-{SUB_VERSION} for {platform} to maven")
|
296 |
| - poms = prepare_poms(release, platform, snapshot) |
297 |
| - pom = poms[1] if platform == "all" else poms[0] |
298 |
| - cmd = f"mvn -Dproject.vversion={release} -Dproject.subrelease={SUB_VERSION} -Dproject.platform={platform} " \ |
299 |
| - f"-Dproject.suffix='{'-SNAPSHOT' if snapshot else ''}' -f {pom} clean deploy" |
300 |
| - try: |
301 |
| - subprocess.check_call(cmd, shell=True, cwd=CURRENT_DIR, stdout=subprocess.DEVNULL, |
302 |
| - stderr=subprocess.DEVNULL) |
303 |
| - except subprocess.CalledProcessError: |
304 |
| - os.system( |
305 |
| - f"cd {CURRENT_DIR}; {cmd}") |
306 |
| - raise |
| 311 | + with PreparedPOMs(release, platform, snapshot) as poms: |
| 312 | + pom = poms.pom_all if platform == "all" else poms.pom |
| 313 | + cmd = f"mvn -Dproject.vversion={release} -Dproject.subversion={SUB_VERSION} -Dproject.platform={platform} " \ |
| 314 | + f"-Dproject.suffix='{'-SNAPSHOT' if snapshot else ''}' -f {pom} clean deploy" |
| 315 | + try: |
| 316 | + subprocess.check_call(cmd, shell=True, cwd=CURRENT_DIR, stdout=subprocess.DEVNULL, |
| 317 | + stderr=subprocess.DEVNULL) |
| 318 | + #os.system(f"cd {CURRENT_DIR}; {cmd}") |
| 319 | + except subprocess.CalledProcessError: |
| 320 | + os.system( |
| 321 | + f"cd {CURRENT_DIR}; {cmd}") |
| 322 | + raise |
307 | 323 |
|
308 | 324 |
|
309 | 325 | def deploy_maven(release: str, snapshot: bool = True):
|
|
0 commit comments