@@ -1457,6 +1457,181 @@ void shouldCommentOutWhenPropertyTrulyUndefinedInEffectiveModel() throws Excepti
14571457 }
14581458 }
14591459
1460+ @ Nested
1461+ @ DisplayName ("Undefined Property Expression in Repositories Fixes" )
1462+ class UndefinedPropertyExpressionInRepositoriesTests {
1463+
1464+ @ Test
1465+ @ DisplayName ("should comment out repository with undefined property in id" )
1466+ void shouldCommentOutRepositoryWithUndefinedPropertyInId () throws Exception {
1467+ String pomXml = """
1468+ <?xml version="1.0" encoding="UTF-8"?>
1469+ <project xmlns="http://maven.apache.org/POM/4.0.0">
1470+ <modelVersion>4.0.0</modelVersion>
1471+ <groupId>test</groupId>
1472+ <artifactId>test</artifactId>
1473+ <version>1.0.0</version>
1474+ <repositories>
1475+ <repository>
1476+ <id>${eclipseP2RepoId}</id>
1477+ <url>https://repo.example.com</url>
1478+ </repository>
1479+ </repositories>
1480+ </project>
1481+ """ ;
1482+
1483+ Document document = Document .of (pomXml );
1484+ Map <Path , Document > pomMap = Map .of (Paths .get ("pom.xml" ), document );
1485+
1486+ UpgradeContext context = createMockContext ();
1487+ UpgradeResult result = strategy .doApply (context , pomMap );
1488+
1489+ assertTrue (result .success (), "Compatibility fix should succeed" );
1490+ assertTrue (result .modifiedCount () > 0 , "Should have commented out repository" );
1491+
1492+ String xml = DomUtils .toXml (document );
1493+ assertTrue (xml .contains ("mvnup: commented out" ), "Should contain comment-out marker" );
1494+ assertTrue (xml .contains ("eclipseP2RepoId" ), "Should mention the undefined property" );
1495+
1496+ Element root = document .root ();
1497+ Element repos = DomUtils .findChildElement (root , "repositories" );
1498+ assertEquals (0 , repos .childElements ("repository" ).count (), "Should have no repository elements" );
1499+ }
1500+
1501+ @ Test
1502+ @ DisplayName ("should comment out repository with undefined property in url" )
1503+ void shouldCommentOutRepositoryWithUndefinedPropertyInUrl () throws Exception {
1504+ String pomXml = """
1505+ <?xml version="1.0" encoding="UTF-8"?>
1506+ <project xmlns="http://maven.apache.org/POM/4.0.0">
1507+ <modelVersion>4.0.0</modelVersion>
1508+ <groupId>test</groupId>
1509+ <artifactId>test</artifactId>
1510+ <version>1.0.0</version>
1511+ <repositories>
1512+ <repository>
1513+ <id>my-repo</id>
1514+ <url>${undefinedBaseUrl}/releases</url>
1515+ </repository>
1516+ </repositories>
1517+ </project>
1518+ """ ;
1519+
1520+ Document document = Document .of (pomXml );
1521+ Map <Path , Document > pomMap = Map .of (Paths .get ("pom.xml" ), document );
1522+
1523+ UpgradeContext context = createMockContext ();
1524+ UpgradeResult result = strategy .doApply (context , pomMap );
1525+
1526+ assertTrue (result .success (), "Compatibility fix should succeed" );
1527+ assertTrue (result .modifiedCount () > 0 , "Should have commented out repository" );
1528+
1529+ String xml = DomUtils .toXml (document );
1530+ assertTrue (xml .contains ("mvnup: commented out" ), "Should contain comment-out marker" );
1531+ assertTrue (xml .contains ("undefinedBaseUrl" ), "Should mention the undefined property" );
1532+ }
1533+
1534+ @ Test
1535+ @ DisplayName ("should not comment out repository with defined property" )
1536+ void shouldNotCommentOutRepositoryWithDefinedProperty () throws Exception {
1537+ String pomXml = """
1538+ <?xml version="1.0" encoding="UTF-8"?>
1539+ <project xmlns="http://maven.apache.org/POM/4.0.0">
1540+ <modelVersion>4.0.0</modelVersion>
1541+ <groupId>test</groupId>
1542+ <artifactId>test</artifactId>
1543+ <version>1.0.0</version>
1544+ <properties>
1545+ <repoId>my-custom-repo</repoId>
1546+ </properties>
1547+ <repositories>
1548+ <repository>
1549+ <id>${repoId}</id>
1550+ <url>https://repo.example.com</url>
1551+ </repository>
1552+ </repositories>
1553+ </project>
1554+ """ ;
1555+
1556+ Document document = Document .of (pomXml );
1557+ Map <Path , Document > pomMap = Map .of (Paths .get ("pom.xml" ), document );
1558+
1559+ UpgradeContext context = createMockContext ();
1560+ strategy .doApply (context , pomMap );
1561+
1562+ Element root = document .root ();
1563+ Element repos = DomUtils .findChildElement (root , "repositories" );
1564+ assertEquals (1 , repos .childElements ("repository" ).count (), "Repository should still be present" );
1565+ }
1566+
1567+ @ Test
1568+ @ DisplayName ("should comment out plugin repository with undefined property" )
1569+ void shouldCommentOutPluginRepositoryWithUndefinedProperty () throws Exception {
1570+ String pomXml = """
1571+ <?xml version="1.0" encoding="UTF-8"?>
1572+ <project xmlns="http://maven.apache.org/POM/4.0.0">
1573+ <modelVersion>4.0.0</modelVersion>
1574+ <groupId>test</groupId>
1575+ <artifactId>test</artifactId>
1576+ <version>1.0.0</version>
1577+ <pluginRepositories>
1578+ <pluginRepository>
1579+ <id>${eclipseP2RepoId}</id>
1580+ <url>https://plugins.example.com</url>
1581+ </pluginRepository>
1582+ </pluginRepositories>
1583+ </project>
1584+ """ ;
1585+
1586+ Document document = Document .of (pomXml );
1587+ Map <Path , Document > pomMap = Map .of (Paths .get ("pom.xml" ), document );
1588+
1589+ UpgradeContext context = createMockContext ();
1590+ UpgradeResult result = strategy .doApply (context , pomMap );
1591+
1592+ assertTrue (result .success (), "Compatibility fix should succeed" );
1593+ assertTrue (result .modifiedCount () > 0 , "Should have commented out plugin repository" );
1594+
1595+ String xml = DomUtils .toXml (document );
1596+ assertTrue (xml .contains ("mvnup: commented out" ), "Should contain comment-out marker" );
1597+
1598+ Element root = document .root ();
1599+ Element repos = DomUtils .findChildElement (root , "pluginRepositories" );
1600+ assertEquals (
1601+ 0 , repos .childElements ("pluginRepository" ).count (), "Should have no pluginRepository elements" );
1602+ }
1603+
1604+ @ Test
1605+ @ DisplayName ("should not comment out repository with well-known property" )
1606+ void shouldNotCommentOutRepositoryWithWellKnownProperty () throws Exception {
1607+ String pomXml = """
1608+ <?xml version="1.0" encoding="UTF-8"?>
1609+ <project xmlns="http://maven.apache.org/POM/4.0.0">
1610+ <modelVersion>4.0.0</modelVersion>
1611+ <groupId>test</groupId>
1612+ <artifactId>test</artifactId>
1613+ <version>1.0.0</version>
1614+ <repositories>
1615+ <repository>
1616+ <id>local-repo</id>
1617+ <url>file://${project.basedir}/repo</url>
1618+ </repository>
1619+ </repositories>
1620+ </project>
1621+ """ ;
1622+
1623+ Document document = Document .of (pomXml );
1624+ Map <Path , Document > pomMap = Map .of (Paths .get ("pom.xml" ), document );
1625+
1626+ UpgradeContext context = createMockContext ();
1627+ strategy .doApply (context , pomMap );
1628+
1629+ Element root = document .root ();
1630+ Element repos = DomUtils .findChildElement (root , "repositories" );
1631+ assertEquals (1 , repos .childElements ("repository" ).count (), "Repository should still be present" );
1632+ }
1633+ }
1634+
14601635 @ Nested
14611636 @ DisplayName ("Strategy Description" )
14621637 class StrategyDescriptionTests {
0 commit comments