All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.leandroborgesferreira.dagcommand.logic.ProjectParse.kt Maven / Gradle / Ivy

There is a newer version: 1.7.0
Show newest version
package com.github.leandroborgesferreira.dagcommand.logic

import com.github.leandroborgesferreira.dagcommand.domain.Config
import com.github.leandroborgesferreira.dagcommand.enums.ModuleType
import com.github.leandroborgesferreira.dagcommand.enums.PlugginType
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency

fun parseAdjacencyList(project: Project, config: Config): Map> =
    project.subprojects
        .filter { subProject -> subProject.isModuleType(config.filter) }
        .map { subProject ->
            subProject.name to subProject.parseDependencies().map { dep -> dep.name }.toSet()
        }
        .toMap()
        .let(::revertAdjacencyList)

private fun Project.isModuleType(moduleType: ModuleType): Boolean {
    val isLibrary = project.plugins.hasPlugin(PlugginType.Library.value)
    val isApplication = project.plugins.hasPlugin(PlugginType.Application.value)

    return when (moduleType) {
        ModuleType.Library -> isLibrary
        ModuleType.Application -> isApplication
        else -> true
    }
}

private fun Project.parseDependencies(): List =
    project.configurations
        .flatMap { configuration ->
            configuration
                .dependencies
                .withType(ProjectDependency::class.java)
                .map { projectDependency ->
                    projectDependency.dependencyProject
                }
        }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy