Skip to content

Commit 0772d80

Browse files
authored
Fix -itr option not honored (#11359)
Fixes #2576
1 parent 58bbee6 commit 0772d80

File tree

8 files changed

+104
-1
lines changed

8 files changed

+104
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ public ModelBuilderException newModelBuilderException() {
535535
}
536536

537537
public void mergeRepositories(Model model, boolean replace) {
538-
if (model.getRepositories().isEmpty()) {
538+
if (model.getRepositories().isEmpty()
539+
|| InternalSession.from(session).getSession().isIgnoreArtifactDescriptorRepositories()) {
539540
return;
540541
}
541542
// We need to interpolate the repositories before we can use them
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
26+
/**
27+
* This is a test set for <a href="https://github.com/apache/maven/issues/2576">GH-2576</a>.
28+
* <p>
29+
* The issue occurs when a project has a dependency which defines a custom repository needed to load its parent.
30+
* The -itr option should not use any transitive repository, so this project should fail.
31+
*
32+
*/
33+
class MavenITgh2576ItrNotHonoredTest extends AbstractMavenIntegrationTestCase {
34+
35+
@Test
36+
void testItrNotHonored() throws Exception {
37+
File testDir = extractResources("/gh-2576-itr-not-honored").getAbsoluteFile();
38+
39+
Verifier verifier = new Verifier(testDir.toString());
40+
verifier.deleteArtifacts("org.apache.maven.its.gh2576");
41+
42+
verifier = new Verifier(new File(testDir, "parent").toString());
43+
verifier.addCliArguments("install:install-file", "-Dfile=pom.xml", "-DpomFile=pom.xml", "-DlocalRepositoryPath=../repo/");
44+
verifier.execute();
45+
verifier.verifyErrorFreeLog();
46+
47+
// use maven 3 personality so that we don't flatten the pom
48+
verifier = new Verifier(new File(testDir, "dep").toString());
49+
verifier.addCliArguments("install", "-Dmaven.maven3Personality");
50+
verifier.execute();
51+
verifier.verifyErrorFreeLog();
52+
53+
verifier = new Verifier(new File(testDir, "consumer").toString());
54+
verifier.addCliArguments("install", "-itr");
55+
assertThrows(VerificationException.class, verifier::execute);
56+
}
57+
}

its/core-it-suite/src/test/resources/gh-2576-itr-not-honored/consumer/.mvn/.gitkeep

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.apache.maven.its.gh2576</groupId>
5+
<artifactId>consumer</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
8+
<dependencies>
9+
<dependency>
10+
<groupId>org.apache.maven.its.gh2576</groupId>
11+
<artifactId>dep</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
</dependency>
14+
</dependencies>
15+
</project>

its/core-it-suite/src/test/resources/gh-2576-itr-not-honored/dep/.mvn/.gitkeep

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.apache.maven.its.gh2576</groupId>
6+
<artifactId>parent</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>dep</artifactId>
11+
12+
<repositories>
13+
<repository>
14+
<id>foo</id>
15+
<url>file:///${basedir}/../repo</url>
16+
<snapshots>
17+
<checksumPolicy>ignore</checksumPolicy>
18+
<enabled>true</enabled>
19+
</snapshots>
20+
</repository>
21+
</repositories>
22+
</project>

its/core-it-suite/src/test/resources/gh-2576-itr-not-honored/parent/.mvn/.gitkeep

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.apache.maven.its.gh2576</groupId>
5+
<artifactId>parent</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>pom</packaging>
8+
</project>

0 commit comments

Comments
 (0)