Skip to content

Commit 39bd4b7

Browse files
authored
Do not include invalid transitive repositories (#11357)
For build POMs, the repositories are validated and cannot contain uninterpolated expressions. We need to ignore repositories containing such invalid URLs from dependencies. Fixes #11356
1 parent 0772d80 commit 39bd4b7

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ public void mergeRepositories(Model model, boolean replace) {
549549
request,
550550
this);
551551
List<RemoteRepository> repos = interpolatedModel.getRepositories().stream()
552+
// filter out transitive invalid repositories
553+
// this should be safe because invalid repo coming from build POMs
554+
// have been rejected earlier during validation
555+
.filter(repo -> repo.getUrl() != null && !repo.getUrl().contains("${"))
552556
.map(session::createRemoteRepository)
553557
.toList();
554558
if (replace) {

impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelBuilderTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ public void testMergeRepositories() throws Exception {
114114

115115
// after merge
116116
repositories = (List<RemoteRepository>) repositoriesField.get(state);
117-
assertEquals(4, repositories.size());
117+
assertEquals(3, repositories.size());
118118
assertEquals("first", repositories.get(0).getId());
119119
assertEquals("https://some.repo", repositories.get(0).getUrl()); // interpolated (user properties)
120-
assertEquals("second", repositories.get(1).getId());
121-
assertEquals("${secondParentRepo}", repositories.get(1).getUrl()); // un-interpolated (no source)
122-
assertEquals("third", repositories.get(2).getId());
123-
assertEquals("https://third.repo", repositories.get(2).getUrl()); // interpolated (own model properties)
124-
assertEquals("central", repositories.get(3).getId()); // default
120+
assertEquals("third", repositories.get(1).getId());
121+
assertEquals("https://third.repo", repositories.get(1).getUrl()); // interpolated (own model properties)
122+
assertEquals("central", repositories.get(2).getId()); // default
125123
}
126124

127125
@Test
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.io.File;
22+
import org.junit.jupiter.api.Test;
23+
24+
/**
25+
* This is a test set for <a href="https://github.com/apache/maven/issues/11356">GH-11356</a>.
26+
* Verify that Maven properly builds projects with a dependency that defines invalid repositories.
27+
*
28+
* @since 4.0.0
29+
*/
30+
public class MavenITgh11356InvalidTransitiveRepositoryTest extends AbstractMavenIntegrationTestCase {
31+
32+
@Test
33+
public void testInvalidTransitiveRepository() throws Exception {
34+
File testDir = extractResources("/gh-11356-invalid-transitive-repository");
35+
36+
// First, verify that normal build works from the actual root
37+
Verifier verifier = newVerifier(testDir.getAbsolutePath());
38+
verifier.addCliArgument("compile");
39+
verifier.execute();
40+
verifier.verifyErrorFreeLog();
41+
}
42+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
21+
22+
<groupId>org.apache.maven.reproducer</groupId>
23+
<artifactId>reproducer-debezium</artifactId>
24+
<version>1.0-SNAPSHOT</version>
25+
<packaging>jar</packaging>
26+
27+
<properties>
28+
<maven.compiler.source>11</maven.compiler.source>
29+
<maven.compiler.target>11</maven.compiler.target>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<debezium-version>3.3.1.Final</debezium-version>
32+
</properties>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>io.debezium</groupId>
37+
<artifactId>debezium-connector-db2</artifactId>
38+
<version>${debezium-version}</version>
39+
</dependency>
40+
</dependencies>
41+
</project>

0 commit comments

Comments
 (0)