Skip to content

Commit e48c122

Browse files
committed
feat: add visible logging for relevant output
1 parent 38d73f0 commit e48c122

File tree

4 files changed

+59
-46
lines changed

4 files changed

+59
-46
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 6.3.7
4+
5+
##### Features
6+
- add visible logging for relevant output
7+
38
## 6.3.6
49

510
##### Fixes

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

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

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

+52-44
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@
4242
import static me.qoomon.gitversioning.commons.StringUtil.*;
4343
import static org.apache.commons.lang3.StringUtils.leftPad;
4444
import static org.apache.commons.lang3.StringUtils.rightPad;
45+
import static org.eclipse.jgit.lib.Constants.HEAD;
4546

4647
public abstract class GitVersioningPluginExtension {
4748

48-
public static final Logger LOGGER = LoggerFactory.getLogger(GitVersioningPluginExtension.class);
49-
5049
private static final Pattern VERSION_PATTERN = Pattern.compile(".*?(?<version>(?<core>(?<major>\\d+)(?:\\.(?<minor>\\d+)(?:\\.(?<patch>\\d+))?)?)(?:-(?<label>.*))?)|");
5150

5251
private static final String OPTION_NAME_GIT_REF = "git.ref";
@@ -88,74 +87,75 @@ private void apply() throws IOException {
8887
if (commandOptionDisable != null) {
8988
boolean disabled = parseBoolean(commandOptionDisable);
9089
if (disabled) {
91-
LOGGER.info("skip - versioning is disabled by command option");
90+
project.getLogger().warn("skip - versioning is disabled by command option");
9291
return;
9392
}
9493
} else {
9594
// check if extension is disabled by config option
9695
if (config.disable) {
97-
LOGGER.info("skip - versioning is disabled by config option");
96+
project.getLogger().warn("skip - versioning is disabled by config option");
9897
return;
9998
}
10099
}
101100

102101
final GitSituation gitSituation = getGitSituation(project.getProjectDir());
103102
if (gitSituation == null) {
104-
LOGGER.warn("skip - project is not part of a git repository");
103+
project.getLogger().warn("skip - project is not part of a git repository");
105104
return;
106105
}
107106

108-
if (LOGGER.isDebugEnabled()) {
109-
LOGGER.debug("git situation:");
110-
LOGGER.debug(" root directory: " + gitSituation.getRootDirectory());
111-
LOGGER.debug(" head commit: " + gitSituation.getRev());
112-
LOGGER.debug(" head commit timestamp: " + gitSituation.getTimestamp());
113-
LOGGER.debug(" head branch: " + gitSituation.getBranch());
114-
LOGGER.debug(" head tags: " + gitSituation.getTags());
115-
LOGGER.debug(" head description: " + gitSituation.getDescription());
107+
if (project.getLogger().isDebugEnabled()) {
108+
project.getLogger().debug("git situation:");
109+
project.getLogger().debug(" root directory: " + gitSituation.getRootDirectory());
110+
project.getLogger().debug(" head commit: " + gitSituation.getRev());
111+
project.getLogger().debug(" head commit timestamp: " + gitSituation.getTimestamp());
112+
project.getLogger().debug(" head branch: " + gitSituation.getBranch());
113+
project.getLogger().debug(" head tags: " + gitSituation.getTags());
114+
project.getLogger().debug(" head description: " + gitSituation.getDescription());
116115
}
117116

118117
// determine git version details
119118
gitVersionDetails = getGitVersionDetails(gitSituation, config);
120119
if (gitVersionDetails == null) {
121-
LOGGER.warn("skip - no matching ref configuration and no rev configuration defined");
122-
LOGGER.warn("git refs:");
123-
LOGGER.warn(" branch: " + gitSituation.getBranch());
124-
LOGGER.warn(" tags: " + gitSituation.getTags());
125-
LOGGER.warn("defined ref configurations:");
126-
config.refs.list.forEach(ref -> LOGGER.warn(" " + rightPad(ref.type.name(), 6) + " - pattern: " + ref.pattern));
120+
project.getLogger().warn("skip - no matching ref configuration and no rev configuration defined");
121+
project.getLogger().warn("git refs:");
122+
project.getLogger().warn(" branch: " + gitSituation.getBranch());
123+
project.getLogger().warn(" tags: " + gitSituation.getTags());
124+
project.getLogger().warn("defined ref configurations:");
125+
config.refs.list.forEach(ref -> project.getLogger().warn(" " + rightPad(ref.type.name(), 6) + " - pattern: " + ref.pattern));
127126
return;
128127
}
129128

130-
LOGGER.info("matching ref: " + gitVersionDetails.getRefType().name() + " - " + gitVersionDetails.getRefName());
129+
project.getLogger().lifecycle("matching ref: " + gitVersionDetails.getRefType().name() + " - " + gitVersionDetails.getRefName());
131130
final RefPatchDescription patchDescription = gitVersionDetails.getPatchDescription();
132-
LOGGER.info("ref configuration: " + gitVersionDetails.getRefType().name() + " - pattern: " + patchDescription.pattern);
131+
project.getLogger().lifecycle("ref configuration: " + gitVersionDetails.getRefType().name() + " - pattern: " + patchDescription.pattern);
133132
if (patchDescription.describeTagPattern != null) {
134-
LOGGER.info(" describeTagPattern: " + patchDescription.describeTagPattern);
133+
project.getLogger().lifecycle(" describeTagPattern: " + patchDescription.describeTagPattern);
135134
gitSituation.setDescribeTagPattern(patchDescription.getDescribeTagPattern());
136135
}
137136
if (patchDescription.version != null) {
138-
LOGGER.info(" version: " + patchDescription.version);
137+
project.getLogger().lifecycle(" version: " + patchDescription.version);
139138
}
140139
if (!patchDescription.properties.isEmpty()) {
141-
LOGGER.info(" properties: " + patchDescription.version);
142-
patchDescription.properties.forEach((key, value) -> LOGGER.info(" " + key + " - " + value));
140+
project.getLogger().lifecycle(" properties:");
141+
patchDescription.properties.forEach((key, value) -> project.getLogger().lifecycle(" " + key + ": " + value));
143142
}
144143
boolean updateGradleProperties = getUpdateGradlePropertiesOption(patchDescription);
145144
if (updateGradleProperties) {
146-
LOGGER.info(" updateGradleProperties: " + updateGradleProperties);
145+
project.getLogger().lifecycle(" updateGradleProperties: " + updateGradleProperties);
147146
}
148147

149148
globalFormatPlaceholderMap = generateGlobalFormatPlaceholderMap(gitSituation, gitVersionDetails, project);
150149
Map<String, String> gitProjectProperties = generateGitProjectProperties(gitSituation, gitVersionDetails);
151150

151+
project.getLogger().lifecycle("");
152152
project.getAllprojects().forEach(project -> {
153153
final String originalProjectVersion = project.getVersion().toString();
154154

155155
final String versionFormat = patchDescription.version;
156156
if (versionFormat != null) {
157157
updateVersion(project, versionFormat);
158-
LOGGER.info("project version: " + project.getVersion());
158+
project.getLogger().lifecycle("project version: " + project.getVersion());
159159
}
160160

161161
final Map<String, String> propertyFormats = patchDescription.properties;
@@ -198,14 +198,14 @@ private void updatePropertyValues(Project project, Map<String, String> propertyF
198198
originalProjectVersion);
199199
if (!gitPropertyValue.equals(projectPropertyValue)) {
200200
if (logHeader) {
201-
LOGGER.info("properties:");
201+
project.getLogger().lifecycle("properties:");
202202
logHeader = false;
203203
}
204-
LOGGER.info("set property " + projectPropertyName + " to " + gitPropertyValue);
204+
project.getLogger().lifecycle(" " + projectPropertyName + ": " + gitPropertyValue);
205205
project.setProperty(projectPropertyName, gitPropertyValue);
206206
}
207207
} else {
208-
LOGGER.warn("Can not update property " + projectPropertyName + "." +
208+
project.getLogger().warn("Can not update property " + projectPropertyName + "." +
209209
" Expected value type is String, but was " + projectPropertyValue.getClass().getName());
210210
}
211211
}
@@ -292,13 +292,21 @@ private GitSituation getGitSituation(File executionRootDirectory) throws IOExcep
292292
}
293293
}
294294

295+
// TODO
296+
// skip if we are on a branch
297+
// if (repository.getBranch() == null) {}
298+
295299
// GitHub Actions support
296300
if (overrideBranch == null && overrideTag == null) {
297301
final String githubEnv = System.getenv("GITHUB_ACTIONS");
298302
if (githubEnv != null && githubEnv.equals("true")) {
299-
LOGGER.info("gather git situation from GitHub Actions environment variable: GITHUB_REF");
303+
// TODO
304+
// skip if head hash differs from GITHUB_SHA
305+
// if(System.getenv("GITHUB_SHA").equals(repository.resolve(HEAD).getName())) {}
306+
307+
project.getLogger().lifecycle("gather git situation from GitHub Actions environment variable: GITHUB_REF");
300308
String githubRef = System.getenv("GITHUB_REF");
301-
LOGGER.debug(" GITHUB_REF: " + githubRef);
309+
project.getLogger().debug(" GITHUB_REF: " + githubRef);
302310
if (githubRef != null && githubRef.startsWith("refs/")) {
303311
if (githubRef.startsWith("refs/tags/")) {
304312
overrideTag = githubRef;
@@ -315,13 +323,13 @@ private GitSituation getGitSituation(File executionRootDirectory) throws IOExcep
315323
if (overrideBranch == null && overrideTag == null) {
316324
final String gitlabEnv = System.getenv("GITLAB_CI");
317325
if (gitlabEnv != null && gitlabEnv.equals("true")) {
318-
LOGGER.info("gather git situation from GitLab CI environment variables: CI_COMMIT_BRANCH, CI_COMMIT_TAG and CI_MERGE_REQUEST_SOURCE_BRANCH_NAME");
326+
project.getLogger().lifecycle("gather git situation from GitLab CI environment variables: CI_COMMIT_BRANCH, CI_COMMIT_TAG and CI_MERGE_REQUEST_SOURCE_BRANCH_NAME");
319327
String commitBranch = System.getenv("CI_COMMIT_BRANCH");
320328
String commitTag = System.getenv("CI_COMMIT_TAG");
321329
String mrSourceBranch = System.getenv("CI_MERGE_REQUEST_SOURCE_BRANCH_NAME");
322-
LOGGER.debug(" CI_COMMIT_BRANCH: " + commitBranch);
323-
LOGGER.debug(" CI_COMMIT_TAG: " + commitTag);
324-
LOGGER.debug(" CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: " + mrSourceBranch);
330+
project.getLogger().debug(" CI_COMMIT_BRANCH: " + commitBranch);
331+
project.getLogger().debug(" CI_COMMIT_TAG: " + commitTag);
332+
project.getLogger().debug(" CI_MERGE_REQUEST_SOURCE_BRANCH_NAME: " + mrSourceBranch);
325333
overrideBranch = commitBranch == null ? mrSourceBranch : commitBranch;
326334
overrideTag = commitTag;
327335
}
@@ -331,11 +339,11 @@ private GitSituation getGitSituation(File executionRootDirectory) throws IOExcep
331339
if (overrideBranch == null && overrideTag == null) {
332340
final String circleciEnv = System.getenv("CIRCLECI");
333341
if (circleciEnv != null && circleciEnv.equals("true")) {
334-
LOGGER.info("gather git situation from Circle CI environment variables: CIRCLE_BRANCH and CIRCLE_TAG");
342+
project.getLogger().lifecycle("gather git situation from Circle CI environment variables: CIRCLE_BRANCH and CIRCLE_TAG");
335343
String commitBranch = System.getenv("CIRCLE_BRANCH");
336344
String commitTag = System.getenv("CIRCLE_TAG");
337-
LOGGER.debug(" CIRCLE_BRANCH: " + commitBranch);
338-
LOGGER.debug(" CIRCLE_TAG: " + commitTag);
345+
project.getLogger().debug(" CIRCLE_BRANCH: " + commitBranch);
346+
project.getLogger().debug(" CIRCLE_TAG: " + commitTag);
339347
overrideBranch = System.getenv("CIRCLE_BRANCH");
340348
overrideTag = System.getenv("CIRCLE_TAG");
341349
}
@@ -345,11 +353,11 @@ private GitSituation getGitSituation(File executionRootDirectory) throws IOExcep
345353
if (overrideBranch == null && overrideTag == null) {
346354
final String jenkinsEnv = System.getenv("JENKINS_HOME");
347355
if (jenkinsEnv != null && !jenkinsEnv.trim().isEmpty()) {
348-
LOGGER.info("gather git situation from jenkins environment variables: BRANCH_NAME and TAG_NAME");
356+
project.getLogger().lifecycle("gather git situation from jenkins environment variables: BRANCH_NAME and TAG_NAME");
349357
String branchName = System.getenv("BRANCH_NAME");
350358
String tagName = System.getenv("TAG_NAME");
351-
LOGGER.debug(" BRANCH_NAME: " + branchName);
352-
LOGGER.debug(" TAG_NAME: " + tagName);
359+
project.getLogger().debug(" BRANCH_NAME: " + branchName);
360+
project.getLogger().debug(" TAG_NAME: " + tagName);
353361
if (branchName != null && branchName.equals(tagName)) {
354362
overrideTag = tagName;
355363
overrideBranch = "";
@@ -382,7 +390,7 @@ void overrideBranch(String branch) {
382390
.replaceFirst("^heads/", "");
383391
}
384392

385-
LOGGER.debug("override git branch with: " + branch);
393+
project.getLogger().debug("override git branch with: " + branch);
386394
setBranch(branch);
387395
}
388396

@@ -399,7 +407,7 @@ void overrideTags(String tag) {
399407
tag = tag.replaceFirst("^refs/tags/", "");
400408
}
401409

402-
LOGGER.debug("override git tags with: " + tag);
410+
project.getLogger().debug("override git tags with: " + tag);
403411
setTags(tag == null ? emptyList() : singletonList(tag));
404412
}
405413
};

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

+1-1
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.1.1"
6+
id("me.qoomon.git-versioning") version "6.3.7"
77
}
88

99
gitVersioning.apply {

0 commit comments

Comments
 (0)