com.vgaidarji.dependencies.overview.writer.JsonWriter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependencies-overview Show documentation
Show all versions of dependencies-overview Show documentation
Generates project dependencies overview report (JSON, Markdown, etc.) from project dependencies
package com.vgaidarji.dependencies.overview.writer
import groovy.json.JsonOutput
import org.gradle.api.artifacts.ResolvedModuleVersion
open class JsonWriter : DependenciesWriter> {
companion object {
const val OUTPUT_FILE_NAME = "DEPENDENCIES-OVERVIEW.json"
const val PARENT_TAG = "dependencies"
}
override fun write(artifacts: List) {
// TODO parametrize task and print to console conditionally
writeToFile(OUTPUT_FILE_NAME, artifactsToJson(artifacts))
}
override fun write(folder: String?, artifacts: List) {
writeToFile(folder, OUTPUT_FILE_NAME, artifactsToJson(artifacts))
}
private fun artifactsToJson(artifacts: List): String {
var json = "{\n\"$PARENT_TAG\": ["
artifacts.forEachIndexed { index, resolvedModuleVersion ->
if (index > 0) json = json.plus(",")
json = json.plus(JsonOutput.toJson(resolvedModuleVersion.id))
}
return JsonOutput.prettyPrint(json.plus("]\n}"))
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy