This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MRESOLVER-98
in repository https://gitbox.apache.org/repos/asf/maven-resolver-ant-tasks.git

commit ca8c1311c81a5da50d01368f56563a990df6bc41
Author: William Leung <williamleung2...@gmail.com>
AuthorDate: Mon Mar 2 12:47:17 2020 +0800

    [MRESOLVER-98] resolver ant task doesn't obey dependencyManagement
    
    Closes #2
---
 pom.xml                                            |  4 +-
 .../maven/resolver/internal/ant/AntRepoSys.java    | 52 ++++++++++++++--------
 .../internal/ant/AntSettingsDecryptorFactory.java  | 21 ++-------
 .../maven/resolver/internal/ant/ResolveTest.java   | 17 +++++--
 src/test/resources/ant/Resolve/ant.xml             |  9 ++++
 .../ant/Resolve/with-dependency-management.pom     | 48 ++++++++++++++++++++
 6 files changed, 108 insertions(+), 43 deletions(-)

diff --git a/pom.xml b/pom.xml
index a52b02c..acb8a15 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,8 +61,8 @@
   </distributionManagement>
 
   <properties>
-    <mavenVersion>3.5.0</mavenVersion>
-    <resolverVersion>1.3.3</resolverVersion>
+    <mavenVersion>3.6.3</mavenVersion>
+    <resolverVersion>1.4.1</resolverVersion>
     <antVersion>1.8.4</antVersion>
     <javaVersion>7</javaVersion>
     
<maven.site.path>resolver-archives/resolver-ant-tasks-LATEST</maven.site.path>
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 9242855..e2848b1 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
@@ -678,33 +678,22 @@ public class AntRepoSys
             Model model = dependencies.getPom().getModel( task );
             for ( org.apache.maven.model.Dependency dep : 
model.getDependencies() )
             {
-                Dependency dependency = new Dependency();
-                dependency.setArtifactId( dep.getArtifactId() );
-                dependency.setClassifier( dep.getClassifier() );
-                dependency.setGroupId( dep.getGroupId() );
-                dependency.setScope( dep.getScope() );
-                dependency.setType( dep.getType() );
-                dependency.setVersion( dep.getVersion() );
+                Dependency dependency = toDependency( dep, task );
                 if ( ids.contains( dependency.getVersionlessKey() ) )
                 {
                     project.log( "Ignoring dependency " + 
dependency.getVersionlessKey() + " from " + model.getId()
                         + ", already declared locally", Project.MSG_VERBOSE );
                     continue;
                 }
-                if ( dep.getSystemPath() != null && 
dep.getSystemPath().length() > 0 )
-                {
-                    dependency.setSystemPath( task.getProject().resolveFile( 
dep.getSystemPath() ) );
-                }
-                for ( org.apache.maven.model.Exclusion exc : 
dep.getExclusions() )
+                collectRequest.addDependency( ConverterUtils.toDependency( 
dependency, globalExclusions, session ) );
+            }
+            if ( model.getDependencyManagement() != null )
+            {
+                for ( org.apache.maven.model.Dependency dep : 
model.getDependencyManagement().getDependencies() )
                 {
-                    Exclusion exclusion = new Exclusion();
-                    exclusion.setGroupId( exc.getGroupId() );
-                    exclusion.setArtifactId( exc.getArtifactId() );
-                    exclusion.setClassifier( "*" );
-                    exclusion.setExtension( "*" );
-                    dependency.addExclusion( exclusion );
+                    Dependency dependency = toDependency( dep, task );
+                    collectRequest.addManagedDependency( 
ConverterUtils.toDependency( dependency, globalExclusions, session ) );
                 }
-                collectRequest.addDependency( ConverterUtils.toDependency( 
dependency, globalExclusions, session ) );
             }
         }
 
@@ -724,6 +713,31 @@ public class AntRepoSys
         }
     }
 
