Skip to content

Commit ce71bb7

Browse files
committed
Merge branch 'master' into release/2
2 parents 11c42a6 + 2edd119 commit ce71bb7

24 files changed

+476
-354
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
[![Build Status](https://travis-ci.org/scm4j/scm4j-releaser.svg?branch=release/2)](https://travis-ci.org/scm4j/scm4j-releaser)
33
[![Coverage Status](https://coveralls.io/repos/github/scm4j/scm4j-releaser/badge.svg?branch=release/2)](https://coveralls.io/github/scm4j/scm4j-releaser?branch=release/2)
44

5-
# Status
6-
7-
IN DEVELOPMENT
8-
9-
# Overview
10-
11-
Tool to manage projects which are represented by many components, each component has its own repository (multi-repository configuration). It detectes changes in repositories, builds new components versions and actualizes dependency lists.
125

136
# Terms
147

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646
add(configuration ?: name.contains('test') ? 'testCompile' : 'compile', "$group:$name:${version?:''}${classifier?:''}${ext?:''}")
4747
}
4848

49+
testCompile 'com.github.stefanbirkner:system-rules:1.16.1'
4950
testCompile 'junit:junit:4.12'
5051
testCompile 'org.mockito:mockito-all:1.9.5'
5152
testCompile 'nl.jqno.equalsverifier:equalsverifier:2.3'

docs/data-structure-SCM4J_VCS_REPOS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Yaml file consists of number of rules which are applied in order of appearance,
4242
- mycompany:component4:
4343
url: http://mycompany.com/repos/component4
4444
type: svn
45-
releaseBanchPrefix: B
45+
releaseBranchPrefix: B
4646
devBranch: branches/develop
4747

4848
# All repos will have `rel` as a `release` branch prefix by default, if not specified above
4949
- ~:
50-
releaseBanchPrefix: rel/
50+
releaseBranchPrefix: rel/
5151

5252
```

run.groovy

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
@Grab('com.github.scm4j:scm4j-releaser:2.1')
33

44
import org.scm4j.releaser.cli.CLI;
5-
import org.scm4j.releaser.exceptions.EConfig;
65

76
class CLIRunner {
87
static void main(args) {
9-
try {
10-
CLI.main(args);
11-
} catch (EConfig e) {
12-
}
8+
System.exit(new CLI().exec(args));
139
}
1410
}

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public IAction getProductionReleaseAction(Component comp, ActionKind actionKind)
7979
childActions.add(getProductionReleaseAction(mDep, actionKind));
8080
}
8181

82-
return getProductionReleaseActionRoot(comp, childActions, actionKind);
82+
return getProductionReleaseActionRoot(comp, rb, childActions, actionKind);
8383
}
8484

85-
public IAction getProductionReleaseActionRoot(Component comp, List<IAction> childActions, ActionKind actionKind) {
85+
private IAction getProductionReleaseActionRoot(Component comp, ReleaseBranch rb, List<IAction> childActions, ActionKind actionKind) {
8686
DevelopBranch db = new DevelopBranch(comp);
8787
if (!db.hasVersionFile()) {
8888
throw new EComponentConfig("no " + VER_FILE_NAME + " file for " + comp.toString());
@@ -93,62 +93,65 @@ public IAction getProductionReleaseActionRoot(Component comp, List<IAction> chil
9393
return new ActionNone(comp, childActions, "develop branch is IGNORED");
9494
}
9595

96-
ReleaseBranch rb = new ReleaseBranch(comp);
9796
ReleaseBranchStatus rbs = rb.getStatus();
9897

9998
if (rbs == ReleaseBranchStatus.MISSING) {
10099
skipAllBuilds(childActions);
101100
if (actionKind == ActionKind.BUILD) {
102-
return new ActionNone(comp, childActions, "nothing to build. " + rb.getVersion() + " " + rb.getStatus());
101+
return new ActionNone(comp, childActions, "nothing to build. " + getReleaseBranchDetailsStr(rb, rbs));
103102
}
104103

105-
return new SCMActionFork(comp, childActions, ReleaseBranchStatus.MISSING, ReleaseBranchStatus.MDEPS_ACTUAL, options);
104+
return new SCMActionFork(comp, rb, childActions, ReleaseBranchStatus.MISSING, ReleaseBranchStatus.MDEPS_ACTUAL, options);
106105
}
107106

108107
if (rbs == ReleaseBranchStatus.BRANCHED) {
109108
// need to freeze mdeps
110109
skipAllBuilds(childActions);
111110
if (actionKind == ActionKind.BUILD) {
112-
return new ActionNone(comp, childActions, "nothing to build. " + rb.getVersion() + " " + rb.getStatus());
111+
return new ActionNone(comp, childActions, "nothing to build. " + getReleaseBranchDetailsStr(rb, rbs));
113112
}
114-
return new SCMActionFork(comp, childActions, ReleaseBranchStatus.BRANCHED, ReleaseBranchStatus.MDEPS_ACTUAL, options);
113+
return new SCMActionFork(comp, rb, childActions, ReleaseBranchStatus.BRANCHED, ReleaseBranchStatus.MDEPS_ACTUAL, options);
115114
}
116115

117116
if (rbs == ReleaseBranchStatus.MDEPS_FROZEN) {
118117
if (needToActualizeMDeps(rb)) {
119118
// need to actualize
120119
skipAllBuilds(childActions);
121120
if (actionKind == ActionKind.BUILD) {
122-
return new ActionNone(comp, childActions, "nothing to build. " + rb.getVersion() + " " + rb.getStatus());
121+
return new ActionNone(comp, childActions, "nothing to build. " + getReleaseBranchDetailsStr(rb, rbs));
123122
}
124-
return new SCMActionFork(comp, childActions, ReleaseBranchStatus.MDEPS_FROZEN, ReleaseBranchStatus.MDEPS_ACTUAL, options);
123+
return new SCMActionFork(comp, rb, childActions, ReleaseBranchStatus.MDEPS_FROZEN, ReleaseBranchStatus.MDEPS_ACTUAL, options);
125124
} else {
126125
// All necessary version will be build by Child Actions. Need to build
127126
skipAllForks(childActions);
128127
if (actionKind == ActionKind.FORK) {
129-
return new ActionNone(comp, childActions, "nothing to fork. " + rb.getVersion() + " " + rb.getStatus());
128+
return new ActionNone(comp, childActions, "nothing to fork. " + getReleaseBranchDetailsStr(rb, rbs));
130129
}
131-
return new SCMActionBuild(comp, childActions, ReleaseReason.NEW_DEPENDENCIES, rb.getVersion(), options);
130+
return new SCMActionBuild(comp, rb, childActions, ReleaseReason.NEW_DEPENDENCIES, rb.getVersion(), options);
132131
}
133132
}
134133

135134
if (rbs == ReleaseBranchStatus.MDEPS_ACTUAL) {
136135
// need to build
137136
if (actionKind == ActionKind.FORK) {
138-
return new ActionNone(comp, childActions, "nothing to fork. " + rb.getVersion() + " " + rb.getStatus());
137+
return new ActionNone(comp, childActions, "nothing to fork. " + getReleaseBranchDetailsStr(rb, rbs));
139138
}
140-
return new SCMActionBuild(comp, childActions, ReleaseReason.NEW_FEATURES, rb.getVersion(), options);
139+
return new SCMActionBuild(comp, rb, childActions, ReleaseReason.NEW_FEATURES, rb.getVersion(), options);
141140
}
142141

143142
if (hasForkChildActions(childActions)) {
144143
skipAllBuilds(childActions);
145144
if (actionKind == ActionKind.FORK) {
146145
return new ActionNone(comp, childActions, "nothing to build. " + rb.getVersion() + " " + rb.getStatus());
147146
}
148-
return new SCMActionFork(comp, childActions, rbs, rbs, options);
147+
return new SCMActionFork(comp, rb, childActions, rbs, rbs, options);
149148
}
150149

151-
return new ActionNone(comp, childActions, rb.getVersion().toString() + " " + rbs.toString());
150+
return new ActionNone(comp, childActions, getReleaseBranchDetailsStr(rb, rbs));
151+
}
152+
153+
private String getReleaseBranchDetailsStr(ReleaseBranch rb, ReleaseBranchStatus rbs) {
154+
return rb.getName() + " " + rbs + ", target version " + rb.getVersion();
152155
}
153156

154157
private boolean needToActualizeMDeps(ReleaseBranch currentCompRB) {
@@ -158,12 +161,12 @@ private boolean needToActualizeMDeps(ReleaseBranch currentCompRB) {
158161
mDepRB = new ReleaseBranch(mDep);
159162
ReleaseBranchStatus rbs = mDepRB.getStatus();
160163
if (rbs == ReleaseBranchStatus.MDEPS_ACTUAL) {
161-
if (!mDepRB.getCurrentVersion().equals(mDep.getVersion())) {
164+
if (!mDepRB.getHeadVersion().equals(mDep.getVersion())) {
162165
return true;
163166
}
164167

165168
} else if (rbs == ReleaseBranchStatus.ACTUAL) {
166-
if (!mDepRB.getCurrentVersion().toPreviousPatch().equals(mDep.getVersion())) {
169+
if (!mDepRB.getHeadVersion().toPreviousPatch().equals(mDep.getVersion())) {
167170
return true;
168171
}
169172
} else {
@@ -225,7 +228,6 @@ public IAction getTagReleaseAction(String compName) {
225228
}
226229

227230
private IAction getTagReleaseActionRoot(Component comp, List<IAction> childActions) {
228-
ReleaseBranch rb = new ReleaseBranch(comp);
229231
DelayedTagsFile cf = new DelayedTagsFile();
230232
IVCS vcs = comp.getVCS();
231233

@@ -234,24 +236,24 @@ private IAction getTagReleaseActionRoot(Component comp, List<IAction> childActio
234236
if (delayedRevisionToTag == null) {
235237
return new ActionNone(comp, childActions, "no delayed tags");
236238
}
237-
239+
240+
ReleaseBranch rb = new ReleaseBranch(comp);
238241
List<VCSTag> tagsOnRevision = vcs.getTagsOnRevision(delayedRevisionToTag);
239242
if (tagsOnRevision.isEmpty()) {
240-
return new SCMActionTagRelease(comp, childActions, options);
243+
return new SCMActionTagRelease(comp, rb, childActions, options);
241244
}
242245
Version delayedTagVersion = new Version(vcs.getFileContent(rb.getName(), SCMReleaser.VER_FILE_NAME, delayedRevisionToTag));
243246
for (VCSTag tag : tagsOnRevision) {
244247
if (tag.getTagName().equals(delayedTagVersion.toReleaseString())) {
245248
return new ActionNone(comp, childActions, "tag " + tag.getTagName() + " already exists");
246249
}
247250
}
248-
return new SCMActionTagRelease(comp, childActions, options);
251+
return new SCMActionTagRelease(comp, rb, childActions, options);
249252
}
250253

251254
public static TagDesc getTagDesc(String verStr) {
252-
String tagName = verStr;
253-
String tagMessage = tagName + " release";
254-
return new TagDesc(tagName, tagMessage);
255+
String tagMessage = verStr + " release";
256+
return new TagDesc(verStr, tagMessage);
255257
}
256258

257259
public List<Option> getOptions() {

src/main/java/org/scm4j/releaser/branch/ReleaseBranch.java

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ReleaseBranch {
2121
private final String name;
2222
private Map<String, Object> cache = new HashMap<>();
2323

24+
// comp version is ignored
2425
public ReleaseBranch(Component comp, Version version) {
2526
this.version = version.toRelease();
2627
this.comp = comp;
@@ -44,10 +45,17 @@ public ReleaseBranch(final Component comp) {
4445
vcs = comp.getVCS();
4546
DevelopBranch db = new DevelopBranch(comp);
4647

47-
// if not product and not snapshot then will work with just one Release Branch which is related to provided version.
48-
// e.g 4.x -> release/4, 4.x-SNAPSHTOT -> release/*
49-
List<String> releaseBranches = new ArrayList<>(vcs.getBranches(
50-
comp.getVcsRepository().getReleaseBranchPrefix() + (comp.getVersion().isSnapshot() ? "" : comp.getVersion().getReleaseNoPatchString())));
48+
List<String> releaseBranches;
49+
if (comp.getVersion().isEmpty() || comp.getVersion().isSnapshot()) {
50+
releaseBranches = new ArrayList<>(vcs.getBranches(comp.getVcsRepository().getReleaseBranchPrefix()));
51+
} else {
52+
String exactReleaseBranchName = comp.getVcsRepository().getReleaseBranchPrefix() + comp.getVersion().getReleaseNoPatchString();
53+
if (vcs.getBranches(comp.getVcsRepository().getReleaseBranchPrefix()).contains(exactReleaseBranchName)) {
54+
releaseBranches = Arrays.asList(exactReleaseBranchName);
55+
} else {
56+
releaseBranches = new ArrayList<>();
57+
}
58+
}
5159

5260
if (releaseBranches.isEmpty()) {
5361
this.version = db.getVersion().toRelease();
@@ -70,26 +78,43 @@ public int compare(String o1, String o2) {
7078
return 1;
7179
}
7280
});
73-
81+
/**
82+
* TODO: to test:
83+
* We have api 4.1 released and have new commits in api dev. Execute status git:4.1.
84+
* We want to get api 4.1 ACTUAL since we provided exact git version but we get api 5.0 MISSING
85+
*/
7486
Version ver = new Version(vcs.getFileContent(releaseBranches.get(0), SCMReleaser.VER_FILE_NAME, null));
7587
List<VCSCommit> commits = vcs.getCommitsRange(releaseBranches.get(0), null, WalkDirection.DESC, 2);
7688
if (commits.size() == 2) {
7789
List<VCSTag> tags = vcs.getTagsOnRevision(commits.get(1).getRevision());
7890
if (!tags.isEmpty()) {
7991
for (VCSTag tag : tags) {
8092
if (tag.getTagName().equals(ver.toPreviousPatch().toReleaseString())) {
81-
// if db MODIFIED and head-1 commit of last release branch tagged then all is built and we need new release. Use DB version.
82-
// if db BRANCHED and head-1 commit of last release branch tagged then all is built and we need the built release. Use patch--
83-
// otherwise we must return last built RB version.
84-
if (comp.getVersion().isExact()) {
93+
DevelopBranchStatus dbs = db.getStatus();
94+
if(comp.getVersion().isExact()) {
95+
/**
96+
* exact version provided and ACTUAL - result must be last ACTUAL despite the DevelopBranch.
97+
*/
8598
ver = ver.toPreviousPatch();
86-
} else {
87-
DevelopBranchStatus dbs = db.getStatus();
88-
if (dbs == DevelopBranchStatus.BRANCHED) {
89-
ver = ver.toPreviousPatch();
90-
} else if(dbs == DevelopBranchStatus.MODIFIED) {
91-
ver = db.getVersion().toRelease();
92-
}
99+
} else if (dbs == DevelopBranchStatus.BRANCHED ) {
100+
/**
101+
* * - scm-ver 3.0-SNAPSHOT
102+
* | * - #scm-ver 2.1
103+
* | * - #scm-ver 2.0, tag
104+
* *------------------------/
105+
* result must be 2.0 ACTUAL
106+
*/
107+
ver = ver.toPreviousPatch();
108+
} else if (dbs == DevelopBranchStatus.MODIFIED) {
109+
/**
110+
* * - feature commit
111+
* * - scm-ver 3.0-SNAPSHOT
112+
* | * - #scm-ver 2.1
113+
* | * - #scm-ver 2.0, tag
114+
* *------------------------/
115+
* result must be 3.0 MISSING
116+
*/
117+
ver = db.getVersion().toRelease();
93118
}
94119
break;
95120
}
@@ -145,7 +170,7 @@ public ReleaseBranchStatus getStatus() {
145170

146171
if (mDepsFrozen()) {
147172
if (mDepsActual()) {
148-
if (isPreHeadCommitTaggedWithVersion() || isPreHeadCommitTagDelayed()) {
173+
if (isActual()) {
149174
return ReleaseBranchStatus.ACTUAL;
150175
}
151176
return ReleaseBranchStatus.MDEPS_ACTUAL;
@@ -159,6 +184,10 @@ public ReleaseBranchStatus getStatus() {
159184
}
160185
}
161186

187+
private boolean isActual() {
188+
return isPreHeadCommitTaggedWithVersion() || isPreHeadCommitTagDelayed();
189+
}
190+
162191
private boolean mDepsActual() {
163192
List<Component> mDeps = getMDeps();
164193
if (mDeps.isEmpty()) {
@@ -167,10 +196,10 @@ private boolean mDepsActual() {
167196
ReleaseBranch mDepRB;
168197
for (Component mDep : mDeps) {
169198
mDepRB = new ReleaseBranch(mDep, mDep.getVersion());
170-
if (!mDepRB.isPreHeadCommitTaggedWithVersion() && !mDepRB.isPreHeadCommitTagDelayed()) {
199+
if (!mDepRB.isActual()) {
171200
return false;
172201
}
173-
if (!mDep.getVersion().equals(mDepRB.getCurrentVersion().toPreviousPatch())) {
202+
if (!mDep.getVersion().equals(mDepRB.getHeadVersion().toPreviousPatch())) {
174203
return false;
175204
}
176205
}
@@ -188,7 +217,7 @@ private boolean isPreHeadCommitTagDelayed() {
188217
return commits.size() >= 2 && commits.get(1).getRevision().equals(delayedTagRevision);
189218
}
190219

191-
protected boolean isPreHeadCommitTaggedWithVersion() {
220+
private boolean isPreHeadCommitTaggedWithVersion() {
192221
List<VCSCommit> commits = getLast2Commits();
193222
if (commits.size() < 2) {
194223
return false;
@@ -198,7 +227,7 @@ protected boolean isPreHeadCommitTaggedWithVersion() {
198227
return false;
199228
}
200229
for (VCSTag tag : tags) {
201-
if (tag.getTagName().equals(getCurrentVersion().toPreviousPatch().toReleaseString())) {
230+
if (tag.getTagName().equals(getHeadVersion().toPreviousPatch().toReleaseString())) {
202231
return true;
203232
}
204233
}
@@ -261,7 +290,7 @@ public String getName() {
261290
return name;
262291
}
263292

264-
public Version getCurrentVersion() {
293+
public Version getHeadVersion() {
265294
return new Version(comp.getVCS().getFileContent(getName(), SCMReleaser.VER_FILE_NAME, null).trim());
266295
}
267296

0 commit comments

Comments
 (0)