Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2143,8 +2143,8 @@ private Model importDependencyManagement(Model model, Collection<String> importI
for (Iterator<Dependency> it = deps.iterator(); it.hasNext(); ) {
Dependency dependency = it.next();

if (!("pom".equals(dependency.getType()) && "import".equals(dependency.getScope()))
|| "bom".equals(dependency.getType())) {
if (!(("pom".equals(dependency.getType()) && "import".equals(dependency.getScope()))
|| "bom".equals(dependency.getType()))) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.apache.maven.api.Constants;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Provides;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.DependencyManagement;
import org.apache.maven.api.model.Model;
Expand All @@ -53,6 +55,10 @@
import org.apache.maven.impl.DefaultRemoteRepository;
import org.apache.maven.impl.standalone.ApiRunner;
import org.eclipse.aether.repository.RepositoryPolicy;
import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractor;
import org.eclipse.aether.spi.io.PathProcessor;
import org.eclipse.aether.transport.apache.ApacheTransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -925,6 +931,42 @@ public void testGetEnhancedPropertiesWithNonNormalizedRootDirectory(@TempDir Pat
+ "which indicates the path normalization fix (GH-12598) is not working.");
}

/**
* {@code type=bom} dependencyManagement entries must be processed as BOM imports
* without requiring {@code scope=import}. The {@code bom} type inherently implies
* import semantics (unlike {@code type=pom}, which requires {@code scope=import}).
* Operator precedence previously skipped {@code type=bom} always (GH-12589).
*/
@Test
public void testBomTypeImpliesImportWithoutScope() {
Path basedir = Paths.get(System.getProperty("basedir", ""));
Path localRepoPath = basedir.resolve("target/local-repo-bom-import");
Path remoteRepoPath = basedir.resolve("src/test/remote-repo");
Session bomSession = ApiRunner.createSession(
injector -> injector.bindInstance(DefaultModelBuilderTest.class, this), localRepoPath);
RemoteRepository remoteRepository = bomSession.createRemoteRepository(
RemoteRepository.CENTRAL_ID, remoteRepoPath.toUri().toString());
bomSession = bomSession.withRemoteRepositories(List.of(remoteRepository));
ModelBuilder bomBuilder = bomSession.getService(ModelBuilder.class);

ModelBuilderResult result = bomBuilder
.newSession()
.build(ModelBuilderRequest.builder()
.session(bomSession)
.requestType(ModelBuilderRequest.RequestType.BUILD_PROJECT)
.source(Sources.buildSource(getPom("import-bom-type")))
.build());

assertNotNull(result);
assertNotNull(result.getEffectiveModel().getDependencyManagement());
Dependency managed = result.getEffectiveModel().getDependencyManagement().getDependencies().stream()
.filter(d -> "a".equals(d.getArtifactId()) && "org.apache.maven.its".equals(d.getGroupId()))
.findFirst()
.orElse(null);
assertNotNull(managed, "Managed dependency from type=bom import should be present");
assertEquals("0.1", managed.getVersion());
}

private static DefaultProfileActivationContext.Record recordActiveProfile(
List<String> activeIds, String profileId) {
DefaultProfileActivationContext recording =
Expand All @@ -939,6 +981,19 @@ private static DefaultProfileActivationContext newProfileActivationContext(
null, null, null, activeIds, inactiveIds, Map.of(), Map.of(), Model.newInstance());
}

@Provides
@Named(FileTransporterFactory.NAME)
static FileTransporterFactory newFileTransporterFactory() {
return new FileTransporterFactory();
}

@Provides
@Named(ApacheTransporterFactory.NAME)
static ApacheTransporterFactory newApacheTransporterFactory(
ChecksumExtractor checksumExtractor, PathProcessor pathProcessor) {
return new ApacheTransporterFactory(checksumExtractor, pathProcessor);
}

private Path getPom(String name) {
return Paths.get("src/test/resources/poms/factory/" + name + ".xml").toAbsolutePath();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.1.0">
<groupId>org.apache.maven.tests</groupId>
<artifactId>import-bom-type</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencyManagement>
<dependencies>
<!-- type=bom without scope=import: the bom type inherently implies import -->
<dependency>
<groupId>org.apache.maven.its</groupId>
<artifactId>bom</artifactId>
<version>0.1</version>
<type>bom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Loading