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

com.freenow.sauron.plugins.protocw.DefaultValidator.kt Maven / Gradle / Ivy

The newest version!
package com.freenow.sauron.plugins.protocw

import arrow.core.Either
import arrow.core.extensions.fx
import java.nio.file.Files
import java.nio.file.Path

class DefaultValidator : Validator {
    override fun check(repository: Path): Either {

        return Either.fx {
            !checkRepositoryExists(repository)
            !checkNeedsProtoc(repository)
            Unit
        }
    }

    private fun checkRepositoryExists(repository: Path): Either {
        return Either.cond(Files.isDirectory(repository),
            { Unit },
            { "Repository is not a directory" }
        )
    }

    private fun checkNeedsProtoc(repository: Path): Either {
        return Either.fx {
            val pom = repository.resolve("pom.xml")
            val reader = !Either.cond(Files.exists(pom),
                { Files.newBufferedReader(pom) },
                { "POM does not exist" }
            )

            !Either.cond(reader.lines().anyMatch { it.contains("protobuf-maven-plugin") },
                { Unit },
                { "Has no protobuf-maven-plugin plugin" }
            )
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy