Search in sources :

Example 1 with Version

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();
}
Also used : MustacheUtils.applyTemplate(org.jreleaser.util.MustacheUtils.applyTemplate) StringUtils.isNotBlank(org.jreleaser.util.StringUtils.isNotBlank) User(org.jreleaser.model.releaser.spi.User) Matcher(java.util.regex.Matcher) Map(java.util.Map) KEY_CHANGELOG_CONTRIBUTORS(org.jreleaser.util.Constants.KEY_CHANGELOG_CONTRIBUTORS) SemVer(org.jreleaser.util.SemVer) JavaRuntimeVersion(org.jreleaser.util.JavaRuntimeVersion) Templates.resolveTemplate(org.jreleaser.util.Templates.resolveTemplate) GitSdk.extractTagName(org.jreleaser.sdk.git.GitSdk.extractTagName) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) StringUtils.normalizeRegexPattern(org.jreleaser.util.StringUtils.normalizeRegexPattern) StringUtils.stripMargin(org.jreleaser.util.StringUtils.stripMargin) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) StringUtils(org.jreleaser.util.StringUtils) Collectors(java.util.stream.Collectors) Project(org.jreleaser.model.Project) Objects(java.util.Objects) Gitlab(org.jreleaser.model.Gitlab) List(java.util.List) Ref(org.eclipse.jgit.lib.Ref) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) GitService(org.jreleaser.model.GitService) RB(org.jreleaser.bundle.RB) CalVer(org.jreleaser.util.CalVer) MustacheUtils.passThrough(org.jreleaser.util.MustacheUtils.passThrough) CollectionUtils(org.jreleaser.util.CollectionUtils) RevCommit(org.eclipse.jgit.revwalk.RevCommit) System.lineSeparator(java.lang.System.lineSeparator) Changelog(org.jreleaser.model.Changelog) KEY_CHANGELOG_CHANGES(org.jreleaser.util.Constants.KEY_CHANGELOG_CHANGES) ChronVer(org.jreleaser.util.ChronVer) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ComparatorUtils.lessThan(org.jreleaser.util.ComparatorUtils.lessThan) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) StringUtils.toSafeRegexPattern(org.jreleaser.util.StringUtils.toSafeRegexPattern) JReleaserContext(org.jreleaser.model.JReleaserContext) StreamSupport(java.util.stream.StreamSupport) LinkedHashSet(java.util.LinkedHashSet) IOException(java.io.IOException) Version(org.jreleaser.util.Version) ObjectId(org.eclipse.jgit.lib.ObjectId) CustomVersion(org.jreleaser.util.CustomVersion) JavaModuleVersion(org.jreleaser.util.JavaModuleVersion) Git(org.eclipse.jgit.api.Git) Comparator(java.util.Comparator) StringUtils.normalizeRegexPattern(org.jreleaser.util.StringUtils.normalizeRegexPattern) Pattern(java.util.regex.Pattern) StringUtils.toSafeRegexPattern(org.jreleaser.util.StringUtils.toSafeRegexPattern) Project(org.jreleaser.model.Project) Ref(org.eclipse.jgit.lib.Ref) JavaRuntimeVersion(org.jreleaser.util.JavaRuntimeVersion) Version(org.jreleaser.util.Version) CustomVersion(org.jreleaser.util.CustomVersion) JavaModuleVersion(org.jreleaser.util.JavaModuleVersion) ObjectId(org.eclipse.jgit.lib.ObjectId) GitService(org.jreleaser.model.GitService)

Aggregations

IOException (java.io.IOException)1 System.lineSeparator (java.lang.System.lineSeparator)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 StreamSupport (java.util.stream.StreamSupport)1 Git (org.eclipse.jgit.api.Git)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 Constants (org.eclipse.jgit.lib.Constants)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1