configure Files as FilesConfiguration
[yosql.git] / yosql-tooling / yosql-tooling-gradle / src / main / java / wtf / metio / yosql / tooling / gradle / Files.java
bloba949e99bdb9947d212de352c5455c13fb5229438
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 http://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.file.DirectoryProperty;
11 import org.gradle.api.file.ProjectLayout;
12 import org.gradle.api.model.ObjectFactory;
13 import org.gradle.api.provider.Property;
14 import org.gradle.api.tasks.InputDirectory;
15 import org.gradle.api.tasks.Internal;
16 import org.gradle.api.tasks.OutputDirectory;
17 import wtf.metio.yosql.models.immutables.FilesConfiguration;
19 /**
20 * Configures input- and output-directories as well as other file related options.
22 public abstract class Files {
24 private final ObjectFactory objectFactory;
26 /**
27 * @return The base path of the input directory.
29 @InputDirectory
30 abstract public DirectoryProperty inputBaseDirectory();
32 /**
33 * @return The base path of the output directory.
35 @OutputDirectory
36 abstract public DirectoryProperty outputBaseDirectory();
38 @Internal
39 Property<FilesConfiguration> fileConfiguration() {
40 final var files = objectFactory.property(FilesConfiguration.class);
41 files.set(FilesConfiguration.usingDefaults()
42 .setInputBaseDirectory(inputBaseDirectory().get().getAsFile().toPath())
43 .setOutputBaseDirectory(outputBaseDirectory().get().getAsFile().toPath())
44 .build());
45 return files;
48 Files(final ObjectFactory objectFactory, final ProjectLayout projectLayout) {
49 this.objectFactory = objectFactory;
50 inputBaseDirectory().convention(projectLayout.getProjectDirectory().dir("src").dir("main").dir("yosql"));
51 outputBaseDirectory().convention(projectLayout.getBuildDirectory().dir("generated").map(d -> d.dir("sources").dir("yosql")));