|
| 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 | +import java.util.Collections; |
| 21 | +import javax.inject.Inject; |
| 22 | +import org.gradle.api.provider.ListProperty; |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * The {@link GitCommitIdPlugin} comes with a sensible set of default configurations and settings. |
| 27 | + * However, there might be cases where a default doesn't fit your project needs. |
| 28 | + * Gradle allows user to configure with |
| 29 | + * <a href="https://docs.gradle.org/current/userguide/implementing_gradle_plugins.html#modeling_dsl_like_apis">Modeling DSL-like APIs</a>. |
| 30 | + * Perhaps one additional item you need to know about configuration is that the |
| 31 | + * {@link GitCommitIdPlugin} makes use of gradle's |
| 32 | + * <a href="https://docs.gradle.org/current/userguide/lazy_configuration.html">Lazy Configuration</a> |
| 33 | + * which is gradle's way to manage growing build complexity. |
| 34 | + * |
| 35 | + * <p>This Extension exposes all configuration options to configure filtering of any |
| 36 | + * properties that may be generated as part of the plugin execution. |
| 37 | + * Do not want to expose hte git.commit.user.email? No problem! Use the filtering |
| 38 | + * to trim down all the properties you do not need, or do not want to be generated. |
| 39 | + * As a plus, filtering may also make the plugin execution faster by a concept that is called |
| 40 | + * 'selective' running. Essentially behind the back the plugin will only ask |
| 41 | + * your git repository about the properties you want to generate. |
| 42 | + * If you have them filtered out, the step of gathering the information is automatically skipped. |
| 43 | + * |
| 44 | + * <p>This extension is generally only made available through the |
| 45 | + * {@link GitCommitIdPluginExtension}. |
| 46 | + * If you want to learn about the plugin, refer to {@link GitCommitIdPlugin}. |
| 47 | + * If you are interested in the task that generates the actual information refer to |
| 48 | + * {@link GitCommitIdPluginGenerationTask}. |
| 49 | + */ |
| 50 | +public abstract class GitCommitIdPluginFilterSettingsExtension { |
| 51 | + /** |
| 52 | + * Name of the extension how it's made available to the end-user as |
| 53 | + * DSL like configuration in the {@code build.gradle}: |
| 54 | + * <pre> |
| 55 | + * gitCommitId { |
| 56 | + * filterSettings { |
| 57 | + * excludeProperties.set([...]]) |
| 58 | + * } |
| 59 | + * } |
| 60 | + * </pre> |
| 61 | + * As may notice this extension is made available as "nested" extension |
| 62 | + * of the {@link GitCommitIdPluginExtension}. |
| 63 | + */ |
| 64 | + public static final String NAME = "filterSettings"; |
| 65 | + |
| 66 | + /** |
| 67 | + * Can be used to exclude certain properties from being emitted (e.g. filter out properties |
| 68 | + * that you *don't* want to expose). May be useful when you want to hide |
| 69 | + * {@code git.build.user.email} (maybe because you don't want to expose your eMail?), |
| 70 | + * or the email of the committer? |
| 71 | + * |
| 72 | + * <p>Each value may be globbing, that is, you can write {@code git.commit.user.*} to |
| 73 | + * exclude both the {@code name}, as well as {@code email} properties from being emitted. |
| 74 | + * |
| 75 | + * <p>Please note that the strings here are Java regexes ({@code .*} is globbing, |
| 76 | + * not plain {@code *}). |
| 77 | + * If you have a very long list of exclusions you may want to |
| 78 | + * use {@link #getIncludeOnlyProperties()}. |
| 79 | + * |
| 80 | + * <p>Defaults to the empty list (= no properties are excluded). |
| 81 | + */ |
| 82 | + public abstract ListProperty<String> getExcludeProperties(); |
| 83 | + |
| 84 | + /** |
| 85 | + * Can be used to include only certain properties into the emission (e.g. include only |
| 86 | + * properties that you <b>want</b> to expose). This feature was implemented to avoid big exclude |
| 87 | + * properties tag when we only want very few specific properties. |
| 88 | + * |
| 89 | + * <p>The inclusion rules, will be overruled by the {@link #getExcludeProperties()} rules |
| 90 | + * (e.g. you can write an inclusion rule that applies for multiple |
| 91 | + * properties and then exclude a subset of them). |
| 92 | + * You can therefor can be a bit broader in the inclusion rules and |
| 93 | + * exclude more sensitive ones in the {@link #getExcludeProperties()} rules. |
| 94 | + * |
| 95 | + * <p>Each value may be globbing, that is, you can write {@code git.commit.user.*} to |
| 96 | + * exclude both the {@code name}, as well as {@code email} properties from being emitted. |
| 97 | + * |
| 98 | + * <p>Please note that the strings here are Java regexes ({@code .*} is globbing, |
| 99 | + * not plain {@code *}). |
| 100 | + * If you have a short list of exclusions you may want to |
| 101 | + * use {@link #getExcludeProperties()}. |
| 102 | + * |
| 103 | + * <p>Defaults to the empty list (= no properties are excluded). |
| 104 | + */ |
| 105 | + public abstract ListProperty<String> getIncludeOnlyProperties(); |
| 106 | + |
| 107 | + /** |
| 108 | + * Setup the default values / conventions for the GitCommitIdPluginOutputSettingsExtension. |
| 109 | + */ |
| 110 | + @Inject |
| 111 | + public GitCommitIdPluginFilterSettingsExtension() { |
| 112 | + getExcludeProperties().convention(Collections.emptyList()); |
| 113 | + getIncludeOnlyProperties().convention(Collections.emptyList()); |
| 114 | + } |
| 115 | +} |
0 commit comments