Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ private void loadBuildData(Properties properties) {
.setDateFormat(dateFormat)
.setDateFormatTimeZone(dateFormatTimeZone)
.setProject(project)
.setPrefixDot(prefixDot);
.setPrefixDot(prefixDot)
.setExcludeProperties(excludeProperties)
.setIncludeOnlyProperties(includeOnlyProperties);

buildServerDataProvider.loadBuildData(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.maven.project.MavenProject;
import pl.project13.maven.git.GitCommitPropertyConstant;
import pl.project13.maven.git.PropertiesFilterer;
import pl.project13.maven.git.log.LoggerBridge;
import pl.project13.maven.git.util.PropertyManager;

Expand All @@ -28,6 +29,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.List;
import java.util.Properties;
import java.util.TimeZone;
import java.util.function.Supplier;
Expand All @@ -40,6 +42,8 @@ public abstract class BuildServerDataProvider {
private String dateFormatTimeZone = null;
private String prefixDot = "";
private MavenProject project = null;
private List<String> excludeProperties = null;
private List<String> includeOnlyProperties = null;

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

public BuildServerDataProvider setExcludeProperties(List<String> excludeProperties) {
this.excludeProperties = excludeProperties;
return this;
}

public BuildServerDataProvider setIncludeOnlyProperties(List<String> includeOnlyProperties) {
this.includeOnlyProperties = includeOnlyProperties;
return this;
}

/**
* Get the {@link BuildServerDataProvider} implementation for the running environment
*
Expand Down Expand Up @@ -113,15 +127,18 @@ public void loadBuildData(@Nonnull Properties properties) {
public abstract String getBuildBranch();

private void loadBuildVersionAndTimeData(@Nonnull Properties properties) {
Date buildDate = new Date();
SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
if (dateFormatTimeZone != null) {
smf.setTimeZone(TimeZone.getTimeZone(dateFormatTimeZone));
}
put(properties, GitCommitPropertyConstant.BUILD_TIME, smf.format(buildDate));
Supplier<String> buildTimeSupplier = () -> {
Date buildDate = new Date();
SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
if (dateFormatTimeZone != null) {
smf.setTimeZone(TimeZone.getTimeZone(dateFormatTimeZone));
}
return smf.format(buildDate);
};
maybePut(properties, GitCommitPropertyConstant.BUILD_TIME, buildTimeSupplier);

if (project != null) {
put(properties, GitCommitPropertyConstant.BUILD_VERSION, project.getVersion());
maybePut(properties, GitCommitPropertyConstant.BUILD_VERSION, () -> project.getVersion());
}
}

Expand Down Expand Up @@ -152,7 +169,7 @@ protected void maybePut(@Nonnull Properties properties, @Nonnull String key, Sup
if (properties.contains(keyWithPrefix)) {
String propertyValue = properties.getProperty(keyWithPrefix);
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
} else {
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

String propertyValue = supplier.get();
log.info("Collected {} with value {}", keyWithPrefix, propertyValue);
PropertyManager.putWithoutPrefix(properties, keyWithPrefix, propertyValue);
Expand Down