fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-tooling / yosql-tooling-gradle / src / main / java / wtf / metio / yosql / tooling / gradle / YoSqlPlugin.java
blobdb49641bca911b1f739f95cfae1af1fb78833bb1
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.tooling.gradle;
10 import org.gradle.api.Plugin;
11 import org.gradle.api.Project;
12 import org.gradle.api.file.ProjectLayout;
13 import org.gradle.api.model.ObjectFactory;
14 import org.gradle.api.plugins.JavaPlugin;
15 import org.gradle.api.plugins.JavaPluginExtension;
16 import org.gradle.api.tasks.SourceSet;
17 import org.gradle.api.tasks.compile.JavaCompile;
19 /**
20 * The YoSQL Gradle plugin. It configures the {@link YoSqlExtension} and registers the {@link GenerateCodeTask}.
22 public class YoSqlPlugin implements Plugin<Project> {
24 @Override
25 public void apply(final Project project) {
26 final var extension = project.getExtensions().create("yosql", YoSqlExtension.class);
27 configureConventions(extension, project.getLayout(), project.getObjects());
28 registerTask(project, extension);
29 configureSourceSets(project, extension);
32 private static void configureConventions(
33 final YoSqlExtension extension,
34 final ProjectLayout layout,
35 final ObjectFactory objects) {
36 extension.getAnnotations().configureConventions();
37 extension.getConverter().configureConventions(objects);
38 extension.getFiles().configureConventions(layout);
39 extension.getJava().configureConventions();
40 extension.getLogging().configureConventions();
41 extension.getNames().configureConventions();
42 extension.getRepositories().configureConventions();
43 extension.getResources().configureConventions();
46 private static void registerTask(final Project project, final YoSqlExtension extension) {
47 final var generate = project.getTasks().register("generateJavaCode",
48 GenerateCodeTask.class, new GenerateTaskConfiguration(extension));
49 project.getTasks().withType(JavaCompile.class, task -> task.doFirst("yosql",
50 new GenerateCodeAction(generate)));
53 private static void configureSourceSets(final Project project, final YoSqlExtension extension) {
54 project.getPlugins().withType(JavaPlugin.class, plugin -> project.getExtensions()
55 .getByType(JavaPluginExtension.class)
56 .getSourceSets()
57 .getByName(SourceSet.MAIN_SOURCE_SET_NAME)
58 .getJava()
59 .srcDir(extension.getFiles().getOutputBaseDirectory().get()));