Skip to content

Commit

Permalink
Avoid builders interface
Browse files Browse the repository at this point in the history
  • Loading branch information
iselo committed Aug 23, 2023
1 parent 3d56a39 commit 75b70e9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,24 @@ class CheckstyleConfiguration(

companion object {

fun newBuilder(): CheckstyleConfigurationBuilder {
class Builder : CheckstyleConfigurationBuilder {
fun newBuilder() = Builder()

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

override fun setVersion(version: String): Builder {
this.toolVersion = version
return this
}

override fun enable(reportFormat: CheckstyleReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}
private var toolVersion = Presets.CHECKSTYLE.version()
private val enabledFormats = mutableListOf<CheckstyleReportFormat>()

override fun build() =
CheckstyleConfiguration(this.toolVersion, this.enabledFormats)
fun setVersion(version: String): Builder {
this.toolVersion = version
return this
}

return Builder()
}

interface CheckstyleConfigurationBuilder {

fun setVersion(version: String): CheckstyleConfigurationBuilder

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

fun build(): CheckstyleConfiguration
fun build() = CheckstyleConfiguration(this.toolVersion, this.enabledFormats)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,18 @@ class JacocoConfiguration private constructor(private val reportFormats: List<Ja
/**
* Returns new JacocoConfigurationBuilder instance.
*/
fun newBuilder(): JacocoConfigurationBuilder {
class Builder : JacocoConfigurationBuilder {
fun newBuilder() = Builder()

private val enabledFormats = mutableListOf<JacocoReportFormat>()
class Builder {

override fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}
private val enabledFormats = mutableListOf<JacocoReportFormat>()

override fun build() = JacocoConfiguration(this.enabledFormats)
fun enable(reportFormat: JacocoReportFormat): Builder {
this.enabledFormats.add(reportFormat)
return this
}
return Builder()
}

interface JacocoConfigurationBuilder {

fun enable(reportFormat: JacocoReportFormat): JacocoConfigurationBuilder

fun build(): JacocoConfiguration
fun build() = JacocoConfiguration(this.enabledFormats)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,22 @@ class JavaLibraryConfiguration private constructor(private val dependencyScope:
dependencyScope.apply(project)
}

companion object{
companion object {

fun default() = this.newBuilder().build()

fun newBuilder(): JavaLibraryConfigurationBuilder {
class Builder: JavaLibraryConfigurationBuilder{
fun newBuilder() = Builder()

private val dependencyScope = DependencyScope()
class Builder {

override fun addDependency(dependency: Dependency): Builder {
this.dependencyScope.add(dependency)
return this
}
private val dependencyScope = DependencyScope()

override fun build() = JavaLibraryConfiguration(this.dependencyScope)
fun addDependency(dependency: Dependency): Builder {
this.dependencyScope.add(dependency)
return this
}
return Builder()
}

interface JavaLibraryConfigurationBuilder {

fun addDependency(dependency: Dependency):JavaLibraryConfigurationBuilder

fun build(): JavaLibraryConfiguration
fun build() = JavaLibraryConfiguration(this.dependencyScope)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,18 @@ class JavadocConfiguration private constructor(private val tags: List<String>) :

companion object {

fun newBuilder(): JavadocConfigurationBuilder {
fun newBuilder() = Builder()

class Builder {

class Builder : JavadocConfigurationBuilder {
private val tags = mutableListOf<String>()

private val tags = mutableListOf<String>()

override fun addTag(tag: JavadocTag): Builder {
this.tags.add(tag.toString())
return this
}

override fun build() = JavadocConfiguration(this.tags.toList())
fun addTag(tag: JavadocTag): Builder {
this.tags.add(tag.toString())
return this
}

return Builder()
}

interface JavadocConfigurationBuilder {

fun addTag(tag: JavadocTag): JavadocConfigurationBuilder

fun build(): JavadocConfiguration
fun build() = JavadocConfiguration(this.tags.toList())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class MavenPublishConfiguration(private val publication: Publication) : Plugin<P
this.createMavenPublication(project)
}


private fun setupPlugin(project: Project) {
project.plugins.apply(MAVEN_PUBLISH_PLUGIN_ID)
}
Expand Down Expand Up @@ -65,4 +64,4 @@ class MavenPublishConfiguration(private val publication: Publication) : Plugin<P
}
}
}
}
}
1 change: 1 addition & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BuildWorkflow.of(project)
.use(Configuration.checkstyle())
.use(Configuration.mavenPublish())


internal object Configuration {

fun testNG() =
Expand Down

0 comments on commit 75b70e9

Please sign in to comment.