Skip to content

Commit

Permalink
Change implementation to protobuf-javalite
Browse files Browse the repository at this point in the history
  • Loading branch information
iselo committed Sep 2, 2023
1 parent 3ef21c2 commit 80cf140
Show file tree
Hide file tree
Showing 29 changed files with 349 additions and 251 deletions.
14 changes: 12 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
dependencies {
implementation(kotlin("stdlib"))
implementation(gradleApi())
implementation("com.google.protobuf:protobuf-java:3.24.1")
implementation("com.google.protobuf:protobuf-javalite:3.24.2")
}

kotlin {
Expand All @@ -21,6 +21,16 @@ kotlin {

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.24.1"
artifact = "com.google.protobuf:protoc:3.24.2"
}

generateProtoTasks {
ofSourceSet("main").forEach { task ->
task.builtins {
getByName("java") {
option("lite")
}
}
}
}
}
30 changes: 17 additions & 13 deletions buildSrc/src/main/kotlin/co/raccoons/local/gradle/BuildWorkflow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,57 @@ import org.gradle.api.Project
* Gradle build configurator.
*/
object BuildWorkflow {

/**
* 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 {
fun of(project: Project): BuildConfigurationHandler {
/** inheritDoc */
class Handler(private val project: Project) : BuildConfigurationHandler {
/** inheritDoc */
override fun use(plugin: Plugin<Project>): ConfigurationHandler {
override fun use(plugin: Plugin<Project>): BuildConfigurationHandler {
plugin.apply(this.project)
return this
}

/** inheritDoc */
override fun setGroup(group: String): ConfigurationHandler {
override fun setGroup(group: String): BuildConfigurationHandler {
this.project.group = group
return this
}

/** inheritDoc */
override fun setVersion(version: String): ConfigurationHandler {
override fun setVersion(version: String): BuildConfigurationHandler {
this.project.version = version
return this
}
}
return BuildConfigurationHandler(project)

return Handler(project)
}

interface ConfigurationHandler {
/**
* Build configuration handler that applies configuration to a project.
*/
interface BuildConfigurationHandler {

/**
* Puts plugin into operation
*/
fun use(plugin: Plugin<Project>): ConfigurationHandler
fun use(plugin: Plugin<Project>): BuildConfigurationHandler

/**
* Sets the group of this project.
*
* @param group The group of this project.
*/
fun setGroup(group: String): ConfigurationHandler
fun setGroup(group: String): BuildConfigurationHandler

/**
* Sets the version of this project.
*
* @param version The version of this project.
*/
fun setVersion(version: String): ConfigurationHandler
fun setVersion(version: String): BuildConfigurationHandler
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,64 @@ import org.gradle.api.Project
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleExtension

private const val CHECKSTYLE_PLUGIN_ID = "checkstyle"

/**
* Checkstyle plugin configuration.
*/
class CheckstyleConfiguration(
private val toolVersion: String,
private val reportFormats: List<CheckstyleReportFormat>
) : Plugin<Project> {

override fun apply(project: Project) {
this.setupPlugin(project)
this.enableReports(project)
}

private fun setupPlugin(project: Project) {
project.plugins.apply(CHECKSTYLE_PLUGIN_ID)
project.extensions
.getByType(CheckstyleExtension::class.java)
.toolVersion = this.toolVersion
}

private fun enableReports(project: Project) {
project.tasks
.withType(Checkstyle::class.java)
.configureEach { checkstyle ->
for (format in this.reportFormats) {
format.subscribeTo(checkstyle.reports)
}
}
}

companion object {

private const val CHECKSTYLE_PLUGIN_ID = "checkstyle"

/** Returns new plugin configuration builder. */
fun newBuilder() = Builder()

/** The configuration builder */
class Builder {

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

/** Sets Checkstyle tool version. */
fun setVersion(version: String): Builder {
this.toolVersion = version
return this
}

/** Enables Checkstyle report format. */
fun enable(reportFormat: CheckstyleReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}

/** Returns new Checkstyle plugin configuration. */
fun build() = CheckstyleConfiguration(this.toolVersion, this.enabledFormats)
}
}

/** @inheritDoc */
override fun apply(project: Project) {
this.setupPlugin(project)
this.enableReports(project)
}

private fun setupPlugin(project: Project) {
project.plugins.apply(CHECKSTYLE_PLUGIN_ID)
project.extensions
.getByType(CheckstyleExtension::class.java)
.toolVersion = this.toolVersion
}

private fun enableReports(project: Project) {
project.tasks
.withType(Checkstyle::class.java)
.configureEach { checkstyle ->
for (format in this.reportFormats) {
format.subscribeTo(checkstyle.reports)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import org.gradle.api.plugins.quality.CheckstyleReports
enum class CheckstyleReportFormat {

HTML {
/**@inheritDoc */
override fun subscribeTo(checkstyleReports: CheckstyleReports) {
checkstyleReports.html.required.set(true)
}
},

XML {
/**@inheritDoc */
override fun subscribeTo(checkstyleReports: CheckstyleReports) {
checkstyleReports.xml.required.set(true)
}
};

/** Subscribes to generate report type. */
abstract fun subscribeTo(checkstyleReports: CheckstyleReports)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,41 @@ import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.testing.jacoco.tasks.JacocoReport

private const val JACOCO_PLUGIN_ID = "jacoco"
/**
* Jacoco plugin configuration.
*/
class JacocoConfiguration private constructor(
private val reportFormats: List<JacocoReportFormat>
) : Plugin<Project> {

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

private const val JACOCO_PLUGIN_ID = "jacoco"

/** Returns new plugin configuration builder. */
fun newBuilder() = Builder()

/** The configuration builder */
class Builder {

private val enabledFormats = mutableListOf<JacocoReportFormat>()

/** Enables Jacoco report format. */
fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}

/** Returns new Jacoco plugin configuration. */
fun build() = JacocoConfiguration(this.enabledFormats)
}
}

/** @inheritDoc */
override fun apply(project: Project) {
this.setupPlugin(project)
this.enableReports(project)
this.addTaskFinalizer(project)
}

private fun setupPlugin(project: Project) {
Expand All @@ -28,29 +55,12 @@ class JacocoConfiguration private constructor(private val reportFormats: List<Ja
format.subscribeTo(jacocoReport.reports)
}
}
}

private fun addTaskFinalizer(project: Project) {
project.tasks
.withType(Test::class.java) { test ->
test.finalizedBy(project.tasks.withType(JacocoReport::class.java))
}
}

companion object {
/**
* Returns new JacocoConfigurationBuilder instance.
*/
fun newBuilder() = Builder()

class Builder {

private val enabledFormats = mutableListOf<JacocoReportFormat>()

fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}

fun build() = JacocoConfiguration(this.enabledFormats)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import org.gradle.testing.jacoco.tasks.JacocoReportsContainer
enum class JacocoReportFormat {

HTML {
/**@inheritDoc */
override fun subscribeTo(jacocoReportContainer: JacocoReportsContainer) {
jacocoReportContainer.html.required.set(true);
}
},

XML {
/**@inheritDoc */
override fun subscribeTo(jacocoReportContainer: JacocoReportsContainer) {
jacocoReportContainer.xml.required.set(true);
}
},

CSV {
/**@inheritDoc */
override fun subscribeTo(jacocoReportContainer: JacocoReportsContainer) {
jacocoReportContainer.csv.required.set(true);
}
};

/** Subscribes to generate report type. */
abstract fun subscribeTo(jacocoReportContainer: JacocoReportsContainer)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023, Raccoons. Developing simple way to change.
*
* @license MIT
*/

package co.raccoons.local.gradle.java

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

/**
* The scopes of the dependencies.
*/
internal class DependencyConfiguration : Plugin<Project> {

private val dependencyScopes = mutableMapOf<String, MutableList<String>>()

/** @inheritDoc */
override fun apply(project: Project) {
for ((configurationScope, dependencies) in dependencyScopes) {
for (dependency in dependencies) {
project.dependencies.add(configurationScope, dependency)
}
}
}

/** Adds dependency to the corresponding configuration scope. */
fun add(dependency: Dependency): DependencyConfiguration {
this.dependencyScopes
.getOrPut(dependency.configurationName()) {
mutableListOf()
}
.add(dependency.dependencyNotation().toString())

return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package co.raccoons.local.gradle.java

class DependencyNotation(
data class DependencyNotation(
private val group: String,
private val name: String,
private val version: String
Expand Down

This file was deleted.

Loading

0 comments on commit 80cf140

Please sign in to comment.