Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
iselo committed Aug 20, 2023
1 parent edb1026 commit 3bc092a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 41 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build.gradle.kts
---

~~~Kotlin
import co.raccoons.local.gradle.BuildConfiguration
import co.raccoons.local.gradle.GradleBuild
import co.raccoons.local.gradle.checkstyle.CheckstyleConfiguration
import co.raccoons.local.gradle.checkstyle.CheckstyleReportFormat
import co.raccoons.local.gradle.jacoco.JacocoConfiguration
Expand All @@ -27,42 +27,42 @@ import co.raccoons.local.gradle.javadoc.JavadocTag
import co.raccoons.local.gradle.repository.Repository
import co.raccoons.local.gradle.test.TestNG

BuildConfiguration.of(project)
GradleBuild.of(project)
.use(Repository.MAVEN_CENTRAL)
.use(Repository.MAVEN_LOCAL)
.use(Configuration.javaLibrary())
.use(Configuration.javaLibrary)
.use(Version.JAVA.of(20))
.use(Configuration.testNG())
.use(Configuration.jacoco())
.use(Configuration.javadoc())
.use(Configuration.checkstyle())
.use(Configuration.testNG)
.use(Configuration.jacoco)
.use(Configuration.javadoc)
.use(Configuration.checkstyle)

class Configuration {
internal class Configuration {
companion object {

fun javaLibrary() =
val javaLibrary =
JavaLibraryConfiguration.default()

fun testNG() =
val testNG =
TestNG.Builder()
.addDependency(TestImplementation("org.testng", "testng", "7.8.0"))
.addDependency(TestImplementation("org.slf4j", "slf4j-simple", "2.0.7"))
.build()

fun jacoco() =
val jacoco =
JacocoConfiguration.Builder()
.enable(JacocoReportFormat.HTML)
.enable(JacocoReportFormat.XML)
.build()

fun javadoc() =
val javadoc =
JavadocConfiguration.Builder()
.addTag(JavadocTag("apiNote", "API Note"))
.addTag(JavadocTag("implSpec", "Implementation Specification"))
.addTag(JavadocTag("implNote", "Implementation Note"))
.build()

fun checkstyle() =
val checkstyle =
CheckstyleConfiguration.Builder()
.setVersion("10.12.2")
.enable(CheckstyleReportFormat.HTML)
Expand Down

This file was deleted.

34 changes: 34 additions & 0 deletions buildSrc/src/main/kotlin/co/raccoons/local/gradle/GradleBuild.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package co.raccoons.local.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project

/**
* Gradle build configurator.
*/
class GradleBuild private constructor() {

companion object {

/**
* Returns build configuration handler of this project.
*/
fun of(project: Project): ConfigurationHandler {

/**
* Build configuration handler that applies configuration to project.
*/
class BuildConfigurationHandler(private val project: Project) : ConfigurationHandler {
override fun use(plugin: Plugin<Project>): ConfigurationHandler {
plugin.apply(this.project)
return this
}
}
return BuildConfigurationHandler(project)
}
}

fun interface ConfigurationHandler {
fun use(plugin: Plugin<Project>): ConfigurationHandler
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package co.raccoons.local.gradle

enum class Defaults(private val version: String) {
/**
* Plugins version
*/
enum class Presets(private val version: String) {
CHECKSTYLE("10.12.2");

fun version() = version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package co.raccoons.local.gradle.checkstyle

import co.raccoons.local.gradle.Defaults
import co.raccoons.local.gradle.Presets
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleExtension

private const val CHECKSTYLE = "checkstyle"
private const val CHECKSTYLE_PLUGIN_ID = "checkstyle"

class CheckstyleConfiguration(
private val toolVersion: String,
Expand All @@ -19,7 +19,7 @@ class CheckstyleConfiguration(
}

private fun setupPlugin(project: Project) {
project.plugins.apply(CHECKSTYLE)
project.plugins.apply(CHECKSTYLE_PLUGIN_ID)
val checkstyleExtension = project.extensions.getByType(CheckstyleExtension::class.java)
checkstyleExtension.toolVersion = this.toolVersion
}
Expand All @@ -36,7 +36,7 @@ class CheckstyleConfiguration(

class Builder {

private var toolVersion = Defaults.CHECKSTYLE.version()
private var toolVersion = Presets.CHECKSTYLE.version()
private val enabledFormats = mutableListOf<CheckstyleReportFormat>()

fun setVersion(version: String): Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.testing.jacoco.tasks.JacocoReport

private const val JACOCO = "jacoco"
private const val JACOCO_PLUGIN_ID = "jacoco"

class JacocoConfiguration(private val reportFormats: List<JacocoReportFormat>) : Plugin<Project> {

Expand All @@ -14,7 +14,7 @@ class JacocoConfiguration(private val reportFormats: List<JacocoReportFormat>) :
}

private fun setupPlugin(project: Project) {
project.plugins.apply(JACOCO)
project.plugins.apply(JACOCO_PLUGIN_ID)
}

private fun enableReports(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import org.gradle.api.Plugin
import org.gradle.api.Project

enum class Repository: Plugin<Project> {

MAVEN_CENTRAL {
override fun apply(project: Project) {
project.repositories.mavenCentral()
}
},

MAVEN_LOCAL {
override fun apply(project: Project) {
project.repositories.mavenLocal()
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import co.raccoons.local.gradle.BuildConfiguration
import co.raccoons.local.gradle.GradleBuild
import co.raccoons.local.gradle.checkstyle.CheckstyleConfiguration
import co.raccoons.local.gradle.checkstyle.CheckstyleReportFormat
import co.raccoons.local.gradle.jacoco.JacocoConfiguration
Expand All @@ -17,7 +17,7 @@ import co.raccoons.local.gradle.javadoc.JavadocTag
import co.raccoons.local.gradle.repository.Repository
import co.raccoons.local.gradle.test.TestNG

BuildConfiguration.of(project)
GradleBuild.of(project)
.use(Repository.MAVEN_CENTRAL)
.use(Repository.MAVEN_LOCAL)
.use(Configuration.javaLibrary)
Expand Down

0 comments on commit 3bc092a

Please sign in to comment.