66import java .util .Map ;
77import java .util .concurrent .ConcurrentHashMap ;
88import java .util .concurrent .ForkJoinPool ;
9+ import java .util .function .Supplier ;
910
1011import org .scm4j .commons .progress .IProgress ;
1112import 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 }
0 commit comments