Commit e554fd85 authored by Setako's avatar Setako

[Add] component list export

parent 21e08de3
...@@ -41,7 +41,7 @@ internal class ReactantCommandRegister( ...@@ -41,7 +41,7 @@ internal class ReactantCommandRegister(
command(::ReactantMainCommand) { command(::ReactantMainCommand) {
command(::ReactantComponentCommand) { command(::ReactantComponentCommand) {
command({ ReactantComponentListSubCommand(providerManager, containerManager) }) command({ ReactantComponentListSubCommand(providerManager, containerManager, jsonParserService, fileIOUploadService) })
} }
command(::ReactantEchoCommand) command(::ReactantEchoCommand)
......
...@@ -4,9 +4,13 @@ import dev.reactant.reactant.core.commands.ReactantPermissions ...@@ -4,9 +4,13 @@ import dev.reactant.reactant.core.commands.ReactantPermissions
import dev.reactant.reactant.core.component.container.ContainerManager import dev.reactant.reactant.core.component.container.ContainerManager
import dev.reactant.reactant.core.dependency.ProviderManager import dev.reactant.reactant.core.dependency.ProviderManager
import dev.reactant.reactant.core.dependency.injection.producer.ComponentProvider import dev.reactant.reactant.core.dependency.injection.producer.ComponentProvider
import dev.reactant.reactant.core.dependency.injection.producer.Provider
import dev.reactant.reactant.extra.command.ReactantCommand import dev.reactant.reactant.extra.command.ReactantCommand
import dev.reactant.reactant.extra.file.FileIOUploadService
import dev.reactant.reactant.extra.parser.GsonJsonParserService
import dev.reactant.reactant.utils.PatternMatchingUtils import dev.reactant.reactant.utils.PatternMatchingUtils
import dev.reactant.reactant.utils.formatting.MultiColumns import dev.reactant.reactant.utils.formatting.MultiColumns
import okhttp3.MediaType
import picocli.CommandLine import picocli.CommandLine
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.reflect.jvm.jvmErasure import kotlin.reflect.jvm.jvmErasure
...@@ -20,7 +24,9 @@ import kotlin.reflect.jvm.jvmName ...@@ -20,7 +24,9 @@ import kotlin.reflect.jvm.jvmName
) )
internal class ReactantComponentListSubCommand( internal class ReactantComponentListSubCommand(
val providerManager: ProviderManager, val providerManager: ProviderManager,
val containerManager: ContainerManager val containerManager: ContainerManager,
val jsonParserService: GsonJsonParserService,
val fileIOUploadService: FileIOUploadService
) : ReactantCommand() { ) : ReactantCommand() {
@CommandLine.Option(names = ["-r", "--is-running"], paramLabel = "IS_RUNNING", @CommandLine.Option(names = ["-r", "--is-running"], paramLabel = "IS_RUNNING",
...@@ -43,6 +49,10 @@ internal class ReactantComponentListSubCommand( ...@@ -43,6 +49,10 @@ internal class ReactantComponentListSubCommand(
description = ["Filtering Component class canonical name, wildcard is available"]) description = ["Filtering Component class canonical name, wildcard is available"])
var classNameWildcards: ArrayList<String> = arrayListOf(); var classNameWildcards: ArrayList<String> = arrayListOf();
@CommandLine.Option(names = ["-e", "--export"],
description = ["Export the file as json"])
var export: Boolean = false
private val listTable = MultiColumns.create { private val listTable = MultiColumns.create {
column { align = MultiColumns.Alignment.Right } column { align = MultiColumns.Alignment.Right }
column { maxLength = 50; overflowCutFromRight = false; } column { maxLength = 50; overflowCutFromRight = false; }
...@@ -66,8 +76,18 @@ internal class ReactantComponentListSubCommand( ...@@ -66,8 +76,18 @@ internal class ReactantComponentListSubCommand(
.filter { matchClassNameWildcards(it) } .filter { matchClassNameWildcards(it) }
.filter { matchContainerIdentifierWildcards(it.container.identifier) } .filter { matchContainerIdentifierWildcards(it.container.identifier) }
.toList() .toList()
.forEach { addToListTable(it) } .map { ComponentRow(it, showShortName, providerManager.blacklistedProviders) }
listTable.generate().forEach(stdout::out) .let {
if (export) {
stdout.out("Exporting components...")
jsonParserService.encode(it).flatMap {
fileIOUploadService.upload("component-list.json", it, MediaType.parse("application/json")!!)
}.subscribe { resp -> stdout.out("Exported and uploaded to ${resp.link}") }
} else {
it.forEach { addToListTable(it) }
listTable.generate().forEach(stdout::out)
}
}
} }
private fun matchClassNameWildcards(componentProvider: ComponentProvider<*>) = private fun matchClassNameWildcards(componentProvider: ComponentProvider<*>) =
...@@ -80,16 +100,26 @@ internal class ReactantComponentListSubCommand( ...@@ -80,16 +100,26 @@ internal class ReactantComponentListSubCommand(
PatternMatchingUtils.matchWildcard(wildcard, identifier) PatternMatchingUtils.matchWildcard(wildcard, identifier)
} }
private fun addToListTable(componentProvider: ComponentProvider<*>) { private fun addToListTable(componentRow: ComponentRow) {
listTable.rows.add(listOf<String>( listTable.rows.add(listOf(
componentProvider.hashCode().toString(36), componentRow.hashCode, componentRow.jvmName, componentRow.container, componentRow.state
componentProvider.productType.jvmErasure.let { if (showShortName) it.simpleName!! else it.jvmName },
componentProvider.container.identifier,
if (componentProvider.isInitialized()) "Running"
else if (providerManager.blacklistedProviders.contains(componentProvider)) "Blacklisted"
else if (componentProvider.catchedThrowable != null) "Error"
else if (!componentProvider.fulfilled) "Not Fulfilled" else ""
)) ))
} }
}
private data class ComponentRow(
val hashCode: String,
val jvmName: String,
val container: String,
val state: String
) {
constructor(componentProvider: ComponentProvider<*>, showShortName: Boolean, blacklist: HashSet<Provider>) : this(
componentProvider.hashCode().toString(36),
componentProvider.productType.jvmErasure.let { if (showShortName) it.simpleName!! else it.jvmName },
componentProvider.container.identifier,
if (componentProvider.isInitialized()) "Running"
else if (blacklist.contains(componentProvider)) "Blacklisted"
else if (componentProvider.catchedThrowable != null) "Error"
else if (!componentProvider.fulfilled) "Not Fulfilled" else ""
)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment