use of org.jreleaser.util.Version in project jreleaser by jreleaser.
the class ChangelogGenerator method resolveCommits.
protected Iterable<RevCommit> resolveCommits(Git git, JReleaserContext context) throws GitAPIException, IOException {
List<Ref> tags = git.tagList().call();
GitService gitService = context.getModel().getRelease().getGitService();
String effectiveTagName = gitService.getEffectiveTagName(context.getModel());
String tagName = gitService.getConfiguredTagName();
String tagPattern = tagName.replaceAll("\\{\\{.*}}", "\\.\\*");
Pattern vp = Pattern.compile(tagName.replaceAll("\\{\\{.*}}", "\\(\\.\\*\\)"));
if (!tagName.contains("{{")) {
vp = Pattern.compile("(.*)");
}
Pattern versionPattern = vp;
unparseableTags.clear();
tags.sort((tag1, tag2) -> {
Version v1 = version(context, tag1, versionPattern);
Version v2 = version(context, tag2, versionPattern);
return v2.compareTo(v1);
});
ObjectId head = git.getRepository().resolve(Constants.HEAD);
context.getLogger().debug(RB.$("changelog.generator.lookup.tag"), effectiveTagName);
Optional<Ref> tag = tags.stream().filter(ref -> extractTagName(ref).equals(effectiveTagName)).findFirst();
Optional<Ref> previousTag = Optional.empty();
String previousTagName = gitService.getConfiguredPreviousTagName();
if (isNotBlank(previousTagName)) {
context.getLogger().debug(RB.$("changelog.generator.lookup.previous.tag"), previousTagName);
previousTag = tags.stream().filter(ref -> extractTagName(ref).equals(previousTagName)).findFirst();
}
Version currentVersion = context.getModel().getProject().version();
Version defaultVersion = defaultVersion(context);
// tag: early-access
if (context.getModel().getProject().isSnapshot()) {
Project.Snapshot snapshot = context.getModel().getProject().getSnapshot();
String effectiveLabel = snapshot.getEffectiveLabel();
if (effectiveLabel.equals(effectiveTagName)) {
if (snapshot.isFullChangelog()) {
tag = Optional.empty();
}
if (!tag.isPresent()) {
if (previousTag.isPresent()) {
tag = previousTag;
}
if (!tag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.lookup.matching.tag"), tagPattern, effectiveTagName);
tag = tags.stream().filter(ref -> !extractTagName(ref).equals(effectiveTagName)).filter(ref -> versionPattern.matcher(extractTagName(ref)).matches()).filter(ref -> currentVersion.equalsSpec(version(context, ref, versionPattern, true))).filter(ref -> !defaultVersion.equals(version(context, ref, versionPattern, true))).findFirst();
}
}
if (tag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.tag.found"), extractTagName(tag.get()));
ObjectId fromRef = getObjectId(git, tag.get());
return git.log().addRange(fromRef, head).call();
} else {
return git.log().add(head).call();
}
}
}
// tag: latest
if (!tag.isPresent()) {
if (previousTag.isPresent()) {
tag = previousTag;
}
if (!tag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.lookup.matching.tag"), tagPattern, effectiveTagName);
tag = tags.stream().filter(ref -> !extractTagName(ref).equals(effectiveTagName)).filter(ref -> versionPattern.matcher(extractTagName(ref)).matches()).filter(ref -> currentVersion.equalsSpec(version(context, ref, versionPattern, true))).filter(ref -> !defaultVersion.equals(version(context, ref, versionPattern, true))).findFirst();
}
if (tag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.tag.found"), extractTagName(tag.get()));
ObjectId fromRef = getObjectId(git, tag.get());
return git.log().addRange(fromRef, head).call();
}
return git.log().add(head).call();
}
// tag: somewhere in the middle
if (!previousTag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.lookup.before.tag"), effectiveTagName, tagPattern);
previousTag = tags.stream().filter(ref -> extractTagName(ref).matches(tagPattern)).filter(ref -> !defaultVersion.equals(version(context, ref, versionPattern, true))).filter(ref -> lessThan(version(context, ref, versionPattern, true), currentVersion)).findFirst();
}
if (previousTag.isPresent()) {
context.getLogger().debug(RB.$("changelog.generator.tag.found"), extractTagName(previousTag.get()));
ObjectId fromRef = getObjectId(git, previousTag.get());
ObjectId toRef = getObjectId(git, tag.get());
return git.log().addRange(fromRef, toRef).call();
}
ObjectId toRef = getObjectId(git, tag.get());
return git.log().add(toRef).call();
}
Aggregations