in eng/versioning/sync_versions.py [0:0]
def update_pom(package_versions: List[PackageVersion]):
versions = {package.package: package.version for package in package_versions}
pom_files = [
"customization-base/src/main/resources/pom.xml",
"core/packages/http-client-java/generator/http-client-generator-core/src/main/resources/pom.xml",
"pom.xml",
]
for folder in os.listdir(root_path):
if path.isdir(path.join(root_path, folder)) and path.isfile(path.join(root_path, folder, "pom.xml")):
pom_files.append(path.join(folder, "pom.xml"))
for folder in os.listdir(root_path):
if path.isdir(path.join(root_path, folder)) and path.isfile(path.join(root_path, folder, "pom.xml")):
pom_files.append(path.join(folder, "pom.xml"))
core_relative_path = "core/packages/http-client-java/generator"
core_path = path.join(root_path, core_relative_path)
for folder in os.listdir(core_path):
if path.isdir(path.join(core_path, folder)) and path.isfile(path.join(core_path, folder, "pom.xml")):
pom_files.append(path.join(core_relative_path, folder, "pom.xml"))
# POMs
for pom_file in pom_files:
with open(path.join(root_path, pom_file), encoding="utf-8") as f_in:
lines = f_in.readlines()
new_lines = []
package = None
for line in lines:
if is_xml_node(line, "groupId"):
package = Package(extract_xml_node_text(line), None)
elif is_xml_node(line, "artifactId"):
if package:
package = Package(package.group, extract_xml_node_text(line))
elif is_xml_node(line, "version"):
if package and package in versions:
line = replace_xml_node_text(line, versions[package])
else:
package = None
new_lines.append(line)
if not lines == new_lines:
with open(path.join(root_path, pom_file), "w", encoding="utf-8") as f_out:
f_out.write("".join(new_lines))
logging.info(f"update POM {pom_file}")
# packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java
project_file = "core/packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/projectmodel/Project.java"
with open(path.join(root_path, project_file)) as f_in:
lines = f_in.readlines()
new_lines = []
for line in lines:
match = re.match(r"( *[_A-Z]*\(\")(.*?)(\", \")(.*?)(\", \")(.*)(\"\)[,;]\n)", line)
if match:
package = Package(match.group(2), match.group(4))
if package in versions:
line = f"{match.group(1)}{match.group(2)}{match.group(3)}{match.group(4)}{match.group(5)}{versions[package]}{match.group(7)}"
new_lines.append(line)
if not lines == new_lines:
with open(path.join(root_path, project_file), "w", encoding="utf-8") as f_out:
f_out.write("".join(new_lines))
logging.info(f"update Project.java {project_file}")
# protocol-sdk-integration-tests/eng/versioning/version_client.txt
version_client_file = "protocol-sdk-integration-tests/eng/versioning/version_client.txt"
with open(path.join(root_path, version_client_file)) as f_in:
lines = f_in.readlines()
new_lines = []
for line in lines:
match = re.match(r"(.*?):(.*?);(.*?);(.*?)\n", line)
if match:
package = Package(match.group(1), match.group(2))
if package in versions:
version = versions[package]
line = f"{match.group(1)}:{match.group(2)};{version};{version}\n"
new_lines.append(line)
if not lines == new_lines:
with open(path.join(root_path, version_client_file), "w", encoding="utf-8") as f_out:
f_out.write("".join(new_lines))
logging.info(f"update version_client.txt {version_client_file}")