1919
2020import org .apache .maven .project .MavenProject ;
2121import pl .project13 .maven .git .GitCommitPropertyConstant ;
22+ import pl .project13 .maven .git .PropertiesFilterer ;
2223import pl .project13 .maven .git .log .LoggerBridge ;
2324import pl .project13 .maven .git .util .PropertyManager ;
2425
2829import java .text .SimpleDateFormat ;
2930import java .util .Date ;
3031import java .util .Map ;
32+ import java .util .List ;
3133import java .util .Properties ;
3234import java .util .TimeZone ;
3335import 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