|
| 1 | +/* |
| 2 | + * This file is part of git-commit-id-gradle-plugin. |
| 3 | + * |
| 4 | + * git-commit-id-gradle-plugin is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * git-commit-id-gradle-plugin is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with git-commit-id-gradle-plugin. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package io.github.git.commit.id.gradle.plugin; |
| 19 | + |
| 20 | + |
| 21 | +import java.util.TimeZone; |
| 22 | +import javax.inject.Inject; |
| 23 | +import org.gradle.api.file.ProjectLayout; |
| 24 | +import org.gradle.api.provider.Property; |
| 25 | + |
| 26 | + |
| 27 | +/** |
| 28 | + * The {@link GitCommitIdPlugin} comes with a sensible set of default configurations and settings. |
| 29 | + * However, there might be cases where a default doesn't fit your project needs. |
| 30 | + * Gradle allows user to configure with |
| 31 | + * <a href="https://docs.gradle.org/current/userguide/implementing_gradle_plugins.html#modeling_dsl_like_apis">Modeling DSL-like APIs</a>. |
| 32 | + * Perhaps one additional item you need to know about configuration is that the |
| 33 | + * {@link GitCommitIdPlugin} makes use of gradle's |
| 34 | + * <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html">Lazy Configuration</a> |
| 35 | + * which is gradle's way to manage growing build complexity. |
| 36 | + * |
| 37 | + * <p>This Extension exposes all configuration options to configure the formatting |
| 38 | + * any properties (also the ones that may be exported into an output |
| 39 | + * file as part of the plugin execution). |
| 40 | + * This extension is generally only made available through the {@link GitCommitIdPluginExtension}. |
| 41 | + * If you want to learn about the plugin, refer to {@link GitCommitIdPlugin}. |
| 42 | + * If you are interested in the task that generates the actual information refer to |
| 43 | + * {@link GitCommitIdPluginGenerationTask}. |
| 44 | + */ |
| 45 | +public abstract class GitCommitIdPluginFormatSettingsExtension { |
| 46 | + /** |
| 47 | + * Name of the extension how it's made available to the end-user as |
| 48 | + * DSL like configuration in the {@code build.gradle}: |
| 49 | + * <pre> |
| 50 | + * gitCommitId { |
| 51 | + * outputSettings { |
| 52 | + * shouldGenerateOutputFile.set(true) |
| 53 | + * } |
| 54 | + * } |
| 55 | + * </pre> |
| 56 | + * As may notice this extension is made available as "nested" extension |
| 57 | + * of the {@link GitCommitIdPluginExtension}. |
| 58 | + */ |
| 59 | + public static final String NAME = "formatSettings"; |
| 60 | + |
| 61 | + /** |
| 62 | + * This configuration allows you to configure the "prefix" of the generated properties and thus |
| 63 | + * will be used as the "namespace" prefix for all exposed/generated properties. |
| 64 | + * |
| 65 | + * <p>An example the plugin may generate the property {@code ${configured-prefix}.commit.id}. |
| 66 | + * Such behaviour can be used to generate properties for multiple git repositories. |
| 67 | + * |
| 68 | + * <p>Refer to {@link pl.project13.core.GitCommitPropertyConstant} for all properties |
| 69 | + * that can be generated. The configured prefix would need to be added in front. |
| 70 | + * |
| 71 | + * <p>Defaults to {@code git} which then results in {@code git.commit.id} and |
| 72 | + * similar generated properties. |
| 73 | + */ |
| 74 | + public abstract Property<String> getPropertyPrefix(); |
| 75 | + |
| 76 | + /** |
| 77 | + * Allows to configure the date format in which "time" properties should be converted into. |
| 78 | + * For example the commit time, or the author time would be converted into the specified format. |
| 79 | + * |
| 80 | + * <p>Defaults to {@code yyyy-MM-dd'T'HH:mm:ssZ} |
| 81 | + * |
| 82 | + * <p>Refer to {@link #getExportDateFormatTimeZone()} if you want to change the time-zone. |
| 83 | + */ |
| 84 | + public abstract Property<String> getExportDateFormat(); |
| 85 | + |
| 86 | + /** |
| 87 | + * Allows to configure the time zone which is utilized for {@link #getExportDateFormat()}. |
| 88 | + * |
| 89 | + * <p>Defaults to {@code java.util.TimeZone.getDefault().getID()}. |
| 90 | + * Allows various formats of timezone configuration |
| 91 | + * (e.g. 'America/Los_Angeles', 'GMT+10', 'PST'). |
| 92 | + * As a general warning try to avoid three-letter time zone IDs because the same |
| 93 | + * abbreviation are often used for multiple time zones. |
| 94 | + */ |
| 95 | + public abstract Property<String> getExportDateFormatTimeZone(); |
| 96 | + |
| 97 | + @Inject |
| 98 | + public ProjectLayout getProjectLayout() { |
| 99 | + throw new IllegalStateException("Should have been injected!"); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Setup the default values / conventions for the GitCommitIdPluginFormatSettingsExtension. |
| 104 | + */ |
| 105 | + @Inject |
| 106 | + public GitCommitIdPluginFormatSettingsExtension() { |
| 107 | + getPropertyPrefix().convention("git"); |
| 108 | + getExportDateFormat().convention("yyyy-MM-dd'T'HH:mm:ssZ"); |
| 109 | + getExportDateFormatTimeZone().convention(TimeZone.getDefault().getID()); |
| 110 | + } |
| 111 | +} |
0 commit comments