Skip to content

Commit d4bc204

Browse files
committed
ensure annotation-api in maven-dependency-plugin configuration
1 parent c07bf8a commit d4bc204

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

monorepo-migration/modernize_pom.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
185185
in_dependencies = False
186186
in_dependency = False
187187
in_reporting = False
188+
in_plugins = False
189+
in_plugin = False
190+
in_configuration = False
191+
in_ignored_deps = False
192+
current_plugin_artifactId = None
193+
has_javax_annotation = False
194+
ignored_deps_lines = []
188195
current_dependency_lines = []
189196
should_preserve = False
190197
current_group_id = None
@@ -387,6 +394,67 @@ def modernize_pom(file_path, parent_version, source_repo_name=None, parent_artif
387394
new_lines.append(line)
388395
continue
389396

397+
# Plugin management (for maven-dependency-plugin configuration)
398+
if '<plugins>' in line:
399+
in_plugins = True
400+
if '</plugins>' in line:
401+
in_plugins = False
402+
403+
if in_plugins:
404+
if '<plugin>' in line:
405+
in_plugin = True
406+
current_plugin_artifactId = None
407+
has_javax_annotation = False
408+
if '</plugin>' in line:
409+
in_plugin = False
410+
411+
if in_plugin:
412+
if '<artifactId>' in line and not in_configuration:
413+
match = re.search(r'<artifactId>(.*?)</artifactId>', line)
414+
if match:
415+
current_plugin_artifactId = match.group(1).strip()
416+
417+
if current_plugin_artifactId == 'maven-dependency-plugin':
418+
if '<configuration>' in line:
419+
in_configuration = True
420+
if '</configuration>' in line:
421+
in_configuration = False
422+
423+
if in_configuration:
424+
if '<ignoredUnusedDeclaredDependencies>' in line:
425+
in_ignored_deps = True
426+
ignored_deps_lines = [line]
427+
continue
428+
429+
if in_ignored_deps:
430+
if 'javax.annotation:javax.annotation-api' in line:
431+
has_javax_annotation = True
432+
433+
if '</ignoredUnusedDeclaredDependencies>' in line:
434+
if not has_javax_annotation:
435+
# Try to find a good indentation
436+
indent = " " # Default
437+
if len(ignored_deps_lines) > 1:
438+
last_line = ignored_deps_lines[-1]
439+
match = re.search(r'^(\s+)', last_line)
440+
if match:
441+
indent = match.group(1)
442+
elif len(ignored_deps_lines) == 1:
443+
# Only the start tag
444+
match = re.search(r'^(\s+)', ignored_deps_lines[0])
445+
if match:
446+
indent = match.group(1) + " "
447+
448+
ignored_deps_lines.append(f"{indent}<ignoredUnusedDeclaredDependency>javax.annotation:javax.annotation-api</ignoredUnusedDeclaredDependency>\n")
449+
450+
new_lines.extend(ignored_deps_lines)
451+
new_lines.append(line)
452+
in_ignored_deps = False
453+
continue
454+
else:
455+
ignored_deps_lines.append(line)
456+
continue
457+
390458
# Reporting section removal
391459
if '<reporting>' in line:
392460
in_reporting = True

0 commit comments

Comments
 (0)