+    private Dependency toDependency( org.apache.maven.model.Dependency dep, 
Task task )
+    {
+        Dependency dependency = new Dependency();
+        dependency.setArtifactId( dep.getArtifactId() );
+        dependency.setClassifier( dep.getClassifier() );
+        dependency.setGroupId( dep.getGroupId() );
+        dependency.setScope( dep.getScope() );
+        dependency.setType( dep.getType() );
+        dependency.setVersion( dep.getVersion() );
+        if ( dep.getSystemPath() != null && dep.getSystemPath().length() > 0 )
+        {
+            dependency.setSystemPath( task.getProject().resolveFile( 
dep.getSystemPath() ) );
+        }
+        for ( org.apache.maven.model.Exclusion exc : dep.getExclusions() )
+        {
+            Exclusion exclusion = new Exclusion();
+            exclusion.setGroupId( exc.getGroupId() );
+            exclusion.setArtifactId( exc.getArtifactId() );
+            exclusion.setClassifier( "*" );
+            exclusion.setExtension( "*" );
+            dependency.addExclusion( exclusion );
+        }
+        return dependency;
+    }
+
     private List<Dependency> readDependencies( File file )
     {
         List<Dependency> dependencies = new ArrayList<Dependency>();
diff --git 
a/src/main/java/org/apache/maven/resolver/internal/ant/AntSettingsDecryptorFactory.java
 
b/src/main/java/org/apache/maven/resolver/internal/ant/AntSettingsDecryptorFactory.java
index 39ef960..bfa2e07 100644
--- 
a/src/main/java/org/apache/maven/resolver/internal/ant/AntSettingsDecryptorFactory.java
+++ 
b/src/main/java/org/apache/maven/resolver/internal/ant/AntSettingsDecryptorFactory.java
@@ -8,9 +8,9 @@ package org.apache.maven.resolver.internal.ant;
  * 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
@@ -19,8 +19,6 @@ package org.apache.maven.resolver.internal.ant;
  * under the License.
  */
 
-import java.lang.reflect.Field;
-
 import org.apache.maven.settings.crypto.DefaultSettingsDecrypter;
 
 /**
@@ -32,20 +30,7 @@ class AntSettingsDecryptorFactory
     {
         AntSecDispatcher secDispatcher = new AntSecDispatcher();
 
-        DefaultSettingsDecrypter decrypter = new DefaultSettingsDecrypter();
-
-        try
-        {
-            Field field = decrypter.getClass().getDeclaredField( 
"securityDispatcher" );
-            field.setAccessible( true );
-            field.set( decrypter, secDispatcher );
-        }
-        catch ( Exception e )
-        {
-            throw new IllegalStateException( e );
-        }
-
-        return decrypter;
+        return new DefaultSettingsDecrypter( secDispatcher );
     }
 
 }
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 a736a74..ab560fd 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
@@ -8,9 +8,9 @@ package org.apache.maven.resolver.internal.ant;
  * 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
@@ -76,14 +76,23 @@ public class ResolveTest
                     new File( dir, 
"org.eclipse.aether/aether-api/org/eclipse/aether/jar" ).exists() );
     }
 
+    public void testResolvePomWithManagedDeps()
+    {
+        executeTarget( "testResolvePomWithManagedDeps" );
+
+        String prop = getProject().getProperty( 
"test.resolve.path.org.apache.maven.resolver:maven-resolver-api:jar" );
+        assertThat( "maven-resolver-api was not resolved to managed version", 
prop.replace( '\\', '/' ),
+                    endsWith( 
"org/apache/maven/resolver/maven-resolver-api/1.4.1/maven-resolver-api-1.4.1.jar"
 ) );
+    }
+
     public void testResolveAttachments()
         throws IOException
     {
         File dir = new File( BUILD_DIR, "resolve-attachments" );
         executeTarget( "testResolveAttachments" );
-        
+
         File jdocDir = new File(dir, "javadoc");
-        
+
         assertThat( "aether-api-javadoc was not saved with custom file layout",
                     new File( jdocDir, 
"org.eclipse.aether-aether-api-javadoc.jar" ).exists() );
 
diff --git a/src/test/resources/ant/Resolve/ant.xml 
b/src/test/resources/ant/Resolve/ant.xml
index 12b4f34..b32b05b 100644
--- a/src/test/resources/ant/Resolve/ant.xml
+++ b/src/test/resources/ant/Resolve/ant.xml
@@ -68,6 +68,15 @@
     </repo:resolve>
   </target>
 
+  <target name="testResolvePomWithManagedDeps">
+    <repo:resolve>
+      <dependencies>
+        <pom file="${project.dir}/with-dependency-management.pom"/>
+      </dependencies>
+      <properties prefix="test.resolve.path" classpath="runtime"/>
+    </repo:resolve>
+  </target>
+
   <target name="testResolveAttachments">
     <repo:resolve>
       <dependencies>
diff --git a/src/test/resources/ant/Resolve/with-dependency-management.pom 
b/src/test/resources/ant/Resolve/with-dependency-management.pom
new file mode 100644
index 0000000..759b540
--- /dev/null
+++ b/src/test/resources/ant/Resolve/with-dependency-management.pom
@@ -0,0 +1,48 @@
+<?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>
+
+  <groupId>test</groupId>
+  <artifactId>dummy</artifactId>
+  <version>0.1-SNAPSHOT</version>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.maven.resolver</groupId>
+        <artifactId>maven-resolver-api</artifactId>
+        <version>1.4.1</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-util</artifactId>
+      <version>1.4.0</version>
+    </dependency>
+  </dependencies>
+</project>

Reply via email to