Skip to content

Commit c69903f

Browse files
committed
Status comand with --delayed-tag option throws exception #53
1 parent d2fe773 commit c69903f

File tree

4 files changed

+67
-42
lines changed

4 files changed

+67
-42
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.scm4j.releaser.actions.IAction;
55
import org.scm4j.releaser.conf.*;
66
import org.scm4j.releaser.exceptions.EBuildOnNotForkedRelease;
7+
import org.scm4j.releaser.exceptions.EDelayingDelayed;
78
import org.scm4j.releaser.exceptions.ENoDelayedTags;
89
import org.scm4j.releaser.scmactions.SCMActionRelease;
910
import org.scm4j.releaser.scmactions.SCMActionTag;
@@ -38,18 +39,28 @@ public IAction getActionTreeForkOnly(ExtendedStatus node, CachedStatuses cache)
3839

3940
private IAction getActionTree(ExtendedStatus node, CachedStatuses cache, ActionSet actionSet, boolean delayedTag) {
4041
List<IAction> childActions = new ArrayList<>();
42+
VCSRepository repo = repoFactory.getVCSRepository(node.getComp());
43+
44+
if (delayedTag && alreadyDelayed(repo.getUrl())) {
45+
throw new EDelayingDelayed(repo.getUrl());
46+
}
47+
4148
for (Map.Entry<Component, ExtendedStatus> nodeEntry : node.getSubComponents().entrySet()) {
4249
childActions.add(getActionTree(nodeEntry.getValue(), cache, actionSet, false));
4350
}
44-
51+
4552
if (node.getStatus() == BuildStatus.FORK && actionSet == ActionSet.FULL) {
4653
throw new EBuildOnNotForkedRelease(node.getComp());
4754
}
4855

49-
VCSRepository repo = repoFactory.getVCSRepository(node.getComp());
5056
return new SCMActionRelease(node.getComp(), childActions, cache, repoFactory, actionSet, delayedTag, repo);
5157
}
5258

