Skip to content

Commit

Permalink
Merge pull request #511 from ryantse/optional-build-information
Browse files Browse the repository at this point in the history
Build system information should be optionally set
  • Loading branch information
TheSnoozer committed Aug 3, 2020
2 parents 6b0b230 + e0d9319 commit 6beb37d
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/pl/project13/core/GitDataProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ protected SimpleDateFormat getSimpleDateFormatWithTimeZone() {
protected void maybePut(@Nonnull Properties properties, String key, SupplierEx<String> value)
throws GitCommitIdExecutionException {
String keyWithPrefix = prefixDot + key;
if (properties.containsKey(keyWithPrefix)) {
if (properties.stringPropertyNames().contains(keyWithPrefix)) {
String propertyValue = properties.getProperty(keyWithPrefix);
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, Fil

final String buildTimeProperty = prefixDot + GitCommitPropertyConstant.BUILD_TIME;

propertiesCopy.remove(buildTimeProperty);
persistedProperties.remove(buildTimeProperty);
propertiesCopy.setProperty(buildTimeProperty, null);
persistedProperties.setProperty(buildTimeProperty, null);

shouldGenerate = !propertiesCopy.equals(persistedProperties);
} catch (CannotReadFileException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public static boolean isActiveServer(Map<String, String> env) {
@Override
void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("CODEBUILD_BUILD_NUMBER", "");
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);

String buildArn = env.get("CODEBUILD_BUILD_ID");
put(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, buildArn);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, () -> buildArn);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static boolean isActiveServer(@Nonnull Map<String, String> env) {
void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("BUILD_BUILDNUMBER", "");

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = Optional.ofNullable(env.get("bamboo.buildNumber"))
.orElseGet(() -> env.getOrDefault("BAMBOO_BUILDNUMBER", ""));

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,9 @@ private void loadBuildHostData(@Nonnull Properties properties) {
maybePut(properties, GitCommitPropertyConstant.BUILD_HOST, buildHostSupplier);
}

protected void put(@Nonnull Properties properties, @Nonnull String key, String value) {
String keyWithPrefix = prefixDot + key;
log.info("Collected {} with value {}", keyWithPrefix, value);
PropertyManager.putWithoutPrefix(properties, keyWithPrefix, value);
}

protected void maybePut(@Nonnull Properties properties, @Nonnull String key, Supplier<String> supplier) {
String keyWithPrefix = prefixDot + key;
if (properties.containsKey(keyWithPrefix)) {
if (properties.stringPropertyNames().contains(keyWithPrefix)) {
String propertyValue = properties.getProperty(keyWithPrefix);
log.info("Using cached {} with value {}", keyWithPrefix, propertyValue);
} else if (PropertiesFilterer.isIncluded(keyWithPrefix, includeOnlyProperties, excludeProperties)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static boolean isActiveServer(Map<String, String> env) {
@Override
void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("CIRCLE_BUILD_NUM", "");
put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void loadBuildNumber(@Nonnull Properties properties) {
// CI_PIPELINE_IID will be present if in a Gitlab CI environment (Gitlab >11.0) and contains the project specific build number
String buildNumber = env.getOrDefault("CI_PIPELINE_IID", "");

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
put(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, uniqueBuildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, () -> uniqueBuildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static boolean isActiveServer(@Nonnull Map<String, String> env) {
void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("BUILD_NUMBER", "");

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("BUILD_NUMBER", "");
String buildNumberUnique = teamcitySystemProperties.getProperty("teamcity.build.id", "");

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
put(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, buildNumberUnique);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, () -> buildNumberUnique);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void loadBuildNumber(@Nonnull Properties properties) {
String buildNumber = env.getOrDefault("TRAVIS_BUILD_NUMBER", "");
String uniqueBuildNumber = env.getOrDefault("TRAVIS_BUILD_ID", "");

put(properties, GitCommitPropertyConstant.BUILD_NUMBER, buildNumber);
put(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, uniqueBuildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER, () -> buildNumber);
maybePut(properties, GitCommitPropertyConstant.BUILD_NUMBER_UNIQUE, () -> uniqueBuildNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void putWithoutPrefix(@Nonnull Properties properties, String key,
if (!isNotEmpty(value)) {
value = "Unknown";
}
properties.put(key, value);
properties.setProperty(key, value);
}

private static boolean isNotEmpty(@Nullable String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ private void loadBuildData(Properties properties) {
}

private void publishPropertiesInto(Properties p) {
p.putAll(properties);
for (String propertyName : properties.stringPropertyNames()) {
p.setProperty(propertyName, properties.getProperty(propertyName));
}
}

/**
Expand Down Expand Up @@ -603,9 +605,8 @@ private File lookupGitDirectory() throws GitCommitIdExecutionException {
}

private void logProperties() {
for (Object key : properties.keySet()) {
String keyString = key.toString();
log.info("including property {} in results", keyString);
for (String propertyName : properties.stringPropertyNames()) {
log.info("including property {} in results", propertyName);
}
}

Expand Down
17 changes: 7 additions & 10 deletions maven/src/main/java/pl/project13/maven/git/PropertiesReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,18 @@ public void performReplacement(Properties properties, List<ReplacementProperty>
}

private void performReplacementOnAllGeneratedProperties(Properties properties, ReplacementProperty replacementProperty) {
Map<Object, Object> propertiesToBeAdded = new HashMap<>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String)entry.getKey();
String content = (String)entry.getValue();
for (String propertyName : properties.stringPropertyNames()) {
String content = properties.getProperty(propertyName);
String result = performReplacement(replacementProperty, content);
if ((replacementProperty.getPropertyOutputSuffix() != null) && (!replacementProperty.getPropertyOutputSuffix().isEmpty())) {
String newPropertyKey = key + "." + replacementProperty.getPropertyOutputSuffix();
propertiesToBeAdded.put(newPropertyKey, result);
log.info("apply replace on property " + key + " and save to " + newPropertyKey + ": original value '" + content + "' with '" + result + "'");
String newPropertyKey = propertyName + "." + replacementProperty.getPropertyOutputSuffix();
properties.setProperty(newPropertyKey, result);
log.info("apply replace on property " + propertyName + " and save to " + newPropertyKey + ": original value '" + content + "' with '" + result + "'");
} else {
entry.setValue(result);
log.info("apply replace on property " + key + ": original value '" + content + "' with '" + result + "'");
properties.setProperty(propertyName, result);
log.info("apply replace on property " + propertyName + ": original value '" + content + "' with '" + result + "'");
}
}
properties.putAll(propertiesToBeAdded);
}

private void performReplacementOnSingleProperty(Properties properties, ReplacementProperty replacementProperty, String propertyKey) {
Expand Down

0 comments on commit 6beb37d

Please sign in to comment.