You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2023/09/07 08:01:05 UTC
[maven-resolver-ant-tasks] 01/01: Add depMgt support and tests
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch depmgt
in repository https://gitbox.apache.org/repos/asf/maven-resolver-ant-tasks.git
commit 3ac672c84b21a93ba3e522a69edcc2508f68ae2c
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Sep 7 10:00:46 2023 +0200
Add depMgt support and tests
---
.../maven/resolver/internal/ant/AntRepoSys.java | 27 +++++++
.../maven/resolver/internal/ant/ResolveTest.java | 19 +++++
src/test/resources/ant/Resolve/ant.xml | 7 ++
.../ant/Resolve/transitive-depmgt-pom.xml | 82 ++++++++++++++++++++++
4 files changed, 135 insertions(+)
diff --git a/src/main/java/org/apache/maven/resolver/internal/ant/AntRepoSys.java b/src/main/java/org/apache/maven/resolver/internal/ant/AntRepoSys.java
index d6329ad..10e8d63 100644
--- a/src/main/java/org/apache/maven/resolver/internal/ant/AntRepoSys.java
+++ b/src/main/java/org/apache/maven/resolver/internal/ant/AntRepoSys.java
@@ -627,6 +627,33 @@ public class AntRepoSys {
if (dependencies.getPom() != null) {
Model model = dependencies.getPom().getModel(task);
+ if (model.getDependencyManagement() != null) {
+ for (org.apache.maven.model.Dependency manDep :
+ model.getDependencyManagement().getDependencies()) {
+ Dependency dependency = new Dependency();
+ dependency.setArtifactId(manDep.getArtifactId());
+ dependency.setClassifier(manDep.getClassifier());
+ dependency.setGroupId(manDep.getGroupId());
+ dependency.setScope(manDep.getScope());
+ dependency.setType(manDep.getType());
+ dependency.setVersion(manDep.getVersion());
+ if (manDep.getSystemPath() != null
+ && !manDep.getSystemPath().isEmpty()) {
+ dependency.setSystemPath(task.getProject().resolveFile(manDep.getSystemPath()));
+ }
+ for (org.apache.maven.model.Exclusion exc : manDep.getExclusions()) {
+ Exclusion exclusion = new Exclusion();
+ exclusion.setGroupId(exc.getGroupId());
+ exclusion.setArtifactId(exc.getArtifactId());
+ exclusion.setClassifier("*");
+ exclusion.setExtension("*");
+ dependency.addExclusion(exclusion);
+ }
+ collectRequest.addManagedDependency(
+ ConverterUtils.toDependency(dependency, globalExclusions, session));
+ }
+ }
+
for (org.apache.maven.model.Dependency dep : model.getDependencies()) {
Dependency dependency = new Dependency();
dependency.setArtifactId(dep.getArtifactId());
diff --git a/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java b/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
index 18307aa..022efd6 100644
--- a/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
+++ b/src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java
@@ -158,4 +158,23 @@ public class ResolveTest extends AntBuildsTest {
file = (FileResource) it.next();
assertThat(file.getFile().getName(), is("aether-api-0.9.0.v20140226.jar"));
}
+
+ @Test
+ public void testResolveTransitiveDependencyManagement() {
+ executeTarget("testResolveTransitiveDependencyManagement");
+
+ String prop = getProject().getProperty("test.resolve.path.org.slf4j:slf4j-api:jar");
+ assertThat("slf4j-api was not resolved as a property", prop, notNullValue());
+ assertThat(
+ "slf4j-api was not resolved to default local repository",
+ prop,
+ allOf(containsString("slf4j-api"), endsWith("slf4j-api-2.0.6.jar")));
+
+ prop = getProject().getProperty("test.resolve.path.org.apiguardian:apiguardian-api:jar");
+ assertThat("apiguardian-api was not resolved as a property", prop, notNullValue());
+ assertThat(
+ "apiguardian-api was not resolved to default local repository",
+ prop,
+ allOf(containsString("apiguardian-api"), endsWith("apiguardian-api-1.1.1.jar")));
+ }
}
diff --git a/src/test/resources/ant/Resolve/ant.xml b/src/test/resources/ant/Resolve/ant.xml
index 12b4f34..d88fd59 100644
--- a/src/test/resources/ant/Resolve/ant.xml
+++ b/src/test/resources/ant/Resolve/ant.xml
@@ -119,4 +119,11 @@
</repo:resolve>
</target>
+ <target name="testResolveTransitiveDependencyManagement">
+ <repo:pom file="${project.dir}/transitive-depmgt-pom.xml"/>
+ <repo:resolve>
+ <properties prefix="test.resolve.path" classpath="compile"/>
+ </repo:resolve>
+ </target>
+
</project>
diff --git a/src/test/resources/ant/Resolve/transitive-depmgt-pom.xml b/src/test/resources/ant/Resolve/transitive-depmgt-pom.xml
new file mode 100644
index 0000000..dd6f8a6
--- /dev/null
+++ b/src/test/resources/ant/Resolve/transitive-depmgt-pom.xml
@@ -0,0 +1,82 @@
+<?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.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.sonatype.forge</groupId>
+ <artifactId>forge-parent</artifactId>
+ <version>10</version>
+ </parent>
+
+ <groupId>org.eclipse.aether</groupId>
+ <artifactId>aether-ant-tasks</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <!--
+ Transitive Dependency Management POM test
+
+ This test does two things:
+ - depends on slf4j-simple:2.0.7 but overrides its transitive dep slf4j-api to version 2.0.6
+ - overrides apiguardian-api to version 1.1.1 in depMgt
+ - uses Junit BOM, that would like to use apiguardian-api 1.1.2
+ -->
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apiguardian</groupId>
+ <artifactId>apiguardian-api</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.10.0</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>