35
35
import static java .util .Collections .emptyList ;
36
36
import static java .util .Collections .singletonList ;
37
37
import static java .util .Comparator .comparing ;
38
- import static java .util .Objects .requireNonNull ;
39
38
import static java .util .stream .Collectors .toList ;
40
39
import static me .qoomon .gitversioning .commons .GitRefType .*;
41
40
import static me .qoomon .gitversioning .commons .StringUtil .*;
42
41
import static org .apache .commons .lang3 .StringUtils .*;
43
- import static org .eclipse .jgit .lib .Constants .HEAD ;
44
42
43
+ @ SuppressWarnings ("StringConcatenationArgumentToLogCall" )
45
44
public abstract class GitVersioningPluginExtension {
46
45
47
46
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 {
80
79
}
81
80
82
81
private void apply () throws IOException {
83
- // check if extension is disabled by command option
82
+ // check if the extension is disabled by command option
84
83
final String commandOptionDisable = getCommandOption (OPTION_NAME_DISABLE );
85
84
if (commandOptionDisable != null ) {
86
85
boolean disabled = parseBoolean (commandOptionDisable );
@@ -89,7 +88,7 @@ private void apply() throws IOException {
89
88
return ;
90
89
}
91
90
} else {
92
- // check if extension is disabled by config option
91
+ // check if the extension is disabled by config option
93
92
if (config .disable ) {
94
93
project .getLogger ().warn ("skip - versioning is disabled by config option" );
95
94
return ;
@@ -126,25 +125,25 @@ private void apply() throws IOException {
126
125
127
126
project .getLogger ().lifecycle ("matching ref: " + gitVersionDetails .getRefType ().name () + " - " + gitVersionDetails .getRefName ());
128
127
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
+ }
130
136
if (patchDescription .describeTagPattern != null ) {
131
- project .getLogger ().lifecycle (" describeTagPattern: " + patchDescription .describeTagPattern );
137
+ project .getLogger ().lifecycle (" describeTagPattern: " + patchDescription .describeTagPattern );
132
138
gitSituation .setDescribeTagPattern (patchDescription .getDescribeTagPattern ());
133
139
}
134
140
if (patchDescription .describeTagFirstParent != null ) {
135
- project .getLogger ().info ( " describeTagFirstParent: " + patchDescription .describeTagFirstParent );
141
+ project .getLogger ().lifecycle ( " describeTagFirstParent: " + patchDescription .describeTagFirstParent );
136
142
gitSituation .setFirstParent (patchDescription .describeTagFirstParent );
137
143
}
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
- }
145
144
boolean updateGradleProperties = getUpdateGradlePropertiesOption (patchDescription );
146
145
if (updateGradleProperties ) {
147
- project .getLogger ().lifecycle (" updateGradleProperties: " + updateGradleProperties );
146
+ project .getLogger ().lifecycle (" updateGradleProperties: true" );
148
147
}
149
148
150
149
globalFormatPlaceholderMap = generateGlobalFormatPlaceholderMap (gitSituation , gitVersionDetails , project );
@@ -157,7 +156,11 @@ private void apply() throws IOException {
157
156
final String versionFormat = patchDescription .version ;
158
157
if (versionFormat != null ) {
159
158
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
+ }
161
164
}
162
165
163
166
final Map <String , String > propertyFormats = patchDescription .properties ;
@@ -312,7 +315,7 @@ private void handleEnvironment(Repository repository) throws IOException {
312
315
}
313
316
}
314
317
315
- // --- try getting branch and tag situation from environment ---
318
+ // --- try getting the branch and tag situation from environment ---
316
319
// skip if we are on a branch
317
320
if (repository .getBranch () == null ) {
318
321
return ;
@@ -400,6 +403,7 @@ private void handleEnvironment(Repository repository) throws IOException {
400
403
} else if (!isBlank (commitTag )) {
401
404
addTag (commitTag );
402
405
}
406
+ //noinspection UnnecessaryReturnStatement
403
407
return ;
404
408
}
405
409
}
@@ -678,11 +682,7 @@ private boolean getUpdateGradlePropertiesOption(final RefPatchDescription gitRef
678
682
return parseBoolean (updateGradlePropertiesOption );
679
683
}
680
684
681
- if (gitRefConfig .updateGradleProperties != null ) {
682
- return gitRefConfig .updateGradleProperties ;
683
- }
684
-
685
- return false ;
685
+ return Objects .requireNonNullElse (gitRefConfig .updateGradleProperties , false );
686
686
}
687
687
688
688
0 commit comments