From 1df5d29e8f704bf7e4e1496ce98fda4ffa8d6cbd Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Wed, 24 Jul 2024 01:20:07 +0200 Subject: [PATCH] refactor(composer): Turn `toPackageReferences()` into an expression Signed-off-by: Frank Viernau --- .../composer/src/main/kotlin/Composer.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/plugins/package-managers/composer/src/main/kotlin/Composer.kt b/plugins/package-managers/composer/src/main/kotlin/Composer.kt index 37c6f2ee9aaa1..3b76517aab61f 100644 --- a/plugins/package-managers/composer/src/main/kotlin/Composer.kt +++ b/plugins/package-managers/composer/src/main/kotlin/Composer.kt @@ -153,12 +153,10 @@ class Composer( packageInfoForName: Map, virtualPackages: Set, dependencyBranch: List = emptyList() - ): Set { - val packageReferences = mutableSetOf() - + ): Set = getScopeDependencies(scopeName).filterNot { packageName -> packageName.isPlatformDependency() || packageName in virtualPackages // Virtual packages have no metadata. - }.forEach { packageName -> + }.mapNotNullTo(mutableSetOf()) { packageName -> val childInfo = packageInfoForName[packageName] ?: throw IOException("Could not find package info for $packageName") @@ -168,10 +166,10 @@ class Composer( "dependency tree: ${dependencyBranch.joinToString(" -> ")}." } - return@forEach + return@mapNotNullTo null } - packageReferences += PackageReference( + PackageReference( id = childInfo.toId(), dependencies = childInfo.toPackageReferences( SCOPE_NAME_REQUIRE, @@ -182,9 +180,6 @@ class Composer( ) } - return packageReferences - } - private fun parseProject(definitionFile: File, scopes: Set): Project { logger.info { "Parsing project metadata from '$definitionFile'..." }