-
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.
- Loading branch information
Showing
14 changed files
with
241 additions
and
190 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
11 changes: 10 additions & 1 deletion
11
app/src/main/kotlin/ch/addere/dga/app/domain/model/CommandConfig.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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package ch.addere.dga.app.domain.model | ||
|
||
import ch.addere.dga.app.configuration.OutputOptions | ||
import ch.addere.dga.app.configuration.OutputOptions.OutputOptionOverviewOnly | ||
import java.io.File | ||
|
||
data class CommandConfig( | ||
val printer: (String) -> Unit, | ||
val gradleProjectPath: File, | ||
val filterConfig: FilterConfig, | ||
val outputConfig: OutputOptions | ||
) | ||
) { | ||
val hasActiveFilter: Boolean = | ||
filterConfig.modules.isNotEmpty() || | ||
filterConfig.originModules.isNotEmpty() || | ||
filterConfig.destinationModules.isNotEmpty() || | ||
filterConfig.configurations.isNotEmpty() || | ||
filterConfig.includeTransitiveDependencies | ||
val hasActiveOutput: Boolean = outputConfig != OutputOptionOverviewOnly | ||
} |
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
8 changes: 0 additions & 8 deletions
8
app/src/main/kotlin/ch/addere/dga/app/domain/model/OverviewData.kt
This file was deleted.
Oops, something went wrong.
92 changes: 0 additions & 92 deletions
92
app/src/main/kotlin/ch/addere/dga/app/domain/service/DependencyCommand.kt
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/src/main/kotlin/ch/addere/dga/app/domain/service/DependencyCommandHandler.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,35 @@ | ||
package ch.addere.dga.app.domain.service | ||
|
||
import ch.addere.dga.app.domain.model.CommandConfig | ||
import ch.addere.dga.app.domain.service.printer.ConsolePrinter | ||
import ch.addere.dga.core.domain.model.Dependency | ||
import ch.addere.dga.importer.application.service.GradleProjectLoader | ||
|
||
class DependencyCommandHandler( | ||
private val config: CommandConfig, | ||
private val printer: ConsolePrinter, | ||
private val gradleProjectLoader: GradleProjectLoader, | ||
private val projectOverviewPrinter: ProjectOverviewPrinter, | ||
private val filterService: FilterService, | ||
private val projectFilterPrinter: ProjectFilterPrinter, | ||
private val projectOutputPrinter: ProjectOutputPrinter, | ||
) { | ||
|
||
fun run() { | ||
val projectName: String = gradleProjectLoader.loadGradleProject(config.gradleProjectPath) | ||
projectOverviewPrinter.output(projectName) | ||
|
||
val relevantDependencies: Set<Dependency> = if (config.hasActiveFilter) { | ||
val filteredDependencies: Set<Dependency> = filterService.filter(config.filterConfig) | ||
projectFilterPrinter.output(filteredDependencies) | ||
filteredDependencies | ||
} else { | ||
filterService.allDependencies() | ||
} | ||
|
||
if (config.hasActiveOutput) { | ||
projectOutputPrinter.output(config.outputConfig, relevantDependencies) | ||
} | ||
printer.println() | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
app/src/main/kotlin/ch/addere/dga/app/domain/service/FilterService.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,68 @@ | ||
package ch.addere.dga.app.domain.service | ||
|
||
import ch.addere.dga.app.domain.model.FilterConfig | ||
import ch.addere.dga.core.domain.model.Dependency | ||
import ch.addere.dga.core.domain.model.FilteredConfiguration | ||
import ch.addere.dga.core.domain.model.FilteredModules | ||
import ch.addere.dga.core.domain.service.ConfigurationService | ||
import ch.addere.dga.core.domain.service.DependencyRelationService | ||
import ch.addere.dga.core.domain.service.DependencyService | ||
import ch.addere.dga.core.domain.service.ModuleService | ||
|
||
class FilterService( | ||
private val dependencyService: DependencyService, | ||
private val moduleService: ModuleService, | ||
private val configurationService: ConfigurationService, | ||
private val dependencyRelationService: DependencyRelationService, | ||
) { | ||
|
||
|
||
fun allDependencies(): Set<Dependency> { | ||
return dependencyService.filteredDependencies( | ||
FilteredModules(false, emptyList()), | ||
FilteredModules(false, emptyList()), | ||
FilteredModules(false, emptyList()), | ||
FilteredConfiguration(false, emptyList()) | ||
) | ||
} | ||
|
||
|
||
fun filter(filterConfig: FilterConfig): Set<Dependency> { | ||
val inputModules = filterConfig.modules | ||
val inputOrigin = filterConfig.originModules | ||
val inputDestination = filterConfig.destinationModules | ||
val inputConfigurations = filterConfig.configurations | ||
|
||
val filteredModules = inputModules.flatMap(moduleService::resolvePartialModuleName).toList() | ||
val filteredOrigin = inputOrigin.flatMap(moduleService::resolvePartialModuleName).toList() | ||
val filteredDestination = | ||
inputDestination.flatMap(moduleService::resolvePartialModuleName).toList() | ||
val filteredConfigurations = | ||
inputConfigurations.flatMap(configurationService::resolvePartialConfigurationName) | ||
.toList() | ||
|
||
var filteredDependencies: Set<Dependency> = | ||
dependencyService.filteredDependencies( | ||
FilteredModules(inputModules.isNotEmpty(), filteredModules), | ||
FilteredModules(inputOrigin.isNotEmpty(), filteredOrigin), | ||
FilteredModules(inputDestination.isNotEmpty(), filteredDestination), | ||
FilteredConfiguration(inputConfigurations.isNotEmpty(), filteredConfigurations) | ||
) | ||
|
||
if (filterConfig.includeTransitiveDependencies) { | ||
val configurationSet = filteredDependencies.map { it.configuration }.toSet() | ||
filteredDependencies = filteredDependencies.flatMap { dependency -> | ||
dependencyRelationService.allDependenciesOf( | ||
dependency.origin, | ||
configurationSet | ||
) union | ||
dependencyRelationService.allDependenciesOf( | ||
dependency.destination, | ||
configurationSet | ||
) | ||
}.toSet() | ||
} | ||
|
||
return filteredDependencies | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
app/src/main/kotlin/ch/addere/dga/app/domain/service/OverviewService.kt
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
app/src/main/kotlin/ch/addere/dga/app/domain/service/ProjectFilterPrinter.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,37 @@ | ||
package ch.addere.dga.app.domain.service | ||
|
||
import ch.addere.dga.app.domain.service.printer.ConsolePrinter | ||
import ch.addere.dga.core.domain.model.Dependency | ||
|
||
class ProjectFilterPrinter(private val printer: ConsolePrinter) { | ||
|
||
/** | ||
* Print filtered module and configuration information. | ||
*/ | ||
fun output(dependencies: Set<Dependency>) { | ||
val overviewData = filteredData(dependencies) | ||
printer.println() | ||
printer.println("Applying filter on data results in:") | ||
printer.println(String.format("%6d modules", overviewData.nofModules)) | ||
printer.println( | ||
String.format( | ||
"%6d dependency configurations (%d unique dependency configurations)", | ||
overviewData.nofDependencies, | ||
overviewData.nofUniqueDependencies | ||
) | ||
) | ||
} | ||
|
||
private fun filteredData(dependencies: Set<Dependency>): FilterData { | ||
val nofModules = dependencies.flatMap { setOf(it.origin, it.destination) }.toSet().size | ||
val nofDependencies = dependencies.map { it.configuration }.count() | ||
val nofUniqueDependencies = dependencies.map { it.configuration }.toSet().size | ||
return FilterData(nofModules, nofDependencies, nofUniqueDependencies) | ||
} | ||
|
||
private data class FilterData( | ||
val nofModules: Int, | ||
val nofDependencies: Int, | ||
val nofUniqueDependencies: Int | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/kotlin/ch/addere/dga/app/domain/service/ProjectOutputPrinter.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,35 @@ | ||
package ch.addere.dga.app.domain.service | ||
|
||
import ch.addere.dga.app.configuration.OutputOptions | ||
import ch.addere.dga.app.configuration.OutputOptions.OutputOptionConfigurations | ||
import ch.addere.dga.app.configuration.OutputOptions.OutputOptionMermaid | ||
import ch.addere.dga.app.configuration.OutputOptions.OutputOptionModules | ||
import ch.addere.dga.app.configuration.OutputOptions.OutputOptionOverviewOnly | ||
import ch.addere.dga.app.domain.service.printer.DependencyPrinter | ||
import ch.addere.dga.app.domain.service.printer.MermaidPrinter | ||
import ch.addere.dga.app.domain.service.printer.ModulePrinter | ||
import ch.addere.dga.core.domain.model.Dependency | ||
|
||
class ProjectOutputPrinter( | ||
private val dependencies: DependencyPrinter, | ||
private val mermaid: MermaidPrinter, | ||
private val modulePrinter: ModulePrinter, | ||
) { | ||
|
||
/** | ||
* Print analysed and filtered Gradle project according to the specified output option. | ||
*/ | ||
fun output(outputConfig: OutputOptions, relevantDependencies: Set<Dependency>) { | ||
when (outputConfig) { | ||
OutputOptionOverviewOnly -> return | ||
OutputOptionModules -> modulePrinter.printToConsole(extractModules(relevantDependencies)) | ||
OutputOptionConfigurations -> dependencies.printToConsole( | ||
configurationAndCount( | ||
relevantDependencies | ||
) | ||
) | ||
|
||
OutputOptionMermaid -> mermaid.printToConsole(relevantDependencies) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/kotlin/ch/addere/dga/app/domain/service/ProjectOverviewPrinter.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,43 @@ | ||
package ch.addere.dga.app.domain.service | ||
|
||
import ch.addere.dga.app.domain.service.printer.ConsolePrinter | ||
import ch.addere.dga.core.domain.service.DependencyService | ||
import ch.addere.dga.core.domain.service.ModuleService | ||
|
||
class ProjectOverviewPrinter( | ||
private val printer: ConsolePrinter, | ||
private val moduleService: ModuleService, | ||
private val dependencyService: DependencyService, | ||
) { | ||
|
||
/** | ||
* Print common information about the whole analysed Gradle project. | ||
*/ | ||
fun output(projectName: String) { | ||
val overviewData = overviewData(projectName) | ||
printer.println() | ||
printer.println("Analyse project \"${overviewData.projectName}\"") | ||
printer.println(String.format("%6d modules", overviewData.nofModules)) | ||
printer.println( | ||
String.format( | ||
"%6d dependency configurations (%d unique dependency configurations)", | ||
overviewData.nofDependencies, | ||
overviewData.nofUniqueDependencies | ||
) | ||
) | ||
} | ||
|
||
private fun overviewData(projectName: String): OverviewData { | ||
val nofModules = moduleService.nofModules() | ||
val nofDependencies = dependencyService.nofProjectDependencies() | ||
val nofUniqueDependencies = dependencyService.nofUniqueConfigurations() | ||
return OverviewData(projectName, nofModules, nofDependencies, nofUniqueDependencies) | ||
} | ||
|
||
private data class OverviewData( | ||
val projectName: String, | ||
val nofModules: Int, | ||
val nofDependencies: Int, | ||
val nofUniqueDependencies: Int | ||
) | ||
} |
Oops, something went wrong.