Skip to content

Commit 71f0c47

Browse files
committed
Add filtering for build server data.
1 parent ca97e60 commit 71f0c47

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ private void loadBuildData(Properties properties) {
504504
.setDateFormat(dateFormat)
505505
.setDateFormatTimeZone(dateFormatTimeZone)
506506
.setProject(project)
507-
.setPrefixDot(prefixDot);
507+
.setPrefixDot(prefixDot)
508+
.setExcludeProperties(excludeProperties)
509+
.setIncludeOnlyProperties(includeOnlyProperties);
508510

509511
buildServerDataProvider.loadBuildData(properties);
510512
}

src/main/java/pl/project13/maven/git/build/BuildServerDataProvider.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.maven.project.MavenProject;
2121
import pl.project13.maven.git.GitCommitPropertyConstant;
22+
import pl.project13.maven.git.PropertiesFilterer;
2223
import pl.project13.maven.git.log.LoggerBridge;
2324
import pl.project13.maven.git.util.PropertyManager;
2425

@@ -28,6 +29,7 @@
2829
import java.text.SimpleDateFormat;
2930
import java.util.Date;
3031
import java.util.Map;
32+
import java.util.List;
3133
import java.util.Properties;
3234
import java.util.TimeZone;
3335
import java.util.function.Supplier;
@@ -40,6 +42,8 @@ public abstract class BuildServerDataProvider {
4042
private String dateFormatTimeZone = null;
4143
private String prefixDot = "";
4244
private MavenProject project = null;
45+
private List<String> excludeProperties = null;
46+
private List<String> includeOnlyProperties = null;
4347

4448
BuildServerDataProvider(@Nonnull LoggerBridge log, @Nonnull Map<String, String> env) {
4549
this.log = log;
@@ -66,6 +70,16 @@ public BuildServerDataProvider setPrefixDot(@Nonnull String prefixDot) {
6670
return this;
6771
}
6872

73+
public BuildServerDataProvider setExcludeProperties(List<String> excludeProperties) {
74+
this.excludeProperties = excludeProperties;
75+
return this;
76+
}
77+
78+
public BuildServerDataProvider setIncludeOnlyProperties(List<String> includeOnlyProperties) {
79+
this.includeOnlyProperties = includeOnlyProperties;
80+
return this;
81+
}
82+
6983
/**
7084
* Get the {@link BuildServerDataProvider} implementation for the running environment
7185
*
@@ -113,15 +127,18 @@ public void loadBuildData(@Nonnull Properties properties) {
113127
public abstract String getBuildBranch();
114128

115129
private void loadBuildVersionAndTimeData(@Nonnull Properties properties) {
116-
Date buildDate = new Date();
117-
SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
118-
if (dateFormatTimeZone != null) {
119-
smf.setTimeZone(TimeZone.getTimeZone(dateFormatTimeZone));
120-
}
121-
put(properties, GitCommitPropertyConstant.BUILD_TIME, smf.format(buildDate));
130+
Supplier<String> buildTimeSupplier = () -> {
131+
Date buildDate = new Date();
132+
SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
133+
if (dateFormatTimeZone != null) {
134+
smf.setTimeZone(TimeZone.getTimeZone(dateFormatTimeZone));
135+
}
136+
return smf.format(buildDate);
137+
};
138+
maybePut(properties, GitCommitPropertyConstant.BUILD_TIME, buildTimeSupplier);
122139

123140
if (project != null) {
124-
put(properties, GitCommitPropertyConstant.BUILD_VERSION, project.getVersion());
141+
maybePut(properties, GitCommitPropertyConstant.BUILD_VERSION, () -> project.getVersion());
125142
}
126143
}
127144

@@ -152,7 +169,7 @@ protected void maybePut(@Nonnull Properties properties, @Nonnull String key, Sup
152169
if (properties.contains(keyWithPrefix)) {
153170
String propertyValue = properties.getProperty(keyWithPrefix);
154171
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
155-
} else {
172+
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {
156173
String propertyValue = supplier.get();
157174
log.info("Collected {} with value {}", keyWithPrefix, propertyValue);
158175
PropertyManager.putWithoutPrefix(properties, keyWithPrefix, propertyValue);

0 commit comments

Comments
 (0)