59+
private boolean alreadyDelayed(String url) {
60+
DelayedTagsFile dtf = new DelayedTagsFile();
61+
return dtf.getDelayedTagByUrl(url) != null;
62+
}
63+
5364
public IAction getTagAction(Component comp) {
5465
VCSRepository repo = repoFactory.getVCSRepository(comp);
5566
DelayedTagsFile dtf = new DelayedTagsFile();

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import org.scm4j.releaser.*;
1313
import org.scm4j.releaser.actions.IAction;
1414
import org.scm4j.releaser.actions.PrintStatus;
15-
import org.scm4j.releaser.conf.*;
16-
import org.scm4j.releaser.exceptions.EDelayingDelayed;
15+
import org.scm4j.releaser.conf.DefaultConfigUrls;
16+
import org.scm4j.releaser.conf.IConfigUrls;
17+
import org.scm4j.releaser.conf.VCSRepositoryFactory;
1718
import org.scm4j.releaser.exceptions.cmdline.*;
1819

1920
import java.io.File;
@@ -124,8 +125,6 @@ public int exec(String[] args) {
124125

125126
repoFactory.load(configUrls);
126127

127-
checkDelayedTags(cmd);
128-
129128
executeCmd(cmd);
130129

131130
out.println(ansi().a(Ansi.Attribute.INTENSITY_BOLD).fgGreen()
@@ -147,15 +146,6 @@ public int exec(String[] args) {
147146
}
148147
}
149148

150-
private void checkDelayedTags(CommandLine cmd) {
151-
if (cmd.isDelayedTag()) {
152-
String rootUrl = repoFactory.getUrl(new Component(cmd.getProductCoords()));
153-
if (hasDelayedTags(rootUrl)) {
154-
throw new EDelayingDelayed(rootUrl);
155-
}
156-
}
157-
}
158-
159149
private void executeCmd(CommandLine cmd) throws Exception {
160150
if (cmd.getCommand() == CLICommand.TAG) {
161151
action = getTagAction(cmd);
@@ -172,11 +162,6 @@ private void executeCmd(CommandLine cmd) throws Exception {
172162
}
173163
}
174164

175-
private boolean hasDelayedTags(String rootUrl) {
176-
DelayedTagsFile dtf = new DelayedTagsFile();
177-
return dtf.getDelayedTagByUrl(rootUrl) != null;
178-
}
179-
180165
void initWorkingDir() throws Exception {
181166
if (configUrls.getCCUrls() != null || configUrls.getCredsUrl() != null) {
182167
return;

src/test/java/org/scm4j/releaser/WorkflowDelayedTagTest.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.scm4j.releaser.branch.ReleaseBranchCurrent;
1111
import org.scm4j.releaser.branch.ReleaseBranchFactory;
1212
import org.scm4j.releaser.branch.ReleaseBranchPatch;
13+
import org.scm4j.releaser.cli.CLICommand;
14+
import org.scm4j.releaser.cli.Option;
1315
import org.scm4j.releaser.conf.*;
1416
import org.scm4j.releaser.exceptions.EDelayingDelayed;
1517
import org.scm4j.releaser.exceptions.ENoDelayedTags;
@@ -37,29 +39,43 @@ public void setUpTearDown() {
3739
public void testDelayedTagOnPatch() throws Exception {
3840
forkAndBuild(compUnTill);
3941

40-
// add feature to unTillDb release/2.59
41-
Component compUnTillDbVersioned = compUnTillDb.clone(env.getUnTillDbVer());
42-
ReleaseBranchPatch rb = ReleaseBranchFactory.getReleaseBranchPatch(compUnTillDbVersioned.getVersion(), repoUnTillDb);
43-
env.generateFeatureCommit(env.getUnTillDbVCS(), rb.getName(), "patch feature merged");
42+
// add feature to unTill
43+
Component compUnTillVersioned = compUnTill.clone(env.getUnTillVer().toReleaseZeroPatch());
44+
ReleaseBranchPatch rb = ReleaseBranchFactory.getReleaseBranchPatch(compUnTillVersioned.getVersion(), repoUnTillDb);
45+
env.generateFeatureCommit(env.getUnTillVCS(), rb.getName(), "patch feature merged");
4446

4547
// build all patches, delayed tag
46-
Component compUnTillVersioned = compUnTill.clone(env.getUnTillVer().toReleaseZeroPatch());
4748
IAction action = execAndGetActionBuildDelayedTag(compUnTillVersioned);
48-
assertActionDoesBuildAllDelayedTag(action);
49+
assertActionDoesBuildDelayedTag(action, compUnTillVersioned);
4950

50-
// check no new tags
51-
Assert.assertEquals(2, env.getUblVCS().getTags().size());
52-
Assert.assertEquals(2, env.getUnTillDbVCS().getTags().size());
51+
// check root component patch tag is delayed
52+
Assert.assertEquals(1, env.getUblVCS().getTags().size());
53+
Assert.assertEquals(1, env.getUnTillDbVCS().getTags().size());
5354
Assert.assertEquals(1, env.getUnTillVCS().getTags().size());
54-
55-
// check Delayed Tags file
56-
assertNull(dtf.getDelayedTagByUrl(repoUnTillDb.getUrl()));
57-
assertNotNull(dtf.getDelayedTagByUrl(repoUnTill.getUrl()));
58-
assertNull(dtf.getDelayedTagByUrl(repoUBL.getUrl()));
5955

60-
// check Delayed Tags are used
56+
// check component with delayed tag is considered as tagged (DONE) on build
6157
action = execAndGetActionBuild(compUnTillVersioned);
6258
assertActionDoesNothing(action);
59+
60+
// check no exceptions on status command with --delayed-tag option
61+
execAndGetNode(null, CLICommand.STATUS.getCmdLineStr(),
62+
compUnTillVersioned.getCoords().toString(), Option.DELAYED_TAG.getCmdLineStr());
63+
64+
// check Delayed Tags file
65+
DelayedTag delayedTag = dtf.getDelayedTagByUrl(repoUnTill.getUrl());
66+
assertEquals(env.getUnTillVer().toReleaseZeroPatch().toNextPatch(), delayedTag.getVersion());
67+
ReleaseBranchPatch patchRB = ReleaseBranchFactory.getReleaseBranchPatch(compUnTillVersioned.getVersion(), repoUnTill);
68+
VCSCommit commitToTag = env.getUnTillVCS().getHeadCommit(patchRB.getName());
69+
assertEquals(delayedTag.getRevision(), commitToTag.getRevision());
70+
71+
// create tag which was delayed
72+
action = execAndGetActionTag(compUnTill, null);
73+
assertActionDoesTag(action, compUnTill);
74+
75+
// check tags
76+
assertTrue(isPreHeadCommitTaggedWithVersion(compUBL));
77+
assertTrue(isPreHeadCommitTaggedWithVersion(compUnTillDb));
78+
assertTrue(isPreHeadCommitTaggedWithVersion(compUnTill));
6379
}
6480

6581
@Test
@@ -77,11 +93,22 @@ public void testDelayedTagOnMinor() throws Exception {
7793
action = execAndGetActionBuild(compUnTill);
7894
assertActionDoesNothing(action);
7995

96+
// expect no exceptions on status command with --delayed-tag option
97+
execAndGetNode(null, CLICommand.STATUS.getCmdLineStr(),
98+
compUnTill.getCoords().toString(), Option.DELAYED_TAG.getCmdLineStr());
99+
80100
// check Delayed Tags file
81101
assertNull(dtf.getDelayedTagByUrl(repoUnTillDb.getUrl()));
82102
assertNotNull(dtf.getDelayedTagByUrl(repoUnTill.getUrl()));
83103
assertNull(dtf.getDelayedTagByUrl(repoUBL.getUrl()));
84104

105+
// check delayed tag
106+
DelayedTag delayedTag = dtf.getDelayedTagByUrl(repoUnTill.getUrl());
107+
assertEquals(env.getUnTillVer().toReleaseZeroPatch(), delayedTag.getVersion());
108+
ReleaseBranchCurrent crb = ReleaseBranchFactory.getCRB(repoUnTill);
109+
VCSCommit commitToTag = env.getUnTillVCS().getHeadCommit(crb.getName());
110+
assertEquals(delayedTag.getRevision(), commitToTag.getRevision());
111+
85112
// create tag which was delayed
86113
action = execAndGetActionTag(compUnTill, null);
87114
assertActionDoesTag(action, compUnTill);
@@ -221,15 +248,19 @@ public void testMDepTagDelayed() {
221248

222249
@Test
223250
public void testDelayingDelayed() {
224-
fork(compUnTillDb);
225-
IAction action = execAndGetActionBuildDelayedTag(compUnTillDb);
226-
assertActionDoesBuildDelayedTag(action, compUnTillDb);
251+
forkAndBuild(compUnTillDb);
227252

228253
ReleaseBranchCurrent crb = ReleaseBranchFactory.getCRB(repoUnTillDb);
229254
env.generateFeatureCommit(env.getUnTillDbVCS(), crb.getName(), "feature merged");
230255

256+
Component compUnTillDbPatch = compUnTillDb.clone(env.getUnTillDbVer().toReleaseZeroPatch());
257+
258+
IAction action = execAndGetActionBuildDelayedTag(compUnTillDbPatch);
259+
assertActionDoesBuildDelayedTag(action, compUnTillDbPatch);
260+
261+
env.generateFeatureCommit(env.getUnTillDbVCS(), crb.getName(), "feature merged");
262+
231263
// try to build next untillDb patch with delayed tag
232-
Component compUnTillDbPatch = new Component(UNTILLDB + ":" + env.getUnTillDbVer().toRelease());
233264
try {
234265
execAndGetActionBuildDelayedTag(compUnTillDbPatch);
235266
fail();
@@ -297,5 +328,3 @@ private boolean isPreHeadCommitTaggedWithVersion(Component comp) {
297328
return false;
298329
}
299330
}
300-
301-

src/test/java/org/scm4j/releaser/WorkflowTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private IAction execAndGetAction(Runnable preExec, String... args) {
377377
return action;
378378
}
379379

380-
private ExtendedStatus execAndGetNode(Runnable preExec, String... args) {
380+
protected ExtendedStatus execAndGetNode(Runnable preExec, String... args) {
381381
CLI cli = execAndGetCLI(preExec, args);
382382
return cli.getNode();
383383
}

0 commit comments

Comments
 (0)