-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve transitive dependency resolution for modules
- Loading branch information
Showing
21 changed files
with
356 additions
and
612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/kotlin/ch/addere/dga/app/infrastructure/factory/CoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ch.addere.dga.app.infrastructure.factory | ||
|
||
import ch.addere.dga.core.application.service.DependencySearchService | ||
import ch.addere.dga.core.application.service.DependencySearchServiceImpl | ||
import org.koin.core.module.dsl.bind | ||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.dsl.module | ||
|
||
val coreModule = module { | ||
singleOf(::DependencySearchServiceImpl) { bind<DependencySearchService>() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
core/src/main/kotlin/ch/addere/dga/core/application/service/DependencySearchService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ch.addere.dga.core.application.service | ||
|
||
import ch.addere.dga.core.domain.model.Configuration | ||
import ch.addere.dga.core.domain.model.Dependency | ||
import ch.addere.dga.core.domain.model.Module | ||
|
||
interface DependencySearchService { | ||
|
||
/** | ||
* Returns all dependencies that have modules requiring [module]. | ||
*/ | ||
fun findAllDependenciesDependingOnModule( | ||
module: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> | ||
|
||
/** | ||
* Returns all dependencies which are required in order [module] can work. | ||
*/ | ||
fun findAllDependenciesUsedByModule( | ||
module: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> | ||
} |
70 changes: 70 additions & 0 deletions
70
core/src/main/kotlin/ch/addere/dga/core/application/service/DependencySearchServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ch.addere.dga.core.application.service | ||
|
||
import ch.addere.dga.core.domain.DependencyRepository | ||
import ch.addere.dga.core.domain.model.Configuration | ||
import ch.addere.dga.core.domain.model.Dependency | ||
import ch.addere.dga.core.domain.model.Module | ||
|
||
class DependencySearchServiceImpl(private val dependencyRepository: DependencyRepository) : | ||
DependencySearchService { | ||
|
||
override fun findAllDependenciesDependingOnModule( | ||
module: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> { | ||
return dependenciesWithDestination(module, withConfigurations) | ||
} | ||
|
||
override fun findAllDependenciesUsedByModule( | ||
module: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> { | ||
return dependenciesWithOrigin(module, withConfigurations) | ||
} | ||
|
||
private fun dependenciesWithDestination( | ||
destination: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> { | ||
val allDependenciesWithSameDestination: Set<Dependency> = | ||
dependencyRepository.getAllDependencies() | ||
.filter { dependency -> | ||
dependency.destination == destination && withConfigurations.contains( | ||
dependency.configuration | ||
) | ||
} | ||
.toSet() | ||
|
||
return if (allDependenciesWithSameDestination.isEmpty()) { | ||
emptySet() | ||
} else { | ||
allDependenciesWithSameDestination | ||
.flatMap { dependenciesWithDestination(it.origin, withConfigurations) } | ||
.toSet() union allDependenciesWithSameDestination | ||
} | ||
} | ||
|
||
private fun dependenciesWithOrigin( | ||
origin: Module, | ||
withConfigurations: Collection<Configuration> | ||
): Set<Dependency> { | ||
println("call with origin = $origin") | ||
val allDependenciesWithSameOrigin: Set<Dependency> = | ||
dependencyRepository.getAllDependencies() | ||
.filter { dependency -> | ||
dependency.origin == origin && withConfigurations.contains( | ||
dependency.configuration | ||
) | ||
} | ||
.toSet() | ||
println(allDependenciesWithSameOrigin.joinToString(", ")) | ||
|
||
return if (allDependenciesWithSameOrigin.isEmpty()) { | ||
emptySet() | ||
} else { | ||
allDependenciesWithSameOrigin | ||
.flatMap { dependenciesWithOrigin(it.destination, withConfigurations) } | ||
.toSet() union allDependenciesWithSameOrigin | ||
} | ||
} | ||
} |
Oops, something went wrong.