Skip to content

Commit 8d103f2

Browse files
committed
impl: automate reporting removal, build verification, and dynamic parent versioning
1 parent 6ddf4df commit 8d103f2

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

monorepo-migration/migrate.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TARGET_DIR="$WORKING_DIR/$MONOREPO_NAME-target"
1919
# Get absolute path to the transformation script before any cd
2020
TRANSFORM_SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
2121
TRANSFORM_SCRIPT="$TRANSFORM_SCRIPT_DIR/transform_workflow.py"
22+
MODERNIZE_POM_SCRIPT="$TRANSFORM_SCRIPT_DIR/modernize_pom.py"
2223

2324
echo "Starting migration using git read-tree with isolated clones..."
2425

@@ -177,6 +178,19 @@ echo "Committing copyright header fixes..."
177178
git add "$SOURCE_REPO_NAME"
178179
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): update copyright headers to 2025 Google LLC"
179180

181+
# 7.9 Modernize root pom.xml
182+
echo "Modernizing root pom.xml..."
183+
PARENT_VERSION=$(grep -m 1 "<version>.*{x-version-update:google-cloud-java:current}" google-cloud-jar-parent/pom.xml | sed -E 's/.*<version>(.*)<\/version>.*/\1/')
184+
python3 "$MODERNIZE_POM_SCRIPT" "$SOURCE_REPO_NAME/pom.xml" "$PARENT_VERSION"
185+
186+
echo "Committing root pom.xml modernization..."
187+
git add "$SOURCE_REPO_NAME/pom.xml"
188+
git commit -n --no-gpg-sign -m "chore($SOURCE_REPO_NAME): modernize root pom.xml"
189+
190+
# 7.10 Verify compilation
191+
echo "Verifying compilation..."
192+
(cd "$SOURCE_REPO_NAME" && mvn compile -DskipTests -T 1C)
193+
180194
# 8. Cleanup
181195
echo "Cleaning up temporary source clone..."
182196
rm -rf "$SOURCE_DIR"
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import sys
2+
import re
3+
4+
def modernize_pom(file_path, parent_version):
5+
with open(file_path, 'r') as f:
6+
lines = f.readlines()
7+
8+
new_lines = []
9+
in_parent = False
10+
in_dep_mgmt = False
11+
in_dependencies = False
12+
in_dependency = False
13+
in_reporting = False
14+
current_dependency_lines = []
15+
has_x_version_update = False
16+
17+
for line in lines:
18+
# Parent section modernization
19+
if '<parent>' in line and not in_parent:
20+
in_parent = True
21+
indent = line[:line.find('<')]
22+
new_lines.append(f"{indent}<parent>\n")
23+
new_lines.append(f"{indent} <groupId>com.google.cloud</groupId>\n")
24+
new_lines.append(f"{indent} <artifactId>google-cloud-jar-parent</artifactId>\n")
25+
new_lines.append(f"{indent} <version>{parent_version}</version><!-- {{x-version-update:google-cloud-java:current}} -->\n")
26+
new_lines.append(f"{indent} <relativePath>../google-cloud-jar-parent/pom.xml</relativePath>\n")
27+
continue
28+
if '</parent>' in line and in_parent:
29+
in_parent = False
30+
new_lines.append(line)
31+
continue
32+
if in_parent:
33+
continue # skip original parent content
34+
35+
# Dependency Management pruning
36+
if '<dependencyManagement>' in line:
37+
in_dep_mgmt = True
38+
new_lines.append(line)
39+
continue
40+
if '</dependencyManagement>' in line:
41+
in_dep_mgmt = False
42+
new_lines.append(line)
43+
continue
44+
45+
if in_dep_mgmt:
46+
if '<dependencies>' in line:
47+
in_dependencies = True
48+
new_lines.append(line)
49+
continue
50+
if '</dependencies>' in line:
51+
in_dependencies = False
52+
new_lines.append(line)
53+
continue
54+
55+
if in_dependencies:
56+
if '<dependency>' in line:
57+
in_dependency = True
58+
current_dependency_lines = [line]
59+
has_x_version_update = False
60+
continue
61+
if '</dependency>' in line:
62+
in_dependency = False
63+
current_dependency_lines.append(line)
64+
if has_x_version_update:
65+
new_lines.extend(current_dependency_lines)
66+
continue
67+
68+
if in_dependency:
69+
current_dependency_lines.append(line)
70+
if '{x-version-update:' in line:
71+
has_x_version_update = True
72+
continue
73+
74+
# Prune comments and extra whitespace in depMgmt for a cleaner result
75+
if not line.strip():
76+
new_lines.append(line)
77+
continue
78+
79+
# Reporting section removal
80+
if '<reporting>' in line:
81+
in_reporting = True
82+
continue
83+
if '</reporting>' in line:
84+
in_reporting = False
85+
continue
86+
if in_reporting:
87+
continue
88+
89+
new_lines.append(line)
90+
91+
with open(file_path, 'w') as f:
92+
# Clean up double empty lines potentially introduced by pruning
93+
content = "".join(new_lines)
94+
content = re.sub(r'\n\s*\n\s*\n', '\n\n', content)
95+
f.write(content)
96+
97+
if __name__ == "__main__":
98+
if len(sys.argv) > 2:
99+
modernize_pom(sys.argv[1], sys.argv[2])
100+
else:
101+
print("Usage: python3 modernize_pom.py <file_path> <parent_version>")
102+
sys.exit(1)

0 commit comments

Comments
 (0)