use of com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription in project maven-git-versioning-extension by qoomon.
the class VersioningModelProcessor method deduceProjectVersion.
private ProjectVersion deduceProjectVersion(GAV gav, File gitDir) throws IOException {
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder().findGitDir(gitDir);
logger.debug(gav + "git directory " + repositoryBuilder.getGitDir());
try (Repository repository = repositoryBuilder.build()) {
final String headCommit = getHeadCommit(repository);
String projectBranchName = null;
String projectTagName = null;
VersionFormatDescription projectVersionFormatDescription = null;
Map<String, String> projectVersionDataMap = buildCommonVersionDataMap(headCommit, gav);
if (!configuration.getTagVersionDescriptions().isEmpty()) {
final List<String> headTags = getHeadTags(repository);
if (!headTags.isEmpty()) {
for (VersionFormatDescription versionFormatDescription : configuration.getTagVersionDescriptions()) {
String tagName = headTags.stream().sequential().filter(tag -> tag.matches(versionFormatDescription.pattern)).sorted((versionLeft, versionRight) -> {
DefaultArtifactVersion tagVersionLeft = new DefaultArtifactVersion(removePrefix(versionLeft, versionFormatDescription.prefix));
DefaultArtifactVersion tagVersionRight = new DefaultArtifactVersion(removePrefix(versionRight, versionFormatDescription.prefix));
// -1 revert sorting, latest version first
return tagVersionLeft.compareTo(tagVersionRight) * -1;
}).findFirst().orElse(null);
if (tagName != null) {
projectTagName = tagName;
projectVersionFormatDescription = versionFormatDescription;
projectVersionDataMap.put("tag", removePrefix(projectTagName, projectVersionFormatDescription.prefix));
projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectTagName));
break;
}
}
}
}
if (projectTagName == null) {
final String branchName = getHeadBranch(repository).orElseThrow(() -> new ModelParseException(gitDir + ": No Branch Name provided in Detached HEAD state. See documentation.", 0, 0));
projectBranchName = branchName;
projectVersionFormatDescription = configuration.getBranchVersionDescriptions().stream().filter(versionFormatDescription -> branchName.matches(versionFormatDescription.pattern)).findFirst().orElseThrow(() -> new ModelParseException(gitDir + ": No version format for branch '" + branchName + "' found.", 0, 0));
projectVersionDataMap.put("branch", removePrefix(projectBranchName, projectVersionFormatDescription.prefix));
projectVersionDataMap.putAll(getRegexGroupValueMap(projectVersionFormatDescription.pattern, projectBranchName));
}
String version = StrSubstitutor.replace(projectVersionFormatDescription.versionFormat, projectVersionDataMap);
ProjectVersion projectVersion = new ProjectVersion(escapeVersion(version), headCommit, projectBranchName, projectTagName);
logger.info(gav.getArtifactId() + ":" + gav.getVersion() + (projectVersion.getTag() != null ? " - tag: " + projectVersion.getTag() : "") + (projectVersion.getTag() != null ? " - branch: " + projectVersion.getBranch() : "") + " -> version: " + projectVersion.getVersion());
return projectVersion;
}
}
use of com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription in project maven-git-versioning-extension by qoomon.
the class VersioningConfigurationProvider method defaultVersionDescription.
private static VersionFormatDescription defaultVersionDescription() {
VersionFormatDescription result = new VersionFormatDescription();
result.pattern = ".*";
result.versionFormat = "${branch}-SNAPSHOT";
return result;
}
use of com.qoomon.maven.extension.gitversioning.config.model.VersionFormatDescription in project maven-git-versioning-extension by qoomon.
the class VersioningConfigurationProvider method get.
public VersioningConfiguration get() {
if (configuration == null) {
MavenSession session = SessionScopeUtil.get(sessionScope, MavenSession.class).get();
List<VersionFormatDescription> branchVersionDescriptions = new LinkedList<>();
List<VersionFormatDescription> tagVersionDescriptions = new LinkedList<>();
File configFile = ExtensionUtil.getConfigFile(session.getRequest(), BuildProperties.projectArtifactId());
if (configFile.exists()) {
Configuration configurationModel = loadConfiguration(configFile);
branchVersionDescriptions.addAll(configurationModel.branches);
tagVersionDescriptions.addAll(configurationModel.tags);
} else {
logger.info("No configuration file found. Apply default configuration.");
}
branchVersionDescriptions.add(DEFAULT_BRANCH_VERSION_DESCRIPTION);
configuration = new VersioningConfiguration(branchVersionDescriptions, tagVersionDescriptions);
}
return configuration;
}
Aggregations