Skip to content

Commit 588a492

Browse files
committed
Determine previous release commit for always-use-branch release Trains.
Closes #108
1 parent 31745c6 commit 588a492

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

src/main/java/org/springframework/data/release/git/GitOperations.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,18 @@ protected ObjectId resolveLowerBoundary(SupportStatus supportStatus, Project pro
575575
if (iteration.contains(project)) {
576576

577577
Iteration it = iteration.getIteration();
578+
579+
if (iteration.getTrain().isAlwaysUseBranch()) {
580+
581+
Branch from = Branch.from(iteration.getModule(project));
582+
String message = expandSummary("Release version %s", iteration.getModule(project), iteration);
583+
584+
RevCommit releaseCommit = findCommit(git, from, message);
585+
if (releaseCommit != null) {
586+
return releaseCommit;
587+
}
588+
}
589+
578590
Optional<Tag> fromTag = tags.filter(iteration.getTrain()).findTag(it);
579591

580592
if (!fromTag.isPresent()) {
@@ -583,13 +595,11 @@ protected ObjectId resolveLowerBoundary(SupportStatus supportStatus, Project pro
583595
if (supportStatus == SupportStatus.COMMERCIAL && (it.isServiceIteration() || it.isGAIteration())) {
584596

585597
Branch from = Branch.from(iteration.getModule(project));
586-
Iterable<RevCommit> commits = git.log().add(repo.resolve(from.toString())).call();
587-
588-
Optional<RevCommit> first = Streamable.of(commits).stream()
589-
.filter(rev -> rev.getFullMessage().contains("Seed " + from + " branch")).findFirst();
598+
String message = "Seed " + from + " branch";
590599

591-
if (first.isPresent()) {
592-
return first.get();
600+
RevCommit first = findCommit(git, from, message);
601+
if (first != null) {
602+
return first;
593603
}
594604
}
595605

@@ -606,6 +616,16 @@ protected ObjectId resolveLowerBoundary(SupportStatus supportStatus, Project pro
606616
return repo.resolve(getFirstCommit(repo));
607617
}
608618

619+
private static RevCommit findCommit(Git git, Branch branch, String message) throws GitAPIException, IOException {
620+
621+
Iterable<RevCommit> commits = git.log().add(git.getRepository().resolve(branch.toString())).call();
622+
623+
Optional<RevCommit> first = Streamable.of(commits).stream().filter(rev -> rev.getFullMessage().contains(message))
624+
.findFirst();
625+
626+
return first.orElse(null);
627+
}
628+
609629
protected ObjectId resolveUpperBoundary(ModuleIteration iteration, VersionTags tags, Repository repo)
610630
throws IOException {
611631

@@ -1133,7 +1153,7 @@ private Predicate<RevCommit> calculateFilter(ModuleIteration module, String summ
11331153
private Optional<Tag> findTagFor(SupportedProject project, ArtifactVersion version) {
11341154

11351155
return getTags(project).stream()//
1136-
.filter(tag -> tag.toArtifactVersion().map(it -> it.equals(version)).orElse(false))//
1156+
.filter(tag -> tag.getArtifactVersion().map(it -> it.equals(version)).orElse(false))//
11371157
.findFirst();
11381158
}
11391159

src/main/java/org/springframework/data/release/git/Tag.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
*/
1616
package org.springframework.data.release.git;
1717

18-
import lombok.AccessLevel;
1918
import lombok.EqualsAndHashCode;
2019
import lombok.Getter;
21-
import lombok.RequiredArgsConstructor;
2220

2321
import java.time.LocalDateTime;
2422
import java.util.Optional;
2523

2624
import org.springframework.data.release.model.ArtifactVersion;
25+
import org.springframework.lang.Nullable;
2726

2827
/**
2928
* Value object to represent an SCM tag.
@@ -32,13 +31,35 @@
3231
* @author Mark Paluch
3332
*/
3433
@EqualsAndHashCode
35-
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
36-
@Getter
3734
public class Tag implements Comparable<Tag> {
3835

36+
@Getter
3937
private final String name;
38+
@Getter
4039
private final LocalDateTime creationDate;
4140

41+
private final @Nullable ArtifactVersion artifactVersion;
42+
43+
private Tag(String name, LocalDateTime creationDate, @Nullable ArtifactVersion artifactVersion) {
44+
this.name = name;
45+
this.creationDate = creationDate;
46+
this.artifactVersion = artifactVersion;
47+
}
48+
49+
private Tag(String name, LocalDateTime creationDate) {
50+
this.name = name;
51+
this.creationDate = creationDate;
52+
53+
ArtifactVersion artifactVersion;
54+
try {
55+
artifactVersion = ArtifactVersion.of(getVersionSource());
56+
} catch (Exception e) {
57+
artifactVersion = null;
58+
}
59+
60+
this.artifactVersion = artifactVersion;
61+
}
62+
4263
public static Tag of(String source) {
4364
return of(source, LocalDateTime.now());
4465
}
@@ -61,20 +82,20 @@ private String getVersionSource() {
6182
}
6283

6384
public boolean isVersionTag() {
64-
return toArtifactVersion().isPresent();
85+
return getArtifactVersion().isPresent();
6586
}
6687

67-
public Optional<ArtifactVersion> toArtifactVersion() {
68-
69-
try {
70-
return Optional.of(getRequiredArtifactVersion());
71-
} catch (IllegalArgumentException o_O) {
72-
return Optional.empty();
73-
}
88+
public Optional<ArtifactVersion> getArtifactVersion() {
89+
return Optional.ofNullable(artifactVersion);
7490
}
7591

7692
public ArtifactVersion getRequiredArtifactVersion() {
77-
return ArtifactVersion.of(getVersionSource());
93+
94+
if (artifactVersion == null) {
95+
throw new IllegalStateException(String.format("Artifact version not set for tag '%s'", name));
96+
}
97+
98+
return this.artifactVersion;
7899
}
79100

80101
/**
@@ -84,7 +105,8 @@ public ArtifactVersion getRequiredArtifactVersion() {
84105
* @return
85106
*/
86107
public Tag createNew(ArtifactVersion version) {
87-
return new Tag(name.startsWith("v") ? "v".concat(version.toString()) : version.toString(), LocalDateTime.now());
108+
return new Tag(name.startsWith("v") ? "v".concat(version.toString()) : version.toString(), LocalDateTime.now(),
109+
artifactVersion);
88110
}
89111

90112
/*
@@ -105,7 +127,7 @@ public int compareTo(Tag that) {
105127

106128
// Prefer artifact versions but fall back to name comparison
107129

108-
return toArtifactVersion().map(left -> that.toArtifactVersion().map(right -> left.compareTo(right)).//
130+
return getArtifactVersion().map(left -> that.getArtifactVersion().map(right -> left.compareTo(right)).//
109131
orElse(name.compareTo(that.name))).orElse(name.compareTo(that.name));
110132
}
111133
}

src/main/java/org/springframework/data/release/git/VersionTags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Map<Tag, TrainIteration> withIterations() {
159159

160160
for (Tag tag : tags) {
161161

162-
Optional<ArtifactVersion> artifactVersion = tag.toArtifactVersion();
162+
Optional<ArtifactVersion> artifactVersion = tag.getArtifactVersion();
163163
if (!artifactVersion.isPresent()) {
164164
continue;
165165
}

src/main/java/org/springframework/data/release/projectservice/ProjectServiceOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private List<MaintainedVersion> getLatestVersion(Module module, Train train) {
207207
.filter(tag -> matches(tag, module.getVersion())).max(Comparator.naturalOrder()) //
208208
.map(it -> {
209209
MaintainedVersion maintainedVersion = MaintainedVersion.of(module.getProject(),
210-
it.toArtifactVersion().get(),
210+
it.getRequiredArtifactVersion(),
211211
train, it.getCreationDate().toLocalDate(), it.getCreationDate().toLocalDate());
212212
return Arrays.asList(maintainedVersion, maintainedVersion.nextDevelopmentVersion());
213213
}) //
@@ -227,7 +227,7 @@ private List<MaintainedVersion> getLatestVersion(Module module, Train train) {
227227
*/
228228
private static boolean matches(Tag tag, Version version) {
229229

230-
return tag.toArtifactVersion()//
230+
return tag.getArtifactVersion()//
231231
.map(it -> it.isVersionWithin(version))//
232232
.orElse(false);
233233
}

0 commit comments

Comments
 (0)