|
| 1 | +"""Integration test for mega-melt's duplicate-class detection. |
| 2 | +
|
| 3 | +Uses the duplicate-classes fixture (a POM that depends directly on both |
| 4 | +log4j and reload4j, which both provide org.apache.log4j.* classes) to |
| 5 | +confirm that pom-scijava's banDuplicateClasses enforcer rule — the rule |
| 6 | +mega-melt validation relies on to catch classpath conflicts across a BOM |
| 7 | +(see README's mega-melt section) — actually fires. |
| 8 | +
|
| 9 | +This runs a real Maven build against Maven Central and is intentionally |
| 10 | +slow. |
| 11 | +""" |
| 12 | + |
| 13 | +from __future__ import annotations |
| 14 | + |
| 15 | +import shutil |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +from pombast.maven._builder import locate_java |
| 19 | +from pombast.maven._mega_melt import run_mega_melt_validation |
| 20 | + |
| 21 | +FIXTURE = Path(__file__).parent.parent / "fixtures" / "duplicate-classes" |
| 22 | + |
| 23 | +# pom-scijava's parent chain requires Java 11+; pin it explicitly so this |
| 24 | +# test doesn't spuriously fail on an older ambient JDK before ever reaching |
| 25 | +# the duplicate-classes rule. |
| 26 | +_JAVA_VERSION = 11 |
| 27 | + |
| 28 | + |
| 29 | +def test_duplicate_classes_fail_enforcer(tmp_path): |
| 30 | + """log4j + reload4j together should trip banDuplicateClasses.""" |
| 31 | + mega_melt_dir = tmp_path / "duplicate-classes" |
| 32 | + shutil.copytree(FIXTURE, mega_melt_dir) |
| 33 | + |
| 34 | + java_home = locate_java(_JAVA_VERSION) |
| 35 | + success, _tree_log, build_log = run_mega_melt_validation( |
| 36 | + mega_melt_dir, java_home=java_home |
| 37 | + ) |
| 38 | + |
| 39 | + assert not success, "expected enforcer to fail on duplicate classes" |
| 40 | + |
| 41 | + log_content = build_log.read_text(encoding="utf-8") |
| 42 | + assert "BanDuplicateClasses" in log_content, ( |
| 43 | + f"expected a BanDuplicateClasses enforcer failure, but got:\n{log_content}" |
| 44 | + ) |
| 45 | + assert "ch.qos.reload4j:reload4j" in log_content |
| 46 | + assert "log4j:log4j" in log_content |
0 commit comments