|
61 | 61 | if git diff --name-only --diff-filter=U | grep -q "^pom.xml$"; then |
62 | 62 | echo "Resolving pom.xml conflicts intelligently..." |
63 | 63 | git show upstream/master:pom.xml > /tmp/upstream-pom.xml |
64 | | - python3 << 'PYTHON_SCRIPT' |
65 | | -import re |
66 | | -import sys |
67 | | - |
68 | | -def smart_merge_pom(our_file, upstream_file, output_file): |
69 | | - with open(our_file, 'r', encoding='utf-8') as f: |
70 | | - our_content = f.read() |
71 | | - with open(upstream_file, 'r', encoding='utf-8') as f: |
72 | | - upstream_content = f.read() |
73 | | - |
74 | | - critical_fixes = { |
75 | | - (r'<artifactId>flatten-maven-plugin</artifactId>\s*<version>1\.3\.0</version>', |
76 | | - '<artifactId>flatten-maven-plugin</artifactId>\n <version>1.6.0</version>'): |
77 | | - "Upgrade flatten plugin for Maven 3.9.6 compatibility", |
78 | | - (r'(</flatten-maven-plugin>\s*</plugin>)', |
79 | | - r'''\1 |
80 | | - <plugin> |
81 | | - <groupId>org.apache.maven.plugins</groupId> |
82 | | - <artifactId>maven-jar-plugin</artifactId> |
83 | | - <version>3.3.0</version> |
84 | | - <dependencies> |
85 | | - <dependency> |
86 | | - <groupId>org.codehaus.plexus</groupId> |
87 | | - <artifactId>plexus-archiver</artifactId> |
88 | | - <version>4.4.0</version> |
89 | | - </dependency> |
90 | | - <dependency> |
91 | | - <groupId>org.codehaus.plexus</groupId> |
92 | | - <artifactId>plexus-io</artifactId> |
93 | | - <version>3.2.0</version> |
94 | | - </dependency> |
95 | | - <dependency> |
96 | | - <groupId>org.codehaus.plexus</groupId> |
97 | | - <artifactId>plexus-interpolation</artifactId> |
98 | | - <version>1.27</version> |
99 | | - </dependency> |
100 | | - <dependency> |
101 | | - <groupId>commons-io</groupId> |
102 | | - <artifactId>commons-io</artifactId> |
103 | | - <version>2.8.0</version> |
104 | | - </dependency> |
105 | | - <dependency> |
106 | | - <groupId>org.apache.commons</groupId> |
107 | | - <artifactId>commons-compress</artifactId> |
108 | | - <version>1.20</version> |
109 | | - </dependency> |
110 | | - </dependencies> |
111 | | - </plugin>'''): |
112 | | - "Add jar plugin configuration with required dependencies" |
113 | | - } |
114 | | - |
115 | | - merged_content = our_content |
116 | | - |
117 | | - upstream_repos = re.search(r'<repositories>(.*?)</repositories>', upstream_content, re.DOTALL) |
118 | | - our_repos = re.search(r'<repositories>(.*?)</repositories>', our_content, re.DOTALL) |
119 | | - |
120 | | - if upstream_repos and our_repos: |
121 | | - upstream_repo_list = re.findall(r'<repository>.*?</repository>', upstream_repos.group(1), re.DOTALL) |
122 | | - our_repo_list = re.findall(r'<repository>.*?</repository>', our_repos.group(1), re.DOTALL) |
123 | | - our_repo_ids = set() |
124 | | - for repo in our_repo_list: |
125 | | - match = re.search(r'<id>(.*?)</id>', repo) |
126 | | - if match: |
127 | | - our_repo_ids.add(match.group(1)) |
128 | | - new_repos = [] |
129 | | - for repo in upstream_repo_list: |
130 | | - match = re.search(r'<id>(.*?)</id>', repo) |
131 | | - if match and match.group(1) not in our_repo_ids: |
132 | | - new_repos.append(repo) |
133 | | - if new_repos: |
134 | | - print(f"Adding {len(new_repos)} new repositories from upstream") |
135 | | - new_repos_str = '\n '.join(new_repos) |
136 | | - merged_content = re.sub( |
137 | | - r'(</repositories>)', |
138 | | - f' {new_repos_str}\n </repositories>', |
139 | | - merged_content |
140 | | - ) |
141 | | - |
142 | | - for pattern, replacement in critical_fixes.items(): |
143 | | - if isinstance(pattern, tuple): |
144 | | - merged_content = re.sub(pattern[0], replacement, merged_content) |
145 | | - else: |
146 | | - merged_content = re.sub(pattern, replacement, merged_content) |
147 | | - |
148 | | - with open(output_file, 'w', encoding='utf-8') as f: |
149 | | - f.write(merged_content) |
150 | | - print("Smart merge completed") |
151 | | - return True |
152 | | - |
153 | | -if __name__ == '__main__': |
154 | | - success = smart_merge_pom('/tmp/our-pom.xml', '/tmp/upstream-pom.xml', 'pom.xml') |
155 | | - sys.exit(0 if success else 1) |
156 | | -PYTHON_SCRIPT |
| 64 | + python3 scripts/smart_merge_pom.py /tmp/our-pom.xml /tmp/upstream-pom.xml pom.xml |
157 | 65 | git add pom.xml |
158 | 66 | git commit -m "Smart merge: resolve pom.xml conflicts with upstream" -m "- Preserved GitHub Actions build fixes" -m "- Merged new repositories from upstream" -m "- Kept flatten-maven-plugin at 1.6.0 for compatibility" -m "- Maintained jar plugin configuration with required dependencies" |
159 | 67 | fi |
|
0 commit comments