Skip to content

Commit d2fe773

Browse files
committed
On delayed tag: release branch wrongly calculated from dev.version.minor(-1) #54
1 parent 481cfeb commit d2fe773

21 files changed

+703
-814
lines changed

docs/minor-release-status.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ Status denotes next action which should be undertaken to finish patch build: {AC
4444
- RB does not exist or RB.patch < 1 => ERROR, show error on status command
4545
- mdeps are not locked => ERROR
4646
- `subComponents` are calculated using mdeps from particular RB
47-
- Any component is in ERROR status => ERROR
48-
- Last tag != RB.patch(-1) or Last delayed tag != RB.patch => ERROR
49-
- Wrong version could be used by root component
5047
- Any component is not in DONE status => BUILD_MDEPS
5148
- Any component has patch which is greater than one mentioned in `mdeps` => ACTUALIZE_PATCHES
5249
- No valuable commits after last tag => DONE

src/main/java/org/scm4j/releaser/ActionTreeBuilder.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package org.scm4j.releaser;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
import java.util.Map;
6-
7-
import org.scm4j.commons.Version;
83
import org.scm4j.releaser.actions.ActionSet;
94
import org.scm4j.releaser.actions.IAction;
10-
import org.scm4j.releaser.branch.DevelopBranch;
11-
import org.scm4j.releaser.conf.Component;
12-
import org.scm4j.releaser.conf.VCSRepository;
13-
import org.scm4j.releaser.conf.VCSRepositoryFactory;
5+
import org.scm4j.releaser.conf.*;
146
import org.scm4j.releaser.exceptions.EBuildOnNotForkedRelease;
15-
import org.scm4j.releaser.exceptions.EInconsistentCompState;
7+
import org.scm4j.releaser.exceptions.ENoDelayedTags;
168
import org.scm4j.releaser.scmactions.SCMActionRelease;
179
import org.scm4j.releaser.scmactions.SCMActionTag;
1810

11+
import java.util.ArrayList;
12+
import java.util.List;
13+
import java.util.Map;
14+
1915
public class ActionTreeBuilder {
2016

2117
private final VCSRepositoryFactory repoFactory;
@@ -46,10 +42,6 @@ private IAction getActionTree(ExtendedStatus node, CachedStatuses cache, ActionS
4642
childActions.add(getActionTree(nodeEntry.getValue(), cache, actionSet, false));
4743
}
4844

49-
if (node.getStatus() == BuildStatus.ERROR) {
50-
throw new EInconsistentCompState(node.getComp(), node.getErrorDesc());
51-
}
52-
5345
if (node.getStatus() == BuildStatus.FORK && actionSet == ActionSet.FULL) {
5446
throw new EBuildOnNotForkedRelease(node.getComp());
5547
}
@@ -60,14 +52,11 @@ private IAction getActionTree(ExtendedStatus node, CachedStatuses cache, ActionS
6052

6153
public IAction getTagAction(Component comp) {
6254
VCSRepository repo = repoFactory.getVCSRepository(comp);
63-
// DelayedTagsFile dtf = new DelayedTagsFile();
64-
// String revisionToTag = dtf.getRevisitonByUrl(repo.getUrl());
65-
// if (revisionToTag == null) {
66-
// throw new ENoRevisionsToTag();
67-
// }
68-
// FIXME: fix
69-
Version lastReleaseVersion = new DevelopBranch(comp, repo).getVersion().toPreviousMinor();
70-
//new Version(repo.getVCS().getFileContent(null, Utils.VER_FILE_NAME, dtf.getRevisitonByUrl(repo.getUrl())));
71-
return new SCMActionTag(comp, Utils.getReleaseBranchName(repo, lastReleaseVersion), repo);
55+
DelayedTagsFile dtf = new DelayedTagsFile();
56+
DelayedTag delayedTag = dtf.getDelayedTagByUrl(repo.getUrl());
57+
if (delayedTag == null) {
58+
throw new ENoDelayedTags(repo.getUrl());
59+
}
60+
return new SCMActionTag(comp, repo);
7261
}
7362
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.scm4j.releaser;
22

33
public enum BuildStatus {
4-
FORK, LOCK, BUILD_MDEPS, ACTUALIZE_PATCHES, BUILD, DONE, ERROR
4+
FORK, LOCK, BUILD_MDEPS, ACTUALIZE_PATCHES, BUILD, DONE
55
}

src/main/java/org/scm4j/releaser/ExtendedStatus.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@ public class ExtendedStatus {
1515
private final BuildStatus status;
1616
private final LinkedHashMap<Component, ExtendedStatus> subComponents;
1717
private final VCSRepository repo;
18-
private final String errorDesc;
19-
20-
public ExtendedStatus(Version nextVersion, BuildStatus status,
21-
LinkedHashMap<Component, ExtendedStatus> subComponents, Component comp, VCSRepository repo) {
22-
this(nextVersion, status, subComponents, comp, repo, null);
23-
}
2418

2519
public ExtendedStatus(Version nextVersion, BuildStatus status,
26-
LinkedHashMap<Component, ExtendedStatus> subComponents, Component comp, VCSRepository repo, String errorDesc) {
20+
LinkedHashMap<Component, ExtendedStatus> subComponents, Component comp, VCSRepository repo) {
2721
this.nextVersion = nextVersion;
2822
this.status = status;
2923
this.subComponents = subComponents;
3024
this.comp = comp;
3125
this.repo = repo;
32-
this.errorDesc = errorDesc;
3326
}
3427

3528
public Version getNextVersion() {
@@ -48,18 +41,11 @@ public Component getComp() {
4841
return comp;
4942
}
5043

51-
public String getErrorDesc() {
52-
return errorDesc;
53-
}
54-
5544
@Override
5645
public String toString() {
5746
if (this == DUMMY) {
5847
return "<DUMMY>";
5948
}
60-
if (status == BuildStatus.ERROR) {
61-
return String.format("%s %s: %s", status, comp.getCoords(), getErrorDesc());
62-
}
6349
String targetBranch = Utils.getReleaseBranchName(repo, nextVersion);
6450
return String.format("%s %s, target version: %s, target branch: %s", status, comp.getCoords(), nextVersion, targetBranch);
6551
}

src/main/java/org/scm4j/releaser/ExtendedStatusBuilder.java

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import org.scm4j.releaser.branch.ReleaseBranchCurrent;
88
import org.scm4j.releaser.branch.ReleaseBranchFactory;
99
import org.scm4j.releaser.branch.ReleaseBranchPatch;
10-
import org.scm4j.releaser.conf.Component;
11-
import org.scm4j.releaser.conf.DelayedTagsFile;
12-
import org.scm4j.releaser.conf.VCSRepository;
13-
import org.scm4j.releaser.conf.VCSRepositoryFactory;
10+
import org.scm4j.releaser.conf.*;
1411
import org.scm4j.releaser.exceptions.ENoReleaseBranchForPatch;
1512
import org.scm4j.releaser.exceptions.ENoReleases;
1613
import org.scm4j.releaser.exceptions.EReleaseMDepsNotLocked;
@@ -74,7 +71,7 @@ public ExtendedStatus getAndCacheStatus(Component comp, CachedStatuses cache, IP
7471
}
7572

7673
DelayedTagsFile dtf = new DelayedTagsFile();
77-
Boolean hasDelayedTag = dtf.getRevisitonByUrl(repo.getUrl()) != null;
74+
Boolean hasDelayedTag = dtf.getDelayedTagByUrl(repo.getUrl()) != null;
7875

7976
ExtendedStatus res = patch ?
8077
getPatchStatus(comp, cache, progress, repo, hasDelayedTag) :
@@ -151,44 +148,22 @@ private ExtendedStatus getPatchStatus(Component comp, CachedStatuses cache, IPro
151148
subComponents.put(mdep, subComponentsLocal.get(mdep));
152149
}
153150

154-
String errorDesc = null;
155-
if (hasMDepsInERRORStatus(rb.getMDeps(), cache)) {
156-
buildStatus = BuildStatus.ERROR;
157-
errorDesc = "has components in ERROR status";
151+
if (hasMDepsNotInDONEStatus(rb.getMDeps(), cache)) {
152+
buildStatus = BuildStatus.BUILD_MDEPS;
153+
} else if (!areMDepsPatchesActual(rb.getMDeps(), cache)) {
154+
buildStatus = BuildStatus.ACTUALIZE_PATCHES;
155+
} else if (reportDuration(() -> noValueableCommitsAfterLastTag(repo, rb), "is release branch modified check", comp, progress)) {
156+
buildStatus = BuildStatus.DONE;
158157
} else {
159-
Version lastTagVersion = reportDuration(() -> getLastTagVersion(repo, rb), "last tag determination", comp, progress);
160-
Version expectedHeadVer = lastTagVersion != null ? hasDelayedTag ? lastTagVersion : lastTagVersion.toNextPatch() : null;
161-
Version actualVersion = rb.getVersion();
162-
if (lastTagVersion != null && !actualVersion.equals(expectedHeadVer)) {
163-
buildStatus = BuildStatus.ERROR;
164-
errorDesc = String.format("last tag %s does not correspond to %s head version. Expected version: %s, actual: %s", lastTagVersion + (hasDelayedTag ? " (delayed)" : ""), rb.getName(),
165-
expectedHeadVer + (hasDelayedTag ? " (considering delayed tag)" : ""), actualVersion);
166-
} else if (hasMDepsNotInDONEStatus(rb.getMDeps(), cache)) {
167-
buildStatus = BuildStatus.BUILD_MDEPS;
168-
} else if (!areMDepsPatchesActual(rb.getMDeps(), cache)) {
169-
buildStatus = BuildStatus.ACTUALIZE_PATCHES;
170-
} else if (reportDuration(() -> noValueableCommitsAfterLastTag(repo, rb), "is release branch modified check", comp, progress)) {
171-
buildStatus = BuildStatus.DONE;
172-
} else {
173-
buildStatus = BuildStatus.BUILD;
174-
}
158+
buildStatus = BuildStatus.BUILD;
175159
}
176-
160+
177161
Version nextVersion = rb.getVersion();
178162
if (hasDelayedTag) {
179163
nextVersion = nextVersion.toNextPatch();
180164
}
181165

182-
return new ExtendedStatus(nextVersion, buildStatus, subComponents, comp, repo, errorDesc);
183-
}
184-
185-
private boolean hasMDepsInERRORStatus(List<Component> mDeps, CachedStatuses cache) {
186-
for (Component mDep : mDeps) {
187-
if (cache.get(repoFactory.getUrl(mDep)).getStatus() == BuildStatus.ERROR) {
188-
return true;
189-
}
190-
}
191-
return false;
166+
return new ExtendedStatus(nextVersion, buildStatus, subComponents, comp, repo);
192167
}
193168

194169
private boolean hasMDepsNotInDONEStatus(List<Component> mDeps, CachedStatuses cache) {
@@ -200,32 +175,12 @@ private boolean hasMDepsNotInDONEStatus(List<Component> mDeps, CachedStatuses ca
200175
return false;
201176
}
202177

203-
private Version getLastTagVersion(VCSRepository repo, ReleaseBranchPatch rb) {
204-
IVCS vcs = repo.getVCS();
205-
DelayedTagsFile dtf = new DelayedTagsFile();
206-
String delayedTagRevision = dtf.getRevisitonByUrl(repo.getUrl());
207-
Version res = walkOnCommitTags(repo, rb, (commit) -> {
208-
if (commit.getRevision().equals(delayedTagRevision)) {
209-
return new Version(vcs.getFileContent(rb.getName(), Utils.VER_FILE_NAME, delayedTagRevision));
210-
}
211-
List<VCSTag> tags = vcs.getTagsOnRevision(commit.getRevision());
212-
for (VCSTag tag : tags) {
213-
Version ver = new Version(tag.getTagName());
214-
if (ver.isSemantic()) {
215-
return ver;
216-
}
217-
}
218-
return null;
219-
});
220-
return res;
221-
}
222-
223178
private boolean noValueableCommitsAfterLastTag(VCSRepository repo, ReleaseBranchPatch rb) {
224179
IVCS vcs = repo.getVCS();
225180
DelayedTagsFile dtf = new DelayedTagsFile();
226-
String delayedTagRevision = dtf.getRevisitonByUrl(repo.getUrl());
227-
Boolean res = walkOnCommitTags(repo, rb, (commit) -> {
228-
if (commit.getRevision().equals(delayedTagRevision)) {
181+
DelayedTag delayedTag = dtf.getDelayedTagByUrl(repo.getUrl());
182+
Boolean res = walkOnCommits(repo, rb, (commit) -> {
183+
if (delayedTag != null && commit.getRevision().equals(delayedTag.getRevision())) {
229184
return true;
230185
}
231186
List<VCSTag> tags = vcs.getTagsOnRevision(commit.getRevision());
@@ -240,7 +195,7 @@ private boolean noValueableCommitsAfterLastTag(VCSRepository repo, ReleaseBranch
240195
return res == null ? true : res;
241196
}
242197

243-
private <T> T walkOnCommitTags(VCSRepository repo, ReleaseBranchPatch rb, Function<VCSCommit, T> func) {
198+
private <T> T walkOnCommits(VCSRepository repo, ReleaseBranchPatch rb, Function<VCSCommit, T> func) {
244199
IVCS vcs = repo.getVCS();
245200
String startingFromRevision = null;
246201

@@ -265,7 +220,7 @@ private boolean areMDepsPatchesActual(List<Component> mDeps, CachedStatuses cach
265220
Version nextMDepVersion = cache.get(url).getNextVersion();
266221
if (!nextMDepVersion.equals(mDep.getVersion().toNextPatch())) {
267222
DelayedTagsFile mdf = new DelayedTagsFile();
268-
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getRevisitonByUrl(url) != null)) {
223+
if (!(nextMDepVersion.getPatch().equals(ZERO_PATCH) && mdf.getDelayedTagByUrl(url) != null)) {
269224
return false;
270225
}
271226
}

src/main/java/org/scm4j/releaser/Utils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public final class Utils {
2828
public static final String ZERO_PATCH = "0";
2929
public static final String VER_FILE_NAME = "version";
3030
public static final String MDEPS_FILE_NAME = "mdeps";
31-
public static final String DELAYED_TAGS_FILE_NAME = "delayed-tags.yml";
3231
public static final File BASE_WORKING_DIR = new File(System.getProperty("user.home"), ".scm4j");
3332

3433
public static <T> T reportDuration(Supplier<T> sup, String message, Component comp, IProgress progress) {

src/main/java/org/scm4j/releaser/cli/CLI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private void executeCmd(CommandLine cmd) throws Exception {
174174

175175
private boolean hasDelayedTags(String rootUrl) {
176176
DelayedTagsFile dtf = new DelayedTagsFile();
177-
return dtf.getRevisitonByUrl(rootUrl) != null;
177+
return dtf.getDelayedTagByUrl(rootUrl) != null;
178178
}
179179

180180
void initWorkingDir() throws Exception {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.scm4j.releaser.conf;
2+
3+
import org.scm4j.commons.Version;
4+
5+
public class DelayedTag {
6+
private final Version version;
7+
private final String revision;
8+
9+
public DelayedTag(Version version, String revision) {
10+
this.version = version;
11+
this.revision = revision;
12+
}
13+
14+
public Version getVersion() {
15+
return version;
16+
}
17+
18+
public String getRevision() {
19+
return revision;
20+
}
21+
22+
@Override
23+
public boolean equals(Object o) {
24+
if (this == o) return true;
25+
if (o == null || getClass() != o.getClass()) return false;
26+
27+
DelayedTag that = (DelayedTag) o;
28+
29+
if (version != null ? !version.equals(that.version) : that.version != null) return false;
30+
return !(revision != null ? !revision.equals(that.revision) : that.revision != null);
31+
32+
}
33+
34+
@Override
35+
public int hashCode() {
36+
int result = version != null ? version.hashCode() : 0;
37+
result = 31 * result + (revision != null ? revision.hashCode() : 0);
38+
return result;
39+
}
40+
}

0 commit comments

Comments
 (0)