Skip to content

Commit 59fb053

Browse files
authored
[Konvert] Convert AssertJGeneratorExtension class to Kotlin (#42)
This is a straight conversion with no functionality changes. Extracted from #29.
1 parent b257873 commit 59fb053

File tree

2 files changed

+106
-123
lines changed

2 files changed

+106
-123
lines changed

src/main/groovy/org/assertj/generator/gradle/tasks/config/AssertJGeneratorExtension.groovy

Lines changed: 0 additions & 123 deletions
This file was deleted.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2023. assertj-generator-gradle-plugin contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package org.assertj.generator.gradle.tasks.config
14+
15+
import org.assertj.assertions.generator.AssertionsEntryPointType
16+
import org.gradle.api.Action
17+
import org.gradle.api.Project
18+
import org.gradle.api.file.DirectoryProperty
19+
import org.gradle.api.model.ObjectFactory
20+
import org.gradle.api.tasks.SourceSet
21+
import org.gradle.kotlin.dsl.newInstance
22+
import javax.inject.Inject
23+
24+
/**
25+
* Defines useful parameters and options for configuration of the
26+
* {@link org.assertj.assertions.generator.AssertionGenerator}.
27+
*/
28+
open class AssertJGeneratorExtension @Inject internal constructor(
29+
objects: ObjectFactory,
30+
project: Project,
31+
sourceSet: SourceSet
32+
) {
33+
/**
34+
* Generate generating Soft Assertions entry point class.
35+
* @return templates value, never {@code null}
36+
*/
37+
val templates: Templates = objects.newInstance()
38+
39+
/**
40+
* Method used for improving configuration DSL
41+
* @return {@code this}
42+
*/
43+
fun templates(action: Action<in Templates>): AssertJGeneratorExtension {
44+
action.execute(templates)
45+
return this
46+
}
47+
48+
/**
49+
* Contains configuration regarding the "Assertion" entry point class generation. By default, only the "standard"
50+
* version is generated.
51+
*
52+
* See the
53+
* [assertj generator docs](http://joel-costigliola.github.io/assertj/assertj-assertions-generator.html#generated-entry-points)
54+
* on entry points.
55+
*
56+
* @return entry points configuration
57+
*/
58+
@Suppress("MaxLineLength")
59+
val entryPoints: EntryPointGeneratorOptions = objects.newInstance()
60+
61+
/**
62+
* Helper method for simplifying usage in build scripts
63+
* @param values Values to set
64+
*/
65+
fun setEntryPoints(vararg rest: AssertionsEntryPointType) {
66+
this.entryPoints.only(rest = rest)
67+
}
68+
69+
/**
70+
* Exposed for build scripts
71+
* @param values String values passed from a build script
72+
*/
73+
fun setEntryPoints(values: Collection<String>) {
74+
entryPoints.only(rest = values.toTypedArray())
75+
}
76+
77+
/**
78+
* Used to change "entry point" class generation.
79+
*
80+
* @param closure Applied via {@link org.gradle.util.ConfigureUtil#configure(Closure, Object)}
81+
* @return this
82+
*/
83+
fun entryPoints(action: Action<in EntryPointGeneratorOptions>): AssertJGeneratorExtension {
84+
action.execute(entryPoints)
85+
return this
86+
}
87+
88+
/**
89+
* The root directory where all generated files will be placed (within sub-folders for packages).
90+
* @return File the output directory for {@code sourceSet}
91+
*/
92+
val outputDir: DirectoryProperty = objects.directoryProperty()
93+
.convention(project.layout.buildDirectory.dir("generated-src/${sourceSet.name}-test/java"))
94+
95+
/**
96+
* Flag specifying whether to generate hierarchical assertions. The default is false.
97+
* @return true if generating hierarchical
98+
*/
99+
var hierarchical = false
100+
101+
/**
102+
* Skip generating classes, handy way to disable temporarily.
103+
* @return true if skipping this set
104+
*/
105+
var skip = false
106+
}

0 commit comments

Comments
 (0)