1- package org .scm4j .wf ;
1+ package org .scm4j .releaser ;
22
3+ import org .scm4j .commons .Version ;
4+ import org .scm4j .releaser .actions .ActionKind ;
5+ import org .scm4j .releaser .actions .ActionNone ;
6+ import org .scm4j .releaser .actions .IAction ;
7+ import org .scm4j .releaser .branch .DevelopBranch ;
8+ import org .scm4j .releaser .branch .DevelopBranchStatus ;
9+ import org .scm4j .releaser .branch .ReleaseBranch ;
10+ import org .scm4j .releaser .branch .ReleaseBranchStatus ;
11+ import org .scm4j .releaser .conf .*;
12+ import org .scm4j .releaser .exceptions .EComponentConfig ;
13+ import org .scm4j .releaser .scmactions .ReleaseReason ;
14+ import org .scm4j .releaser .scmactions .SCMActionBuild ;
15+ import org .scm4j .releaser .scmactions .SCMActionFork ;
16+ import org .scm4j .releaser .scmactions .SCMActionTagRelease ;
317import org .scm4j .vcs .api .IVCS ;
418import org .scm4j .vcs .api .VCSTag ;
5- import org .scm4j .wf .actions .ActionKind ;
6- import org .scm4j .wf .actions .ActionNone ;
7- import org .scm4j .wf .actions .IAction ;
8- import org .scm4j .wf .branch .DevelopBranch ;
9- import org .scm4j .wf .branch .DevelopBranchStatus ;
10- import org .scm4j .wf .branch .ReleaseBranch ;
11- import org .scm4j .wf .branch .ReleaseBranchStatus ;
12- import org .scm4j .wf .conf .*;
13- import org .scm4j .wf .exceptions .EComponentConfig ;
14- import org .scm4j .wf .scmactions .ReleaseReason ;
15- import org .scm4j .wf .scmactions .SCMActionBuild ;
16- import org .scm4j .wf .scmactions .SCMActionFork ;
17- import org .scm4j .wf .scmactions .SCMActionTagRelease ;
1819
1920import java .io .File ;
2021import java .util .ArrayList ;
2122import java .util .List ;
2223import java .util .ListIterator ;
2324
24- public class SCMWorkflow {
25+ public class SCMReleaser {
2526
2627 public static final String MDEPS_FILE_NAME = "mdeps" ;
2728 public static final String VER_FILE_NAME = "version" ;
@@ -30,11 +31,11 @@ public class SCMWorkflow {
3031
3132 private final List <Option > options ;
3233
33- public SCMWorkflow (List <Option > options ) {
34+ public SCMReleaser (List <Option > options ) {
3435 this .options = options ;
3536 }
3637
37- public SCMWorkflow () {
38+ public SCMReleaser () {
3839 this (new ArrayList <Option >());
3940 }
4041
@@ -49,15 +50,15 @@ public static List<Option> parseOptions(String[] args) {
4950 }
5051
5152 public static File getDelayedTagsFile () {
52- return new File (SCMWorkflow .DELAYED_TAGS_FILE_NAME );
53+ return new File (SCMReleaser .DELAYED_TAGS_FILE_NAME );
5354 }
5455
5556 public IAction getProductionReleaseAction (String componentName ) {
56- return getProductionReleaseAction (new Component (componentName ), ActionKind .AUTO );
57+ return getProductionReleaseAction (new Component (componentName , true ), ActionKind .AUTO );
5758 }
5859
5960 public IAction getProductionReleaseAction (String componentCoords , ActionKind actionKind ) {
60- return getProductionReleaseAction (new Component (componentCoords ), actionKind );
61+ return getProductionReleaseAction (new Component (componentCoords , true ), actionKind );
6162 }
6263
6364 public IAction getProductionReleaseAction (Component comp ) {
@@ -66,11 +67,16 @@ public IAction getProductionReleaseAction(Component comp) {
6667
6768 public IAction getProductionReleaseAction (Component comp , ActionKind actionKind ) {
6869 List <IAction > childActions = new ArrayList <>();
69- DevelopBranch db = new DevelopBranch (comp );
70- List <Component > devMDeps = db .getMDeps ();
70+ ReleaseBranch rb = new ReleaseBranch (comp );
71+ List <Component > mDeps ;
72+ if (rb .exists ()) {
73+ mDeps = rb .getMDeps ();
74+ } else {
75+ mDeps = new DevelopBranch (comp ).getMDeps ();
76+ }
7177
72- for (Component mDep : devMDeps ) {
73- childActions .add (getProductionReleaseAction (mDep , actionKind ));
78+ for (Component mDep : mDeps ) {
79+ childActions .add (getProductionReleaseAction (mDep , actionKind ));
7480 }
7581
7682 return getProductionReleaseActionRoot (comp , childActions , actionKind );
@@ -86,44 +92,41 @@ public IAction getProductionReleaseActionRoot(Component comp, List<IAction> chil
8692 if (dbs == DevelopBranchStatus .IGNORED ) {
8793 return new ActionNone (comp , childActions , "develop branch is IGNORED" );
8894 }
89-
95+
9096 ReleaseBranch rb = new ReleaseBranch (comp );
9197 ReleaseBranchStatus rbs = rb .getStatus ();
9298
9399 if (rbs == ReleaseBranchStatus .MISSING ) {
94100 skipAllBuilds (childActions );
95101 if (actionKind == ActionKind .BUILD ) {
96- return new ActionNone (comp , childActions , "nothing to build " );
97- }
98- if (dbs == DevelopBranchStatus .MODIFIED ) {
99- return new SCMActionFork (comp , childActions , ReleaseReason .NEW_FEATURES , options );
100- } else {
101- return new SCMActionFork (comp , childActions , ReleaseReason .NEW_DEPENDENCIES , options );
102+ return new ActionNone (comp , childActions , "nothing to build. " + rb .getVersion () + " " + rb .getStatus ());
102103 }
104+
105+ return new SCMActionFork (comp , childActions , ReleaseBranchStatus .MISSING , ReleaseBranchStatus .MDEPS_ACTUAL , options );
103106 }
104107
105108 if (rbs == ReleaseBranchStatus .BRANCHED ) {
106109 // need to freeze mdeps
107110 skipAllBuilds (childActions );
108111 if (actionKind == ActionKind .BUILD ) {
109- return new ActionNone (comp , childActions , "nothing to build" );
112+ return new ActionNone (comp , childActions , "nothing to build. " + rb . getVersion () + " " + rb . getStatus () );
110113 }
111- return new SCMActionFork (comp , childActions , ReleaseReason . NEW_FEATURES , options );
114+ return new SCMActionFork (comp , childActions , ReleaseBranchStatus . BRANCHED , ReleaseBranchStatus . MDEPS_ACTUAL , options );
112115 }
113116
114117 if (rbs == ReleaseBranchStatus .MDEPS_FROZEN ) {
115118 if (needToActualizeMDeps (rb )) {
116119 // need to actualize
117120 skipAllBuilds (childActions );
118121 if (actionKind == ActionKind .BUILD ) {
119- return new ActionNone (comp , childActions , "nothing to build" );
122+ return new ActionNone (comp , childActions , "nothing to build. " + rb . getVersion () + " " + rb . getStatus () );
120123 }
121- return new SCMActionFork (comp , childActions , ReleaseReason . ACTUALIZE_MDEPS , options );
124+ return new SCMActionFork (comp , childActions , ReleaseBranchStatus . MDEPS_FROZEN , ReleaseBranchStatus . MDEPS_ACTUAL , options );
122125 } else {
123126 // All necessary version will be build by Child Actions. Need to build
124127 skipAllForks (childActions );
125128 if (actionKind == ActionKind .FORK ) {
126- return new ActionNone (comp , childActions , "nothing to fork" );
129+ return new ActionNone (comp , childActions , "nothing to fork. " + rb . getVersion () + " " + rb . getStatus () );
127130 }
128131 return new SCMActionBuild (comp , childActions , ReleaseReason .NEW_DEPENDENCIES , rb .getVersion (), options );
129132 }
@@ -132,31 +135,37 @@ public IAction getProductionReleaseActionRoot(Component comp, List<IAction> chil
132135 if (rbs == ReleaseBranchStatus .MDEPS_ACTUAL ) {
133136 // need to build
134137 if (actionKind == ActionKind .FORK ) {
135- return new ActionNone (comp , childActions , "nothing to fork" );
138+ return new ActionNone (comp , childActions , "nothing to fork. " + rb . getVersion () + " " + rb . getStatus () );
136139 }
137140 return new SCMActionBuild (comp , childActions , ReleaseReason .NEW_FEATURES , rb .getVersion (), options );
138141 }
139142
140143 if (hasForkChildActions (childActions )) {
141144 skipAllBuilds (childActions );
142145 if (actionKind == ActionKind .FORK ) {
143- return new ActionNone (comp , childActions , "nothing to build" );
146+ return new ActionNone (comp , childActions , "nothing to build. " + rb . getVersion () + " " + rb . getStatus () );
144147 }
145- return new SCMActionFork (comp , childActions , ReleaseReason . NEW_DEPENDENCIES , options );
148+ return new SCMActionFork (comp , childActions , rbs , rbs , options );
146149 }
147150
148- return new ActionNone (comp , childActions , rbs .toString ());
151+ return new ActionNone (comp , childActions , rb . getVersion (). toString () + " " + rbs .toString ());
149152 }
150153
151154 private boolean needToActualizeMDeps (ReleaseBranch currentCompRB ) {
152155 List <Component > mDeps = currentCompRB .getMDeps ();
153156 ReleaseBranch mDepRB ;
154157 for (Component mDep : mDeps ) {
155158 mDepRB = new ReleaseBranch (mDep );
156- if (mDepRB .getStatus () == ReleaseBranchStatus .MDEPS_ACTUAL ) {
159+ ReleaseBranchStatus rbs = mDepRB .getStatus ();
160+ if (rbs == ReleaseBranchStatus .MDEPS_ACTUAL ) {
157161 if (!mDepRB .getCurrentVersion ().equals (mDep .getVersion ())) {
158162 return true ;
159163 }
164+
165+ } else if (rbs == ReleaseBranchStatus .ACTUAL ) {
166+ if (!mDepRB .getCurrentVersion ().toPreviousPatch ().equals (mDep .getVersion ())) {
167+ return true ;
168+ }
160169 } else {
161170 if (needToActualizeMDeps (mDepRB )) {
162171 return true ;
@@ -194,7 +203,8 @@ private void skipAllBuilds(List<IAction> childActions) {
194203 action = li .next ();
195204 skipAllBuilds (action .getChildActions ());
196205 if (action instanceof SCMActionBuild ) {
197- li .set (new ActionNone (((SCMActionBuild ) action ).getComponent (), action .getChildActions (), "build skipped because not all parent components forked" ));
206+ li .set (new ActionNone (((SCMActionBuild ) action ).getComponent (), action .getChildActions (), ((SCMActionBuild ) action ).getTargetVersion () +
207+ " build skipped because not all parent components forked" ));
198208 }
199209 }
200210 }
@@ -229,7 +239,7 @@ private IAction getTagReleaseActionRoot(Component comp, List<IAction> childActio
229239 if (tagsOnRevision .isEmpty ()) {
230240 return new SCMActionTagRelease (comp , childActions , options );
231241 }
232- Version delayedTagVersion = new Version (vcs .getFileContent (rb .getName (), SCMWorkflow .VER_FILE_NAME , delayedRevisionToTag ));
242+ Version delayedTagVersion = new Version (vcs .getFileContent (rb .getName (), SCMReleaser .VER_FILE_NAME , delayedRevisionToTag ));
233243 for (VCSTag tag : tagsOnRevision ) {
234244 if (tag .getTagName ().equals (delayedTagVersion .toReleaseString ())) {
235245 return new ActionNone (comp , childActions , "tag " + tag .getTagName () + " already exists" );
@@ -243,4 +253,8 @@ public static TagDesc getTagDesc(String verStr) {
243253 String tagMessage = tagName + " release" ;
244254 return new TagDesc (tagName , tagMessage );
245255 }
256+
257+ public List <Option > getOptions () {
258+ return options ;
259+ }
246260}
0 commit comments