You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/11/09 07:18:41 UTC
[groovy] 10/12: GROOVY-8372: pass remote (not local) conf to
addDependencyArtifact
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit dddd5ff74bbaeb4d654d47fa09fc18e4f5c46904
Author: Eric Milles <er...@thomsonreuters.com>
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
(cherry picked from commit 16280716c22848df5ebbef799f3ec1f2b5c99322)
---
src/main/groovy/groovy/grape/GrapeIvy.groovy | 18 ++++-----
src/test/groovy/grape/GrapeIvyTest.groovy | 56 +++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 10 deletions(-)
diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index 64fef55..cb1d802 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -423,23 +423,23 @@ 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 to dependency descriptor
+ def dad = new DefaultDependencyArtifactDescriptor(dd, grabRecord.mrid.name, grabRecord.type ?: 'jar', grabRecord.ext ?: 'jar', null, grabRecord.classifier ? [classifier: grabRecord.classifier] : null)
+ confs.each { conf -> 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..635e5b4 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,60 @@ 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')
+ 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 {
+ System.clearProperty('grape.config')
+ Grape.@instance = null
+ tempDir.deleteDir()
+ }
+ }
+
@Test
void testClassifier() {
def shell = new GroovyShell(new GroovyClassLoader())