diff --git a/build.gradle b/build.gradle index 53bd565..31fac9b 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,8 @@ contacts { } } +compileGroovy.groovyOptions.configurationScript = file('src/groovyCompile/groovycConfig.groovy') + dependencies { compile 'com.netflix.nebula:nebula-gradle-interop:latest.release' compile 'org.apache.maven:maven-model-builder:3.+' diff --git a/src/groovyCompile/groovycConfig.groovy b/src/groovyCompile/groovycConfig.groovy new file mode 100644 index 0000000..19ca2df --- /dev/null +++ b/src/groovyCompile/groovycConfig.groovy @@ -0,0 +1,6 @@ +import org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder +import groovy.transform.CompileStatic + +CompilerCustomizationBuilder.withConfig(configuration) { + ast(CompileStatic) +} \ No newline at end of file diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/provider/CustomRecommendationProvider.java b/src/main/groovy/netflix/nebula/dependency/recommender/provider/CustomRecommendationProvider.java index c147686..8e09f70 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/provider/CustomRecommendationProvider.java +++ b/src/main/groovy/netflix/nebula/dependency/recommender/provider/CustomRecommendationProvider.java @@ -1,7 +1,6 @@ package netflix.nebula.dependency.recommender.provider; import groovy.lang.Closure; - public class CustomRecommendationProvider extends AbstractRecommendationProvider { private Closure versionFunction; 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 1692cc8..a658aa7 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy +++ b/src/main/groovy/netflix/nebula/dependency/recommender/provider/DependencyLockProvider.groovy @@ -16,16 +16,16 @@ class DependencyLockProvider extends FileBasedRecommendationProvider { String getVersion(String org, String name) throws Exception { if (!recommendations) { input.withCloseable { - final locks = new JsonSlurper().parse(it) - final isDependencyLock4Format = locks.every { + final Map> locks = (Map>) new JsonSlurper().parse(it) + final boolean isDependencyLock4Format = locks.every { it.value.every { it.value instanceof Map } } recommendations = (isDependencyLock4Format ? locks.collectEntries { it.value } : locks).collectEntries { - [(it.key): it.value.locked] - } + [(it.key): it.value["locked"]] + } as Map } } recommendations[org + ':' + name] diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/provider/IvyRecommendationProvider.groovy b/src/main/groovy/netflix/nebula/dependency/recommender/provider/IvyRecommendationProvider.groovy index c95e644..5772664 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/provider/IvyRecommendationProvider.groovy +++ b/src/main/groovy/netflix/nebula/dependency/recommender/provider/IvyRecommendationProvider.groovy @@ -1,5 +1,6 @@ package netflix.nebula.dependency.recommender.provider +import groovy.transform.CompileDynamic import org.gradle.api.Project class IvyRecommendationProvider extends FileBasedRecommendationProvider { @@ -7,6 +8,7 @@ class IvyRecommendationProvider extends FileBasedRecommendationProvider { IvyRecommendationProvider(Project p) { super(p) } + @CompileDynamic @Override String getVersion(String org, String name) throws Exception { if (versionsByCoord == null) { @@ -23,7 +25,7 @@ class IvyRecommendationProvider extends FileBasedRecommendationProvider { @SuppressWarnings("unchecked") @Override - public InputStreamProvider setModule(Object dependencyNotation) { + InputStreamProvider setModule(Object dependencyNotation) { if (dependencyNotation == null) throw new IllegalArgumentException("Module may not be null") diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/publisher/MavenBomXmlGenerator.groovy b/src/main/groovy/netflix/nebula/dependency/recommender/publisher/MavenBomXmlGenerator.groovy index 1b91f18..5382596 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/publisher/MavenBomXmlGenerator.groovy +++ b/src/main/groovy/netflix/nebula/dependency/recommender/publisher/MavenBomXmlGenerator.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 Netflix, Inc. + * Copyright 2016-2019 Netflix, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,11 @@ * limitations under the License. */ package netflix.nebula.dependency.recommender.publisher + +import groovy.transform.CompileDynamic import netflix.nebula.dependency.recommender.ModuleNotationParser import org.gradle.api.Project import org.gradle.api.artifacts.Configuration -import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ModuleVersionIdentifier import org.gradle.api.artifacts.ResolvedDependency import org.gradle.api.publish.maven.MavenPublication @@ -30,7 +31,7 @@ class MavenBomXmlGenerator { } void fromConfigurations(Closure configurationsClosure) { - MavenPublication pub = configurationsClosure.delegate.delegate + MavenPublication pub = getMavenPublication(configurationsClosure) Iterable configurations @@ -38,13 +39,13 @@ class MavenBomXmlGenerator { if(configurationsRet instanceof Configuration) configurations = [(Configuration) configurationsRet] else if(Iterable.class.isAssignableFrom(configurationsRet.class)) - configurations = configurationsRet + configurations = configurationsRet as Iterable generateDependencyManagementXml(pub, { configurations.collect { getManagedDependencies(it) }.flatten() }) } void withDependencies(Closure dependenciesClosure) { - MavenPublication pub = dependenciesClosure.delegate.delegate + MavenPublication pub = getMavenPublication(dependenciesClosure) Iterable dependencies = null @@ -52,11 +53,12 @@ class MavenBomXmlGenerator { if(dependenciesRet instanceof String) dependencies = [(String) dependenciesRet] else if(Iterable.class.isAssignableFrom(dependenciesRet.class)) - dependencies = dependenciesRet + dependencies = dependenciesRet as Iterable generateDependencyManagementXml(pub, { dependencies.collect { ModuleNotationParser.parse(it) } }) } + @CompileDynamic protected static generateDependencyManagementXml(MavenPublication pub, Closure> deps) { pub.pom.withXml { Node root = it.asNode() @@ -78,6 +80,11 @@ class MavenBomXmlGenerator { } } + @CompileDynamic + private MavenPublication getMavenPublication(Closure configurationsClosure) { + return configurationsClosure.delegate.delegate + } + protected static Set getManagedDependencies(Configuration configuration) { getManagedDependenciesRecursive(configuration.resolvedConfiguration.firstLevelModuleDependencies, new HashSet())