From 267e239e52eef29b053b0202e5346d4e8c92fbf6 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Mon, 20 Aug 2018 23:39:00 +0300 Subject: [PATCH] Pill: Refactoring, introduce a generic predicate in DependencyMapper --- buildSrc/src/main/kotlin/pill/context.kt | 22 ++++++++++++++++++---- buildSrc/src/main/kotlin/pill/parser.kt | 6 +----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/buildSrc/src/main/kotlin/pill/context.kt b/buildSrc/src/main/kotlin/pill/context.kt index 82e594f1ffc..756ab67fb2a 100644 --- a/buildSrc/src/main/kotlin/pill/context.kt +++ b/buildSrc/src/main/kotlin/pill/context.kt @@ -4,12 +4,26 @@ package org.jetbrains.kotlin.pill import org.gradle.api.artifacts.* class DependencyMapper( - val group: String, - val module: String, + val predicate: (ResolvedDependency) -> Boolean, vararg val configurations: String, - val version: String? = null, val mapping: (ResolvedDependency) -> MappedDependency? -) +) { + constructor( + group: String, + module: String, + vararg configurations: String, + version: String? = null, + mapping: (ResolvedDependency) -> MappedDependency? + ) : this( + { dep -> + dep.moduleGroup == group + && dep.moduleName == module + && (version == null || dep.moduleVersion == version) + }, + configurations = *configurations, + mapping = mapping + ) +} class MappedDependency(val main: PDependency?, val deferred: List = emptyList()) diff --git a/buildSrc/src/main/kotlin/pill/parser.kt b/buildSrc/src/main/kotlin/pill/parser.kt index 98c8ac2586d..eb18d31ab32 100644 --- a/buildSrc/src/main/kotlin/pill/parser.kt +++ b/buildSrc/src/main/kotlin/pill/parser.kt @@ -363,11 +363,7 @@ private fun ParserContext.parseDependencies(project: Project, forTests: Boolean) val dependency = (dependencyInfo as DependencyInfo.ResolvedDependencyInfo).dependency for (mapper in dependencyMappers) { - if (dependency.moduleGroup == mapper.group - && dependency.moduleName == mapper.module - && dependency.configuration in mapper.configurations - && (mapper.version == null || dependency.moduleVersion == mapper.version) - ) { + if (dependency.configuration in mapper.configurations && mapper.predicate(dependency)) { val mappedDependency = mapper.mapping(dependency) if (mappedDependency != null) {