Skip to content

Commit ee27160

Browse files
committed
refactor: prevent cluttering version logs
1 parent 7ad13b4 commit ee27160

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group 'me.qoomon'
15-
version '6.4.3'
15+
version '6.4.4'
1616
sourceCompatibility = JavaVersion.VERSION_11
1717
targetCompatibility = JavaVersion.VERSION_11
1818

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@
3535
import static java.util.Collections.emptyList;
3636
import static java.util.Collections.singletonList;
3737
import static java.util.Comparator.comparing;
38-
import static java.util.Objects.requireNonNull;
3938
import static java.util.stream.Collectors.toList;
4039
import static me.qoomon.gitversioning.commons.GitRefType.*;
4140
import static me.qoomon.gitversioning.commons.StringUtil.*;
4241
import static org.apache.commons.lang3.StringUtils.*;
43-
import static org.eclipse.jgit.lib.Constants.HEAD;
4442

43+
@SuppressWarnings("StringConcatenationArgumentToLogCall")
4544
public abstract class GitVersioningPluginExtension {
4645

4746
private static final Pattern VERSION_PATTERN = Pattern.compile(".*?(?<version>(?<core>(?<major>\\d+)(?:\\.(?<minor>\\d+)(?:\\.(?<patch>\\d+))?)?)(?:-(?<label>.*))?)|");
@@ -80,7 +79,7 @@ public void apply(GitVersioningPluginConfig config) throws IOException {
8079
}
8180

8281
private void apply() throws IOException {
83-
// check if extension is disabled by command option
82+
// check if the extension is disabled by command option
8483
final String commandOptionDisable = getCommandOption(OPTION_NAME_DISABLE);
8584
if (commandOptionDisable != null) {
8685
boolean disabled = parseBoolean(commandOptionDisable);
@@ -89,7 +88,7 @@ private void apply() throws IOException {
8988
return;
9089
}
9190
} else {
92-
// check if extension is disabled by config option
91+
// check if the extension is disabled by config option
9392
if (config.disable) {
9493
project.getLogger().warn("skip - versioning is disabled by config option");
9594
return;
@@ -126,25 +125,25 @@ private void apply() throws IOException {
126125

127126
project.getLogger().lifecycle("matching ref: " + gitVersionDetails.getRefType().name() + " - " + gitVersionDetails.getRefName());
128127
final RefPatchDescription patchDescription = gitVersionDetails.getPatchDescription();
129-
project.getLogger().lifecycle("ref configuration: " + gitVersionDetails.getRefType().name() + " - pattern: " + patchDescription.pattern);
128+
project.getLogger().lifecycle(" ref configuration: " + gitVersionDetails.getRefType().name() + " - pattern: " + patchDescription.pattern);
129+
if (patchDescription.version != null) {
130+
project.getLogger().lifecycle(" version: " + patchDescription.version);
131+
}
132+
if (!patchDescription.properties.isEmpty()) {
133+
project.getLogger().lifecycle(" properties:");
134+
patchDescription.properties.forEach((key, value) -> project.getLogger().lifecycle(" " + key + ": " + value));
135+
}
130136
if (patchDescription.describeTagPattern != null) {
131-
project.getLogger().lifecycle(" describeTagPattern: " + patchDescription.describeTagPattern);
137+
project.getLogger().lifecycle(" describeTagPattern: " + patchDescription.describeTagPattern);
132138
gitSituation.setDescribeTagPattern(patchDescription.getDescribeTagPattern());
133139
}
134140
if (patchDescription.describeTagFirstParent != null) {
135-
project.getLogger().info(" describeTagFirstParent: " + patchDescription.describeTagFirstParent);
141+
project.getLogger().lifecycle(" describeTagFirstParent: " + patchDescription.describeTagFirstParent);
136142
gitSituation.setFirstParent(patchDescription.describeTagFirstParent);
137143
}
138-
if (patchDescription.version != null) {
139-
project.getLogger().lifecycle(" version: " + patchDescription.version);
140-
}
141-
if (!patchDescription.properties.isEmpty()) {
142-
project.getLogger().lifecycle(" properties:");
143-
patchDescription.properties.forEach((key, value) -> project.getLogger().lifecycle(" " + key + ": " + value));
144-
}
145144
boolean updateGradleProperties = getUpdateGradlePropertiesOption(patchDescription);
146145
if (updateGradleProperties) {
147-
project.getLogger().lifecycle(" updateGradleProperties: " + updateGradleProperties);
146+
project.getLogger().lifecycle(" updateGradleProperties: true");
148147
}
149148

150149
globalFormatPlaceholderMap = generateGlobalFormatPlaceholderMap(gitSituation, gitVersionDetails, project);
@@ -157,7 +156,11 @@ private void apply() throws IOException {
157156
final String versionFormat = patchDescription.version;
158157
if (versionFormat != null) {
159158
updateVersion(project, versionFormat);
160-
project.getLogger().lifecycle("project version: " + project.getVersion());
159+
if(project == project.getRootProject()) {
160+
project.getLogger().lifecycle("project version: " + project.getVersion());
161+
} else if (!project.getVersion().equals(project.getRootProject().getVersion())) {
162+
project.getLogger().lifecycle(project.getName()+ " > project version: " + project.getVersion());
163+
}
161164
}
162165

163166
final Map<String, String> propertyFormats = patchDescription.properties;
@@ -312,7 +315,7 @@ private void handleEnvironment(Repository repository) throws IOException {
312315
}
313316
}
314317

315-
// --- try getting branch and tag situation from environment ---
318+
// --- try getting the branch and tag situation from environment ---
316319
// skip if we are on a branch
317320
if (repository.getBranch() == null) {
318321
return;
@@ -400,6 +403,7 @@ private void handleEnvironment(Repository repository) throws IOException {
400403
} else if (!isBlank(commitTag)) {
401404
addTag(commitTag);
402405
}
406+
//noinspection UnnecessaryReturnStatement
403407
return;
404408
}
405409
}
@@ -678,11 +682,7 @@ private boolean getUpdateGradlePropertiesOption(final RefPatchDescription gitRef
678682
return parseBoolean(updateGradlePropertiesOption);
679683
}
680684

681-
if (gitRefConfig.updateGradleProperties != null) {
682-
return gitRefConfig.updateGradleProperties;
683-
}
684-
685-
return false;
685+
return Objects.requireNonNullElse(gitRefConfig.updateGradleProperties, false);
686686
}
687687

688688

src/test/resources/testProjects/multiModuleProject/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'me.qoomon.git-versioning' version '6.4.3'
2+
id 'me.qoomon.git-versioning' version '6.4.4'
33
}
44

55
gitVersioning.apply {

src/test/resources/testProjects/standardProject/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'me.qoomon.git-versioning' version '6.4.2'
2+
id 'me.qoomon.git-versioning' version '6.4.4'
33
}
44

55
gitVersioning.apply {

src/test/resources/testProjects/standardProjectKotlinDSL/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import kotlin.reflect.full.declaredMemberProperties
33
import kotlin.reflect.full.declaredMembers
44

55
plugins {
6-
id("me.qoomon.git-versioning") version "6.4.2"
6+
id("me.qoomon.git-versioning") version "6.4.4"
77
}
88

99
gitVersioning.apply {

0 commit comments

Comments
 (0)