Skip to content

Commit

Permalink
Merge pull request #6 from noel-yap/handle-new-dependency-lock-format
Browse files Browse the repository at this point in the history
Dependency Lock v4 file format handled correctly.
  • Loading branch information
jkschneider committed Jan 11, 2016
2 parents 168adf8 + 0363a75 commit cad78b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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'
}
}

0 comments on commit cad78b9

Please sign in to comment.