Skip to content

Commit 0b5fc93

Browse files
author
TheSnoozer
committed
move some settings from GitCommitIdPluginExtension to GitCommitIdPluginFilterSettingsExtension
1 parent 1d150a2 commit 0b5fc93

5 files changed

Lines changed: 130 additions & 48 deletions

File tree

src/main/java/io/github/git/commit/id/gradle/plugin/GitCommitIdPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public void apply(Project project) {
8585
((ExtensionAware) extension).getExtensions().create(
8686
GitCommitIdPluginFormatSettingsExtension.NAME,
8787
GitCommitIdPluginFormatSettingsExtension.class);
88+
// gitCommitId -> filterSettings
89+
((ExtensionAware) extension).getExtensions().create(
90+
GitCommitIdPluginFilterSettingsExtension.NAME,
91+
GitCommitIdPluginFilterSettingsExtension.class);
8892
// Task
8993
var task = project.getTasks().create(
9094
GitCommitIdPluginGenerationTask.NAME,

src/main/java/io/github/git/commit/id/gradle/plugin/GitCommitIdPluginExtension.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
package io.github.git.commit.id.gradle.plugin;
1919

20-
import java.util.Collections;
2120
import javax.inject.Inject;
22-
import org.gradle.api.provider.ListProperty;
2321
import org.gradle.api.provider.Property;
2422

2523
/**
@@ -73,47 +71,6 @@ public abstract class GitCommitIdPluginExtension {
7371
*/
7472
public abstract Property<Boolean> getSkip();
7573

76-
/**
77-
* Can be used to exclude certain properties from being emitted (e.g. filter out properties
78-
* that you *don't* want to expose). May be useful when you want to hide
79-
* {@code git.build.user.email} (maybe because you don't want to expose your eMail?),
80-
* or the email of the committer?
81-
*
82-
* <p>Each value may be globbing, that is, you can write {@code git.commit.user.*} to
83-
* exclude both the {@code name}, as well as {@code email} properties from being emitted.
84-
*
85-
* <p>Please note that the strings here are Java regexes ({@code .*} is globbing,
86-
* not plain {@code *}).
87-
* If you have a very long list of exclusions you may want to
88-
* use {@link #getIncludeOnlyProperties()}.
89-
*
90-
* <p>Defaults to the empty list (= no properties are excluded).
91-
*/
92-
public abstract ListProperty<String> getExcludeProperties();
93-
94-
/**
95-
* Can be used to include only certain properties into the emission (e.g. include only
96-
* properties that you <b>want</b> to expose). This feature was implemented to avoid big exclude
97-
* properties tag when we only want very few specific properties.
98-
*
99-
* <p>The inclusion rules, will be overruled by the {@link #getExcludeProperties()} rules
100-
* (e.g. you can write an inclusion rule that applies for multiple
101-
* properties and then exclude a subset of them).
102-
* You can therefor can be a bit broader in the inclusion rules and
103-
* exclude more sensitive ones in the {@link #getExcludeProperties()} rules.
104-
*
105-
* <p>Each value may be globbing, that is, you can write {@code git.commit.user.*} to
106-
* exclude both the {@code name}, as well as {@code email} properties from being emitted.
107-
*
108-
* <p>Please note that the strings here are Java regexes ({@code .*} is globbing,
109-
* not plain {@code *}).
110-
* If you have a short list of exclusions you may want to
111-
* use {@link #getExcludeProperties()}.
112-
*
113-
* <p>Defaults to the empty list (= no properties are excluded).
114-
*/
115-
public abstract ListProperty<String> getIncludeOnlyProperties();
116-
11774
/**
11875
* When set to {@code true} this plugin will try to use the branch name from build environment.
11976
* Set to {@code false} to use JGit/GIT to get current branch name which can be useful
@@ -133,8 +90,6 @@ public GitCommitIdPluginExtension() {
13390
getVerbose().convention(false);
13491
// skipPoms
13592
getSkip().convention(false);
136-
getExcludeProperties().convention(Collections.emptyList());
137-
getIncludeOnlyProperties().convention(Collections.emptyList());
13893
// commitIdGenerationMode
13994
// replacementProperties
14095
getUseBranchNameFromBuildEnvironment().convention(true);
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
}

src/main/java/io/github/git/commit/id/gradle/plugin/GitCommitIdPluginGenerationTask.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ private GitCommitIdPluginFormatSettingsExtension getGitCommitIdPluginFormatSetti
8383
.findByType(GitCommitIdPluginFormatSettingsExtension.class);
8484
}
8585

86+
private GitCommitIdPluginFilterSettingsExtension getGitCommitIdPluginFilterSettingsExtension() {
87+
return ((ExtensionAware) getGitCommitIdPluginExtension()).getExtensions()
88+
.findByType(GitCommitIdPluginFilterSettingsExtension.class);
89+
}
90+
8691
/**
8792
* Since we are generating "git" information this task needs to specify the git-directory
8893
* as input. The input can then be used by gradle to determine if the task is "up-to-date"
@@ -196,12 +201,14 @@ public String getPrefixDot() {
196201

197202
@Override
198203
public List<String> getExcludeProperties() {
199-
return extension.getExcludeProperties().get();
204+
return getGitCommitIdPluginFilterSettingsExtension()
205+
.getExcludeProperties().get();
200206
}
201207

202208
@Override
203209
public List<String> getIncludeOnlyProperties() {
204-
return extension.getIncludeOnlyProperties().get();
210+
return getGitCommitIdPluginFilterSettingsExtension()
211+
.getIncludeOnlyProperties().get();
205212
}
206213

207214
@Nullable

src/main/java/io/github/git/commit/id/gradle/plugin/GitCommitIdPluginGitSettingsExtension.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public abstract class GitCommitIdPluginGitSettingsExtension {
8484
*
8585
* <p>Refer to {@link GitDescribeConfig} for options that can be passed towards git-describe.
8686
* The result of this configuration is exposed as
87-
* {@link GitCommitIdPluginFormatSettingsExtension#getPropertyPrefix()}{@code .commit.id.describe}.
87+
* {@link GitCommitIdPluginFormatSettingsExtension#getPropertyPrefix()}
88+
* {@code .commit.id.describe}.
8889
*/
8990
public abstract Property<GitDescribeConfig> getGitDescribeConfig();
9091

0 commit comments

Comments
 (0)