-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: java templates generator plugin
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/su/plo/voice/plugin/JavaTemplatesExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package su.plo.voice.plugin | ||
|
||
open class JavaTemplatesExtension { | ||
|
||
var inputs: Map<String, String> = emptyMap() | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/su/plo/voice/plugin/java-templates.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package su.plo.voice.plugin | ||
|
||
import org.gradle.plugins.ide.idea.model.IdeaModel | ||
import org.gradle.plugins.ide.idea.model.IdeaProject | ||
import org.jetbrains.gradle.ext.ProjectSettings | ||
import org.jetbrains.gradle.ext.TaskTriggersConfig | ||
import org.jetbrains.gradle.ext.taskTriggers | ||
|
||
plugins { | ||
java | ||
id("org.jetbrains.gradle.plugin.idea-ext") | ||
} | ||
|
||
val extension = project.extensions.create("javaTemplates", JavaTemplatesExtension::class) | ||
|
||
val templateSource = file("src/main/java-templates") | ||
val templateDestination: Provider<Directory> = layout.buildDirectory.dir("generated/sources/java-templates") | ||
val generateTemplates = tasks.register<Copy>("generateTemplates") { | ||
val props = mutableMapOf( | ||
"version" to version | ||
) + extension.inputs | ||
|
||
inputs.properties(props) | ||
|
||
from(templateSource) | ||
into(templateDestination) | ||
expand(props) | ||
} | ||
|
||
sourceSets.main.get().java.srcDir(generateTemplates.map { it.outputs }) | ||
|
||
fun Project.idea(block: IdeaModel.() -> Unit) = | ||
(this as ExtensionAware).extensions.configure("idea", block) | ||
|
||
fun IdeaProject.settings(block: ProjectSettings.() -> Unit) = | ||
(this@settings as ExtensionAware).extensions.configure(block) | ||
|
||
val ProjectSettings.taskTriggers: TaskTriggersConfig | ||
get() = (this as ExtensionAware).extensions.getByName("taskTriggers") as TaskTriggersConfig | ||
|
||
rootProject.idea { | ||
project { | ||
settings { | ||
taskTriggers { | ||
afterSync(generateTemplates) | ||
beforeBuild(generateTemplates) | ||
} | ||
} | ||
} | ||
} |