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

com.vgaidarji.dependencies.overview.writer.JsonWriter.kt Maven / Gradle / Ivy

Go to download

Generates project dependencies overview report (JSON, Markdown, etc.) from project dependencies

There is a newer version: 1.0.1
Show newest version
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