com.labun.buildnumber.JGitBuildNumberGradleTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgit-buildnumber-gradle-plugin Show documentation
Show all versions of jgit-buildnumber-gradle-plugin Show documentation
Extracts Git metadata and a freely composable build number in pure Java without Git command-line tool.
The newest version!
package com.labun.buildnumber;
import java.io.File;
import java.util.Map;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
import lombok.Getter;
import lombok.Setter;
/** Extracts Git metadata and creates build number. Publishes them as project properties. */
@Getter
@Setter
public class JGitBuildNumberGradleTask extends DefaultTask implements Parameters {
@Input @Optional private String namespace;
@Input @Optional private String dirtyValue;
@Input @Optional private Integer shortRevisionLength;
@Input @Optional private String gitDateFormat;
@Input @Optional private String buildDateFormat;
@Input @Optional private String dateFormatTimeZone;
@Input @Optional private String countCommitsSinceInclusive;
@Input @Optional private String countCommitsSinceExclusive;
@Input @Optional private String countCommitsInPath;
@Input @Optional private String buildNumberFormat;
@InputDirectory @Optional private File repositoryDirectory;
@Input @Optional private Boolean runOnlyAtExecutionRoot;
@Input @Optional private Boolean skip;
@Input @Optional private Boolean verbose;
@TaskAction
public void extractBuildnumber() throws Exception {
// set some parameters to Gradle specific values
if (getRepositoryDirectory() == null) setRepositoryDirectory(getProject().getProjectDir());
validateAndSetParameterValues();
if (skip) {
getLogger().lifecycle("Execution is skipped by configuration.");
return;
}
Map properties = new BuildNumberExtractor(this, msg -> getLogger().lifecycle(msg)).extract(); // "info" level will not be printed by default
getProject().getExtensions().add(Map.class, namespace, properties);
}
}