diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy b/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy index 366d894..1c5ac0a 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy +++ b/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy @@ -15,8 +15,16 @@ class DependencyLockProvider extends FileBasedRecommendationProvider { @Override String getVersion(String org, String name) throws Exception { if(!recommendations) { - recommendations = new JsonSlurper().parse(input) - .collectEntries { [(it.key) : it.value.locked] } + final locks = new JsonSlurper().parse(input) + final isDependencyLock4Format = locks.every { + it.value.every { + it.value instanceof Map + } + } + + recommendations = (isDependencyLock4Format ? locks.collectEntries { it.value } : locks).collectEntries { + [(it.key) : it.value.locked] + } } recommendations[org + ':' + name] } diff --git a/src/test/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProviderSpec.groovy b/src/test/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProviderSpec.groovy index 043334a..68ac1b1 100644 --- a/src/test/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProviderSpec.groovy +++ b/src/test/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProviderSpec.groovy @@ -7,7 +7,7 @@ import spock.lang.Specification class DependencyLockProviderSpec extends Specification { @Rule TemporaryFolder projectDir - def 'dependency locks provide recommendations'() { + def 'v3 dependency locks provide recommendations'() { setup: def recommender = new DependencyLockProvider() @@ -26,4 +26,26 @@ class DependencyLockProviderSpec extends Specification { recommender.getVersion('commons-logging', 'commons-logging') == '1.1.1' recommender.getVersion('commons-configuration', 'commons-configuration') == '1.1.2' } + + def 'v4 dependency locks provide recommendations'() { + setup: + def recommender = new DependencyLockProvider() + + def file = projectDir.newFile() + file << ''' + { + "compile": { + "commons-logging:commons-logging": { "locked": "1.1.1", "requested": "1.1.+" }, + "commons-configuration:commons-configuration": { "locked": "1.1.2" } + } + } + ''' + + when: + recommender.setFile(file) + + then: + recommender.getVersion('commons-logging', 'commons-logging') == '1.1.1' + recommender.getVersion('commons-configuration', 'commons-configuration') == '1.1.2' + } }