Skip to content

Commit 562edc3

Browse files
committed
improve status calculation reporting #25
1 parent b7fdeb6 commit 562edc3

File tree

6 files changed

+45
-64
lines changed

6 files changed

+45
-64
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Map;
77
import java.util.concurrent.ConcurrentHashMap;
88
import java.util.concurrent.ForkJoinPool;
9+
import java.util.function.Supplier;
910

1011
import org.scm4j.commons.progress.IProgress;
1112
import org.scm4j.commons.progress.ProgressConsole;
@@ -64,7 +65,6 @@ public IAction getActionTree(Component comp, final ActionKind actionKind, final
6465

6566
myPool.shutdown();
6667

67-
6868
for (Component mdep : cr.getMDeps()) {
6969
if (res.get(mdep) instanceof Exception) {
7070
throw (Exception) res.get(mdep);
@@ -75,7 +75,7 @@ public IAction getActionTree(Component comp, final ActionKind actionKind, final
7575

7676
return new SCMActionRelease(cr.getReleaseBranch(), childActions, actionKind, cr.getBuildStatus());
7777
}
78-
78+
7979
private CalculatedResult getCalculatedResult(Component comp, Map<String, CalculatedResult> calculatedStatuses) throws Exception {
8080
CalculatedResult cr = calculatedStatuses.get(comp.getVcsRepository().getUrl());
8181
if (cr != null) {
@@ -96,41 +96,41 @@ private CalculatedResult getCalculatedResult(Component comp, Map<String, Calcula
9696

9797
IProgress progress = new ProgressConsole();
9898
// If we are build, build_mdeps or actualize_patches then we need to use mdeps from release branches to show what versions we are going to build or actualize
99-
progress.startTrace(String.format("analyzing %s, url %s:\r\n", comp, comp.getVcsRepository().getUrl()));
100-
progress.startTrace("determining release branch version for " + comp.getCoordsNoComment() + "... ");
101-
rb = new ReleaseBranch(comp);
102-
progress.endTrace("done");
99+
rb = reportDuration(() -> new ReleaseBranch(comp), "release branch version calculation", comp, progress);
103100
bs = getBuildStatus(rb);
104-
if (bs == BuildStatus.FORK) {
101+
if (bs != BuildStatus.FORK && rb.exists()) {
105102
// untill has untilldb, ubl has untilldb. untill is BUILD_MDEPS, UBL has release branch but need to FORK.
106103
// result: regressinon for untill FORK, regiression for UBL is DONE prev version (mdep fro existing UBL RB is used)
107104
// TODO: add test: untill build_mdeps, untill needs to be forked. UBL has release rbanch but has to be forked also. untilldbs must have the same status
108-
progress.startTrace("reading mdeps from develop branch... ");
109-
mDeps = new DevelopBranch(comp).getMDeps();
110-
progress.endTrace("done");
105+
mDeps = reportDuration(() -> rb.getMDeps(), "read mdeps from release branch", comp, progress);
111106
} else {
112-
if (rb.exists()) {
113-
progress.startTrace("reading mdeps from release branch " + rb.getName() + "... ");
114-
mDeps = rb.getMDeps();
115-
progress.endTrace("done");
116-
} else {
117-
progress.startTrace("reading mdeps from develop branch... ");
118-
mDeps = new DevelopBranch(comp).getMDeps();
119-
progress.endTrace("done");
120-
}
107+
mDeps = reportDuration(() -> new DevelopBranch(comp).getMDeps(), "read mdeps from develop branch", comp, progress);
121108
}
109+
122110
cr = new CalculatedResult(rb, bs, mDeps);
123111
calculatedStatuses.put(comp.getVcsRepository().getUrl(), cr);
124112
progress.close();
125113
return cr;
126114
}
127115

116+
public static <T> T reportDuration(Supplier<T> sup, String message, Component comp, IProgress progress) {
117+
long start = System.currentTimeMillis();
118+
T res = sup.get();
119+
progress.reportStatus(message + ": " + (comp == null ? "" : comp.getCoordsNoComment() + " ") + "in " + (System.currentTimeMillis() - start) + "ms");
120+
return res;
121+
}
122+
123+
public static <T> void reportDuration(Runnable run, String message, Component comp, IProgress progress) {
124+
reportDuration(() -> {
125+
run.run();
126+
return null;
127+
}, message, comp, progress);
128+
}
129+
128130
protected BuildStatus getBuildStatus(ReleaseBranch rb) throws Exception {
129131
Build mb = new Build(rb);
130132
IProgress progress = new ProgressConsole();
131-
progress.startTrace("calculating status for " + rb.getComponent().getName() + "... ");
132-
BuildStatus mbs = mb.getStatus();
133-
progress.endTrace("done");
133+
BuildStatus mbs = reportDuration(() -> mb.getStatus(), "status calculation", rb.getComponent(), progress);
134134
progress.close();
135135
return mbs;
136136
}

src/main/java/org/scm4j/releaser/scmactions/SCMActionTag.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ protected void executeAction(IProgress progress) {
3636
TagDesc tagDesc = SCMReleaser.getTagDesc(delayedTagVersion.toString());
3737

3838
try {
39-
progress.startTrace(String.format("tagging revision %s of %s: %s... ", revisionToTag, rb.getName(), delayedTagVersion.toReleaseString()));
40-
vcs.createTag(rb.getName(), tagDesc.getName(), tagDesc.getMessage(), revisionToTag);
41-
progress.endTrace("done");
39+
SCMReleaser.reportDuration(() -> vcs.createTag(rb.getName(), tagDesc.getName(), tagDesc.getMessage(), revisionToTag),
40+
String.format("tag revision %s of %s: %s", revisionToTag, rb.getName(), delayedTagVersion.toReleaseString()), null, progress);
4241
} catch (EVCSTagExists e) {
4342
progress.reportStatus(String.format("revision %s is already tagged with %s tag", revisionToTag, tagDesc.getName()));
4443
}

src/main/java/org/scm4j/releaser/scmactions/procs/SCMProcActualizePatches.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ public SCMProcActualizePatches(ReleaseBranch rb) {
2121

2222
@Override
2323
public void execute(IProgress progress) {
24-
progress.startTrace("reading mdeps to actualize patches... ");
25-
MDepsFile currentMDepsFile = rb.getMDepsFile();
26-
progress.endTrace("done");
24+
MDepsFile currentMDepsFile = SCMReleaser.reportDuration(() -> rb.getMDepsFile(), "mdeps read to actualize patches", null, progress);
2725
StringBuilder sb = new StringBuilder();
2826
boolean hasNew = false;
2927
ReleaseBranch rbMDep;
3028
Version newVersion;
3129
for (Component currentMDep : currentMDepsFile.getMDeps()) {
32-
progress.startTrace("determining Release Branch version for mdep " + currentMDep + "... ");
33-
rbMDep = new ReleaseBranch(currentMDep);
34-
progress.endTrace("done");
30+
rbMDep = SCMReleaser.reportDuration(() -> new ReleaseBranch(currentMDep), "release branch version calculation", currentMDep, progress);
3531
newVersion = rbMDep.getVersion().toPreviousPatch(); // TODO: which patch of mdep to actualize on if there are no mdep release branches at all?
3632
if (!newVersion.equals(currentMDep.getVersion())) {
3733
hasNew = true;
@@ -45,9 +41,8 @@ public void execute(IProgress progress) {
4541
if (hasNew) {
4642
sb.setLength(sb.length() - 2);
4743
progress.reportStatus("patches to actualize:\r\n" + sb.toString());
48-
progress.startTrace("actualizing patches... ");
49-
vcs.setFileContent(rb.getName(), SCMReleaser.MDEPS_FILE_NAME, currentMDepsFile.toFileContent(), LogTag.SCM_MDEPS);
50-
progress.endTrace("done");
44+
SCMReleaser.reportDuration(() -> vcs.setFileContent(rb.getName(), SCMReleaser.MDEPS_FILE_NAME, currentMDepsFile.toFileContent(), LogTag.SCM_MDEPS),
45+
"writting mdeps", null, progress);
5146
} else {
5247
progress.reportStatus("mdeps patches are actual already");
5348
}

src/main/java/org/scm4j/releaser/scmactions/procs/SCMProcBuild.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ private void build(IProgress progress, VCSCommit headCommit) {
6161
FileUtils.deleteDirectory(buildDir);
6262
}
6363
Files.createDirectories(buildDir.toPath());
64-
progress.startTrace(String.format("checking out %s on revision %s into %s... ", comp.getName(), headCommit.getRevision(), buildDir.getPath()));
65-
vcs.checkout(rb.getName(), buildDir.getPath(), headCommit.getRevision());
66-
progress.endTrace("done");
64+
SCMReleaser.reportDuration(() -> vcs.checkout(rb.getName(), buildDir.getPath(), headCommit.getRevision()),
65+
String.format("check out %s on revision %s into %s", comp.getName(), headCommit.getRevision(), buildDir.getPath()), null, progress);
6766
comp.getVcsRepository().getBuilder().build(comp, buildDir, progress);
6867
}
6968

@@ -76,18 +75,16 @@ private void tagBuild(IProgress progress, VCSCommit headCommit) {
7675
} else {
7776
String releaseBranchName = rb.getName();
7877
TagDesc tagDesc = SCMReleaser.getTagDesc(rb.getVersion().toString());
79-
progress.startTrace(String.format("tagging head of %s: %s... ", releaseBranchName, tagDesc.getName()));
80-
vcs.createTag(releaseBranchName, tagDesc.getName(), tagDesc.getMessage(), headCommit.getRevision());
81-
progress.endTrace("done");
78+
SCMReleaser.reportDuration(() -> vcs.createTag(releaseBranchName, tagDesc.getName(), tagDesc.getMessage(), headCommit.getRevision()),
79+
String.format("tag head of %s: %s", releaseBranchName, tagDesc.getName()), null, progress);
8280
}
8381
}
8482

8583
private void raisePatchVersion(IProgress progress) {
8684
Version nextPatchVersion = rb.getVersion().toNextPatch();
87-
progress.startTrace("bumping patch version in release branch: " + nextPatchVersion +"... ");
88-
vcs.setFileContent(rb.getName(), SCMReleaser.VER_FILE_NAME, nextPatchVersion.toString(),
89-
LogTag.SCM_VER + " " + nextPatchVersion);
90-
progress.endTrace("done");
85+
SCMReleaser.reportDuration(() -> vcs.setFileContent(rb.getName(), SCMReleaser.VER_FILE_NAME, nextPatchVersion.toString(),
86+
LogTag.SCM_VER + " " + nextPatchVersion),
87+
"bump patch version in release branch: " + nextPatchVersion, null, progress);
9188
}
9289

9390
}

src/main/java/org/scm4j/releaser/scmactions/procs/SCMProcForkBranch.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,20 @@ public void execute(IProgress progress) {
3131

3232
private void createBranch(IProgress progress) {
3333
String newBranchName = rb.getName();
34-
progress.startTrace("Creating branch " + newBranchName + "... ");
35-
vcs.createBranch(db.getName(), newBranchName, "release branch created");
36-
progress.endTrace("done");
34+
SCMReleaser.reportDuration(() -> vcs.createBranch(db.getName(), newBranchName, "release branch created"),
35+
"create branch " + newBranchName, null, progress);
3736
}
3837

3938
private void truncateSnapshotReleaseVersion(IProgress progress) {
4039
String noSnapshotVersion = rb.getVersion().toString();
4140
String newBranchName = rb.getName();
42-
progress.startTrace("truncating snapshot: " + noSnapshotVersion + " in branch " + newBranchName + "... ");
43-
vcs.setFileContent(newBranchName, SCMReleaser.VER_FILE_NAME, noSnapshotVersion, LogTag.SCM_VER + " " + noSnapshotVersion);
44-
progress.endTrace("done");
41+
SCMReleaser.reportDuration(() -> vcs.setFileContent(newBranchName, SCMReleaser.VER_FILE_NAME, noSnapshotVersion, LogTag.SCM_VER + " " + noSnapshotVersion),
42+
"truncate snapshot: " + noSnapshotVersion + " in branch " + newBranchName, null, progress);
4543
}
4644

4745
private void bumpTrunkMinorVersion(IProgress progress) {
4846
Version newMinorVersion = db.getVersion().toNextMinor();
49-
progress.startTrace("changing to version " + newMinorVersion + " in trunk... ");
50-
vcs.setFileContent(db.getName(), SCMReleaser.VER_FILE_NAME, newMinorVersion.toString(), LogTag.SCM_VER + " " + newMinorVersion);
51-
progress.endTrace("done");
47+
SCMReleaser.reportDuration(() -> vcs.setFileContent(db.getName(), SCMReleaser.VER_FILE_NAME, newMinorVersion.toString(), LogTag.SCM_VER + " " + newMinorVersion),
48+
"change to version " + newMinorVersion + " in trunk", null, progress);
5249
}
5350
}

src/main/java/org/scm4j/releaser/scmactions/procs/SCMProcFreezeMDeps.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public SCMProcFreezeMDeps(ReleaseBranch rb) {
2222

2323
@Override
2424
public void execute(IProgress progress) {
25-
progress.startTrace("reading mdeps to freeze... ");
26-
MDepsFile currentMDepsFile = rb.getMDepsFile();
27-
progress.endTrace("done");
25+
MDepsFile currentMDepsFile = SCMReleaser.reportDuration(() -> rb.getMDepsFile(), "read mdeps to freeze" , null, progress);
2826
if (!currentMDepsFile.hasMDeps()) {
2927
progress.reportStatus("no mdeps to freeze");
3028
return;
@@ -34,9 +32,7 @@ public void execute(IProgress progress) {
3432
Version newVersion;
3533
boolean hasChanges = false;
3634
for (Component currentMDep : currentMDepsFile.getMDeps()) {
37-
progress.startTrace("determining Release Branch version for mdep " + currentMDep + "... ");
38-
rbMDep = new ReleaseBranch(currentMDep);
39-
progress.endTrace("done");
35+
rbMDep = SCMReleaser.reportDuration(() -> new ReleaseBranch(currentMDep), "Release Branch version calculation" , currentMDep, progress);
4036
// untilldb is built -> rbMDep.getVersion is 2.59.1, but we need 2.59.0
4137
newVersion = rbMDep.getVersion();
4238
if (!newVersion.getPatch().equals(Build.ZERO_PATCH)) {
@@ -51,11 +47,8 @@ public void execute(IProgress progress) {
5147
}
5248
if (hasChanges) {
5349
progress.reportStatus("mdeps to freeze:\r\n" + sb.toString());
54-
progress.startTrace("freezing... ");
55-
vcs.setFileContent(rb.getName(), SCMReleaser.MDEPS_FILE_NAME, currentMDepsFile.toFileContent(), LogTag.SCM_MDEPS);
56-
progress.endTrace("done");
50+
SCMReleaser.reportDuration(() -> vcs.setFileContent(rb.getName(), SCMReleaser.MDEPS_FILE_NAME, currentMDepsFile.toFileContent(), LogTag.SCM_MDEPS),
51+
"freeze mdeps" , null, progress);
5752
}
58-
5953
}
60-
6154
}

0 commit comments

Comments
 (0)