Skip to content

Commit

Permalink
[core] rework custom tag resolution. Relates to #275
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 10, 2021
1 parent 659c123 commit 66087ae
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(Constants.KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public String getResolvedTagName(JReleaserModel model) {
return cachedTagName;
}

public String getEffectiveTagName() {
public String getEffectiveTagName(JReleaserModel model) {
if (model.getProject().isSnapshot()) {
return model.getProject().getSnapshot().getResolvedLabel(model);
}
return cachedTagName;
}

Expand Down Expand Up @@ -686,7 +689,7 @@ public void fillProps(Map<String, Object> props, JReleaserModel model) {
props.put(Constants.KEY_REPO_BRANCH, branch);
props.put(Constants.KEY_REVERSE_REPO_HOST, getReverseRepoHost());
props.put(Constants.KEY_CANONICAL_REPO_NAME, getCanonicalRepoName());
props.put(Constants.KEY_TAG_NAME, getEffectiveTagName());
props.put(Constants.KEY_TAG_NAME, getEffectiveTagName(model));
props.put(Constants.KEY_RELEASE_NAME, getEffectiveReleaseName());
props.put(Constants.KEY_MILESTONE_NAME, milestone.getEffectiveName());
props.put(Constants.KEY_REPO_URL, getResolvedRepoUrl(model));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void report() {
props.put(KEY_PROJECT_VERSION, project.getVersion());
props.put(KEY_PROJECT_SNAPSHOT, String.valueOf(project.isSnapshot()));
GitService gitService = model.getRelease().getGitService();
props.put(KEY_TAG_NAME, gitService.getEffectiveTagName());
props.put(KEY_TAG_NAME, gitService.getEffectiveTagName(model));
if (gitService.isReleaseSupported()) {
props.put(KEY_RELEASE_NAME, gitService.getEffectiveReleaseName());
props.put(KEY_MILESTONE_NAME, gitService.getMilestone().getEffectiveName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void fillReleaseProperties(Map<String, Object> props, Release release) {
props.put(Constants.KEY_REPO_OWNER, service.getOwner());
props.put(Constants.KEY_REPO_NAME, service.getName());
props.put(Constants.KEY_REPO_BRANCH, service.getBranch());
props.put(Constants.KEY_TAG_NAME, service.getEffectiveTagName());
props.put(Constants.KEY_TAG_NAME, service.getEffectiveTagName(this));
props.put(Constants.KEY_RELEASE_NAME, service.getEffectiveReleaseName());
props.put(Constants.KEY_MILESTONE_NAME, service.getMilestone().getEffectiveName());
props.put(Constants.KEY_REVERSE_REPO_HOST, service.getReverseRepoHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ void setAll(Mail mail) {
public String getResolvedSubject(JReleaserContext context) {
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName(context.getModel()));
return applyTemplate(subject, props);
}

public String getResolvedMessage(JReleaserContext context) {
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService().getEffectiveTagName(context.getModel()));
return applyTemplate(message, props);
}

public String getResolvedMessageTemplate(JReleaserContext context, Map<String, Object> extraProps) {
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ public String getResolvedVersion() {
return isNotBlank(resolvedVersion) ? resolvedVersion : "";
}

public String getResolvedSnapshotPattern() {
snapshotPattern = Env.resolve(PROJECT_SNAPSHOT_PATTERN, snapshotPattern);
if (isBlank(snapshotPattern)) {
snapshotPattern = DEFAULT_SNAPSHOT_PATTERN;
}
return snapshotPattern;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public String getResolvedMessageTemplate(JReleaserContext context, Map<String, O
Map<String, Object> props = context.props();
applyTemplates(props, getResolvedExtraProperties());
props.put(KEY_TAG_NAME, context.getModel().getRelease().getGitService()
.getEffectiveTagName());
.getEffectiveTagName(context.getModel()));
props.putAll(extraProps);

Path templatePath = context.getBasedir().resolve(messageTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,10 @@ public static void validateProject(JReleaserContext context, JReleaserContext.Mo
project.getSnapshot().getLabel(),
DEFAULT_SNAPSHOT_LABEL));

if(isNotBlank(project.getSnapshotPattern())) {
if (isNotBlank(project.getSnapshotPattern())) {
context.nag("0.6.0", "project.snapshotPattern has been deprecated. Use project.snapshot.pattern instead");
}

if (project.isSnapshot()) {
context.getModel().getRelease().getGitService().setTagName(
project.getSnapshot().getResolvedLabel(context.getModel()));
}

boolean javaDistributions = context.getModel().getDistributions().values().stream()
.map(Distribution::getType)
.anyMatch(type -> type == Distribution.DistributionType.JAVA_BINARY ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void release() throws ReleaseException {
org.jreleaser.model.GenericGit generic = context.getModel().getRelease().getGeneric();
context.getLogger().info("Releasing to a generic Git repository is not supported");
context.getLogger().info("Tagging {}", repository.getHttpUrl());
String tagName = generic.getEffectiveTagName();
String tagName = generic.getEffectiveTagName(context.getModel());

context.getLogger().debug("looking up tag {}", tagName);
boolean tagged = git.findTag(tagName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ private static Iterable<RevCommit> resolveCommits(Git git, JReleaserContext cont
List<Ref> tags = git.tagList().call();

GitService gitService = context.getModel().getRelease().getGitService();
String effectiveTagName = gitService.getEffectiveTagName();
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;
System.out.println("effectiveTagName = " + effectiveTagName);
System.out.println("tagName = " + tagName);
System.out.println("tagPattern = " + tagPattern);
System.out.println("vp = " + vp);

tags.sort((tag1, tag2) -> {
Comparable v1 = version(context, tag1, versionPattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected Repository.Kind resolveRepositoryKind() {
public void release() throws ReleaseException {
org.jreleaser.model.Gitea gitea = resolveGiteaFromModel();
context.getLogger().info("Releasing to {}", gitea.getResolvedRepoUrl(context.getModel()));
String tagName = gitea.getEffectiveTagName();
String tagName = gitea.getEffectiveTagName(context.getModel());

try {
String changelog = context.getChangelog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GithubReleaser implements Releaser {
public void release() throws ReleaseException {
org.jreleaser.model.Github github = context.getModel().getRelease().getGithub();
context.getLogger().info("Releasing to {}", github.getResolvedRepoUrl(context.getModel()));
String tagName = github.getEffectiveTagName();
String tagName = github.getEffectiveTagName(context.getModel());

try {
String changelog = context.getChangelog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class GitlabReleaser implements Releaser {
public void release() throws ReleaseException {
org.jreleaser.model.Gitlab gitlab = context.getModel().getRelease().getGitlab();
context.getLogger().info("Releasing to {}", gitlab.getResolvedRepoUrl(context.getModel()));
String tagName = gitlab.getEffectiveTagName();
String tagName = gitlab.getEffectiveTagName(context.getModel());

try {
String changelog = context.getChangelog();
Expand Down

0 comments on commit 66087ae

Please sign in to comment.