[groovy] branch GROOVY-8372 created (now 50ea7be)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch GROOVY-8372 created (now 50ea7be)

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

emilles pushed a change to branch GROOVY-8372
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 50ea7be  GROOVY-8372: pass remote (not local) conf to addDependencyArtifact

This branch includes the following new commits:

     new 50ea7be  GROOVY-8372: pass remote (not local) conf to addDependencyArtifact

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[groovy] 01/01: GROOVY-8372: pass remote (not local) conf to addDependencyArtifact

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

emilles pushed a commit to branch GROOVY-8372
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 50ea7be540008301852aa8bcbc8fd5e55a08625b
Author: Eric Milles <[hidden email]>
AuthorDate: Wed Nov 6 15:33:01 2019 -0600

    GROOVY-8372: pass remote (not local) conf to addDependencyArtifact
   
    add dependency artifacts only if ext, type or classifier is non-default
---
 src/main/groovy/groovy/grape/GrapeIvy.groovy | 20 +++++-----
 src/test/groovy/grape/GrapeIvyTest.groovy    | 58 +++++++++++++++++++++++++++-
 2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index c1c637e..7c6a541 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -422,23 +422,25 @@ class GrapeIvy implements GrapeEngine {
         addExcludesIfNeeded(args, md)
 
         for (IvyGrabRecord grabRecord : grabRecords) {
-            def conf = grabRecord.conf ?: ['*']
+            def confs = grabRecord.conf ?: ['*']
             DefaultDependencyDescriptor dd = (DefaultDependencyDescriptor) md.dependencies.find {
                 it.dependencyRevisionId == grabRecord.mrid
             }
             if (!dd) {
                 dd = new DefaultDependencyDescriptor(md, grabRecord.mrid, grabRecord.force, grabRecord.changing, grabRecord.transitive)
-                conf.each { dd.addDependencyConfiguration('default', it) }
+                confs.each { conf -> dd.addDependencyConfiguration('default', conf) }
                 md.addDependency(dd)
             }
 
-            // the optional configuration typically does not extend the default or master configuration, so prevent grabbing the main artifact
-            if (Collections.singleton('optional') == (conf as Set)) continue
-
-            // add artifact descriptor to dependency descriptor
-            def dad = new DefaultDependencyArtifactDescriptor(dd, grabRecord.mrid.name, grabRecord.type ?: 'jar', grabRecord.ext ?: 'jar', null, grabRecord.classifier ? [classifier: grabRecord.classifier] : null)
-            conf.each { dad.addConfiguration(it) }
-            dd.addDependencyArtifact('default', dad)
+            if (grabRecord.classifier != null
+                    || (grabRecord.ext != null && grabRecord.ext != 'jar')
+                    || (grabRecord.type != null && grabRecord.type != 'jar')) {
+                // add artifact descriptor(s) to dependency descriptor
+                confs.each { conf ->
+                    def dad = new DefaultDependencyArtifactDescriptor(dd, grabRecord.mrid.name, grabRecord.type ?: 'jar', grabRecord.ext ?: 'jar', null, grabRecord.classifier ? [classifier: grabRecord.classifier] : null)
+                    dd.addDependencyArtifact(conf, dad)
+                }
+            }
         }
 
         // resolve grab and dependencies
diff --git a/src/test/groovy/grape/GrapeIvyTest.groovy b/src/test/groovy/grape/GrapeIvyTest.groovy
index 375d0c7..1de4232 100644
--- a/src/test/groovy/grape/GrapeIvyTest.groovy
+++ b/src/test/groovy/grape/GrapeIvyTest.groovy
@@ -209,7 +209,7 @@ final class GrapeIvyTest {
     }
 
     @Test
-    void testConf() {
+    void testConf1() {
         Set noJars = [
         ]
         Set coreJars = [
@@ -257,6 +257,62 @@ final class GrapeIvyTest {
         assert jars == coreJars + optionalJars, 'assert that no extraneous jars are present'
     }
 
+    @Test // GROOVY-8372
+    void testConf2() {
+        def tempDir = File.createTempDir()
+        def jarsDir = new File(tempDir, 'foo/bar/jars'); jarsDir.mkdirs()
+
+        new File(jarsDir, 'bar-1.2.3.jar').createNewFile()
+        new File(jarsDir, 'baz-1.2.3.jar').createNewFile()
+
+        new File(tempDir, 'ivysettings.xml').write '''\
+            <?xml version="1.0" encoding="UTF-8"?>
+            <ivysettings>
+                <caches useOrigin="true" />
+                <resolvers>
+                    <filesystem name="downloadGrapes">
+                        <ivy pattern="${ivy.settings.dir}/[organization]/[module]/ivy-[revision].xml" />
+                        <artifact pattern="${ivy.settings.dir}/[organization]/[module]/[type]s/[artifact]-[revision].[ext]" />
+                    </filesystem>
+                </resolvers>
+            </ivysettings>
+            '''.stripIndent()
+
+        new File(tempDir, 'foo/bar/ivy-1.2.3.xml').write '''\
+            <?xml version="1.0" encoding="UTF-8"?>
+            <ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
+                <info organisation="foo" module="bar" revision="1.2.3" status="release" />
+                <configurations>
+                    <conf name="default" visibility="public" extends="master" />
+                    <conf name="master" visibility="public" />
+                    <conf name="other" visibility="public" />
+                </configurations>
+                <publications>
+                    <artifact name="bar" type="jar" ext="jar" conf="master" />
+                    <artifact name="baz" type="jar" ext="jar" conf="other" />
+                </publications>
+            </ivy-module>
+            '''.stripIndent()
+
+        System.setProperty('grape.config', tempDir.absolutePath + File.separator + 'ivysettings.xml')
+        System.setProperty('groovy.grape.report.downloads', 'true')
+        try {
+            Grape.@instance = null
+            def loader = new GroovyClassLoader()
+            // request conf="other" which should resolve to artifact "baz-1.2.3.jar"
+            def uris = Grape.resolve(classLoader:loader, validate:false, [group:'foo', module:'bar', version:'1.2.3', conf:'other'])
+
+            def jars = uris.collect { uri -> uri.path.split('/')[-1] } as Set
+            assert 'baz-1.2.3.jar' in jars
+            assert 'bar-1.2.3.jar' !in jars
+        } finally {
+            tempDir.deleteDir()
+            Grape.@instance = null
+            System.clearProperty('grape.config')
+            System.clearProperty('groovy.grape.report.downloads')
+        }
+    }
+
     @Test
     void testClassifier() {
         def shell = new GroovyShell(new GroovyClassLoader())