Skip to content

Commit f955dcd

Browse files
committed
Delayed tagging #2 (only root component tag is delayed)
1 parent b80c48a commit f955dcd

File tree

5 files changed

+46
-44
lines changed

5 files changed

+46
-44
lines changed

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package org.scm4j.releaser;
22

3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
38
import org.scm4j.commons.Version;
49
import org.scm4j.releaser.actions.ActionSet;
510
import org.scm4j.releaser.actions.IAction;
611
import org.scm4j.releaser.branch.DevelopBranch;
7-
import org.scm4j.releaser.branch.ReleaseBranchFactory;
812
import org.scm4j.releaser.conf.Component;
913
import org.scm4j.releaser.scmactions.SCMActionRelease;
1014
import org.scm4j.releaser.scmactions.SCMActionTag;
1115

12-
import java.io.File;
13-
import java.util.ArrayList;
14-
import java.util.List;
15-
import java.util.Map;
16-
1716
public class ActionTreeBuilder {
1817

1918
public static final String MDEPS_FILE_NAME = "mdeps";
@@ -25,8 +24,8 @@ public IAction getActionTree(String coords) {
2524
return getActionTreeFull(coords, false);
2625
}
2726

28-
public IAction getTagActionTree(String coords) {
29-
return getTagActionTree(new Component(coords));
27+
public IAction getTagAction(String coords) {
28+
return getTagAction(new Component(coords));
3029
}
3130

3231
public IAction getActionTreeForkOnly(String coords) {
@@ -62,23 +61,15 @@ private IAction getActionTree(Component comp, ActionSet actionSet, boolean delay
6261
public IAction getActionTree(ExtendedStatus node, CachedStatuses cache, ActionSet actionSet, boolean delayedTag) {
6362
List<IAction> childActions = new ArrayList<>();
6463
for (Map.Entry<Component, ExtendedStatus> nodeEntry : node.getSubComponents().entrySet()) {
65-
childActions.add(getActionTree(nodeEntry.getValue(), cache, actionSet, delayedTag));
64+
childActions.add(getActionTree(nodeEntry.getValue(), cache, actionSet, false));
6665
}
6766

6867
return new SCMActionRelease(node.getComp(), childActions, cache, actionSet, delayedTag);
6968
}
7069

71-
public IAction getTagActionTree(Component comp) {
70+
public IAction getTagAction(Component comp) {
7271
List<IAction> childActions = new ArrayList<>();
73-
List<Component> mDeps = ReleaseBranchFactory.getMDepsDevelop(comp);
74-
75-
for (Component mDep : mDeps) {
76-
childActions.add(getTagActionTree(mDep));
77-
}
78-
7972
Version lastReleaseVersion = new DevelopBranch(comp).getVersion().toPreviousMinor();
80-
8173
return new SCMActionTag(comp, childActions, Utils.getReleaseBranchName(comp, lastReleaseVersion));
8274
}
83-
8475
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IAction getActionTree(CommandLine cmd) {
5252
case FORK:
5353
return actionBuilder.getActionTreeForkOnly(cmd.getProductCoords());
5454
case TAG:
55-
return actionBuilder.getTagActionTree(cmd.getProductCoords());
55+
return actionBuilder.getTagAction(cmd.getProductCoords());
5656
default:
5757
throw new IllegalArgumentException("Unsupported command: " + cmd.getCommand().toString());
5858
}

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

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

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
35
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.assertNull;
47
import static org.junit.Assert.assertTrue;
58

69
import java.util.List;
@@ -43,19 +46,19 @@ public void testDelayedTagOnPatch() throws Exception {
4346

4447
// build all patches, delayed tag
4548
Component compUnTillVersioned = compUnTill.clone(env.getUnTillVer().toReleaseZeroPatch());
46-
action = getActionTreeDelayedTag(compUnTillVersioned); //actionBuilder.getActionTreeDelayedTag(compUnTillVersioned);
49+
action = getActionDelayedTag(compUnTillVersioned); //actionBuilder.getActionTreeDelayedTag(compUnTillVersioned);
4750
assertIsGoingToBuildAll(action);
4851
execAction(action);
4952

5053
// check no new tags
51-
assertTrue(env.getUblVCS().getTags().size() == 1);
52-
assertTrue(env.getUnTillDbVCS().getTags().size() == 1);
53-
assertTrue(env.getUnTillVCS().getTags().size() == 1);
54+
assertEquals(2, env.getUblVCS().getTags().size());
55+
assertEquals(2, env.getUnTillDbVCS().getTags().size());
56+
assertEquals(1, env.getUnTillVCS().getTags().size());
5457

5558
// check Delayed Tags file
56-
assertNotNull(dtf.getRevisitonByUrl(compUnTillDb.getVcsRepository().getUrl()));
59+
assertNull(dtf.getRevisitonByUrl(compUnTillDb.getVcsRepository().getUrl()));
5760
assertNotNull(dtf.getRevisitonByUrl(compUnTill.getVcsRepository().getUrl()));
58-
assertNotNull(dtf.getRevisitonByUrl(compUBL.getVcsRepository().getUrl()));
61+
assertNull(dtf.getRevisitonByUrl(compUBL.getVcsRepository().getUrl()));
5962

6063
// check Delayed Tags are used
6164
action = getActionTreeBuild(compUnTillVersioned);
@@ -64,22 +67,27 @@ public void testDelayedTagOnPatch() throws Exception {
6467

6568
@Test
6669
public void testDelayedTag() throws Exception {
67-
IAction action = getActionTreeDelayedTag(compUnTill);
70+
IAction action = getActionDelayedTag(compUnTill);
6871
execAction(action);
6972

70-
// check no tags
73+
// check root component tag is delayed
7174
assertTrue(env.getUnTillVCS().getTags().isEmpty());
72-
assertTrue(env.getUnTillDbVCS().getTags().isEmpty());
73-
assertTrue(env.getUblVCS().getTags().isEmpty());
75+
assertTrue(env.getUnTillDbVCS().getTags().size() == 1);
76+
assertTrue(env.getUblVCS().getTags().size() == 1);
77+
78+
// check component with delayed tag is considered as tagged (DONE) on build
79+
action = getActionTreeBuild(compUnTill);
80+
assertIsGoingToDoNothing(action);
7481

7582
// check Delayed Tags file
76-
assertNotNull(dtf.getRevisitonByUrl(compUnTillDb.getVcsRepository().getUrl()));
83+
assertNull(dtf.getRevisitonByUrl(compUnTillDb.getVcsRepository().getUrl()));
7784
assertNotNull(dtf.getRevisitonByUrl(compUnTill.getVcsRepository().getUrl()));
78-
assertNotNull(dtf.getRevisitonByUrl(compUBL.getVcsRepository().getUrl()));
85+
assertNull(dtf.getRevisitonByUrl(compUBL.getVcsRepository().getUrl()));
7986

80-
// tag all
87+
// create tag which was delayed
8188
action = getActionTreeTag(compUnTill);
82-
assertIsGoingToTagAll(action);
89+
assertIsGoingToTag(action, compUnTill);
90+
8391
execAction(action);
8492

8593
// check tags
@@ -93,30 +101,31 @@ public void testDelayedTag() throws Exception {
93101

94102
@Test
95103
public void testTagFileDeleted() throws Exception {
96-
IAction action = getActionTreeDelayedTag(compUnTill);
104+
// build all, root tag delayed
105+
IAction action = getActionDelayedTag(compUnTill);
97106
execAction(action);
98107

99108
// simulate delayed tags file is deleted right after action create
100109
action = getActionTreeTag(compUnTill);
101-
assertIsGoingToTagAll(action);
110+
assertIsGoingToTag(action, compUnTill);
102111
dtf.delete();
103112
execAction(action);
104113

105114
// check no tags
106115
assertTrue(env.getUnTillVCS().getTags().isEmpty());
107-
assertTrue(env.getUnTillDbVCS().getTags().isEmpty());
108-
assertTrue(env.getUblVCS().getTags().isEmpty());
116+
assertFalse(env.getUnTillDbVCS().getTags().isEmpty());
117+
assertFalse(env.getUblVCS().getTags().isEmpty());
109118
}
110119

111120
@Test
112121
public void testTagExistsOnExecute() throws Exception {
113122
// build all
114-
IAction action = getActionTreeDelayedTag(compUnTill);
123+
IAction action = getActionDelayedTag(compUnTill);
115124
execAction(action);
116125

117126
// all is going to tag
118127
action = getActionTreeTag(compUnTill);
119-
assertIsGoingToTagAll(action);
128+
assertIsGoingToTag(action, compUnTill);
120129

121130
// simulate tag exists already
122131
ReleaseBranch rb = ReleaseBranchFactory.getCRB(compUnTill);
@@ -158,7 +167,7 @@ public void testDoNothingIfNoDelayedTags() {
158167
@Test
159168
public void testTagExistsOnGetActionTree() throws Exception {
160169
// build all
161-
IAction action = getActionTreeDelayedTag(compUnTillDb);
170+
IAction action = getActionDelayedTag(compUnTillDb);
162171
assertIsGoingToForkAndBuild(action, compUnTillDb);
163172
execAction(action);
164173

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ protected void assertIsGoingToDoNothing(IAction action, Component... comps) {
383383
}
384384

385385
protected void assertIsGoingToTag(IAction action, Component comp) {
386-
assertThat(action, instanceOf(SCMActionTag.class), comp);
386+
assertThat(action, allOf(
387+
instanceOf(SCMActionTag.class),
388+
hasProperty("childActions", empty())), comp);
387389
}
388390

389391
protected void assertIsGoingToBuildAll(IAction action) {
@@ -416,7 +418,7 @@ protected IAction getActionTreeTag(Component comp) {
416418
return new CLI().getActionTree(new CommandLine(new String[] {CLICommand.TAG.getCmdLineStr(), comp.getCoords().toString()}));
417419
}
418420

419-
protected IAction getActionTreeDelayedTag(Component comp) {
421+
protected IAction getActionDelayedTag(Component comp) {
420422
return new CLI().getActionTree(new CommandLine(new String[] {CLICommand.BUILD.getCmdLineStr(), comp.getCoords().toString(), Option.DELAYED_TAG.getCmdLineStr()}));
421423
}
422424
}

src/test/java/org/scm4j/releaser/cli/CLITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public void testCommandBUILD() throws Exception {
104104

105105
@Test
106106
public void testCommandTAG() throws Exception {
107-
doReturn(mockedAction).when(mockedReleaser).getTagActionTree(UNTILL);
107+
doReturn(mockedAction).when(mockedReleaser).getTagAction(UNTILL);
108108
String[] args = new String[] { CLICommand.TAG.getCmdLineStr(), UNTILL };
109109

110110
assertEquals(CLI.EXIT_CODE_OK, mockedCLI.exec(args));
111111

112-
verify(mockedReleaser).getTagActionTree(UNTILL);
112+
verify(mockedReleaser).getTagAction(UNTILL);
113113
verify(mockedAction).execute(any(IProgress.class));
114114

115115
exit.expectSystemExitWithStatus(CLI.EXIT_CODE_OK);

0 commit comments

Comments
 (0)