@@ -72,8 +72,6 @@ public class DefaultReleaseManager
72
72
*/
73
73
private final AtomicReference <ReleaseDescriptorStore > configStore ;
74
74
75
- private static final int PHASE_SKIP = 0 , PHASE_START = 1 , PHASE_END = 2 , GOAL_END = 12 , ERROR = 99 ;
76
-
77
75
@ Inject
78
76
public DefaultReleaseManager ( Map <String , Strategy > strategies ,
79
77
Map <String , ReleasePhase > releasePhases ,
@@ -187,7 +185,7 @@ public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependen
187
185
188
186
for ( int idx = 0 ; idx <= index ; idx ++ )
189
187
{
190
- updateListener ( prepareRequest .getReleaseManagerListener (), preparePhases .get ( idx ), PHASE_SKIP );
188
+ phaseSkip ( prepareRequest .getReleaseManagerListener (), preparePhases .get ( idx ) );
191
189
}
192
190
193
191
if ( index == preparePhases .size () - 1 )
@@ -212,7 +210,7 @@ else if ( index >= 0 )
212
210
throw new ReleaseExecutionException ( "Unable to find phase '" + name + "' to execute" );
213
211
}
214
212
215
- updateListener ( prepareRequest .getReleaseManagerListener (), name , PHASE_START );
213
+ phaseStart ( prepareRequest .getReleaseManagerListener (), name );
216
214
217
215
ReleaseResult phaseResult = null ;
218
216
try
@@ -249,10 +247,10 @@ else if ( index >= 0 )
249
247
throw new ReleaseExecutionException ( "Error writing release properties after completing phase" , e );
250
248
}
251
249
252
- updateListener ( prepareRequest .getReleaseManagerListener (), name , PHASE_END );
250
+ phaseEnd ( prepareRequest .getReleaseManagerListener () );
253
251
}
254
252
255
- updateListener ( prepareRequest .getReleaseManagerListener (), "prepare" , GOAL_END );
253
+ goalEnd ( prepareRequest .getReleaseManagerListener () );
256
254
}
257
255
258
256
@ Override
@@ -277,16 +275,16 @@ public void rollback( ReleaseRollbackRequest rollbackRequest )
277
275
throw new ReleaseExecutionException ( "Unable to find phase '" + name + "' to execute" );
278
276
}
279
277
280
- updateListener ( rollbackRequest .getReleaseManagerListener (), name , PHASE_START );
278
+ phaseStart ( rollbackRequest .getReleaseManagerListener (), name );
281
279
phase .execute ( releaseDescriptor ,
282
280
rollbackRequest .getReleaseEnvironment (),
283
281
rollbackRequest .getReactorProjects () );
284
- updateListener ( rollbackRequest .getReleaseManagerListener (), name , PHASE_END );
282
+ phaseEnd ( rollbackRequest .getReleaseManagerListener () );
285
283
}
286
284
287
285
//call release:clean so that resume will not be possible anymore after a rollback
288
286
clean ( rollbackRequest );
289
- updateListener ( rollbackRequest .getReleaseManagerListener (), "rollback" , GOAL_END );
287
+ goalEnd ( rollbackRequest .getReleaseManagerListener () );
290
288
}
291
289
292
290
@ Override
@@ -363,7 +361,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
363
361
throw new ReleaseExecutionException ( "Unable to find phase '" + name + "' to execute" );
364
362
}
365
363
366
- updateListener ( performRequest .getReleaseManagerListener (), name , PHASE_START );
364
+ phaseStart ( performRequest .getReleaseManagerListener (), name );
367
365
368
366
ReleaseResult phaseResult = null ;
369
367
try
@@ -389,7 +387,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
389
387
}
390
388
}
391
389
392
- updateListener ( performRequest .getReleaseManagerListener (), name , PHASE_END );
390
+ phaseEnd ( performRequest .getReleaseManagerListener () );
393
391
}
394
392
395
393
if ( BooleanUtils .isNotFalse ( performRequest .getClean () ) )
@@ -398,7 +396,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
398
396
clean ( performRequest );
399
397
}
400
398
401
- updateListener ( performRequest .getReleaseManagerListener (), "perform" , GOAL_END );
399
+ goalEnd ( performRequest .getReleaseManagerListener () );
402
400
}
403
401
404
402
@ Override
@@ -445,7 +443,7 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
445
443
throw new ReleaseExecutionException ( "Unable to find phase '" + name + "' to execute" );
446
444
}
447
445
448
- updateListener ( branchRequest .getReleaseManagerListener (), name , PHASE_START );
446
+ phaseStart ( branchRequest .getReleaseManagerListener (), name );
449
447
450
448
if ( dryRun )
451
449
{
@@ -459,15 +457,16 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
459
457
branchRequest .getReleaseEnvironment (),
460
458
branchRequest .getReactorProjects () );
461
459
}
462
- updateListener ( branchRequest .getReleaseManagerListener (), name , PHASE_END );
460
+
461
+ phaseEnd ( branchRequest .getReleaseManagerListener () );
463
462
}
464
463
465
464
if ( !dryRun )
466
465
{
467
466
clean ( branchRequest );
468
467
}
469
468
470
- updateListener ( branchRequest .getReleaseManagerListener (), "branch" , GOAL_END );
469
+ goalEnd ( branchRequest .getReleaseManagerListener () );
471
470
}
472
471
473
472
@ Override
@@ -513,16 +512,16 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
513
512
throw new ReleaseExecutionException ( "Unable to find phase '" + name + "' to execute" );
514
513
}
515
514
516
- updateListener ( updateVersionsRequest .getReleaseManagerListener (), name , PHASE_START );
515
+ phaseStart ( updateVersionsRequest .getReleaseManagerListener (), name );
517
516
phase .execute ( releaseDescriptor ,
518
517
updateVersionsRequest .getReleaseEnvironment (),
519
518
updateVersionsRequest .getReactorProjects () );
520
- updateListener ( updateVersionsRequest .getReleaseManagerListener (), name , PHASE_END );
519
+ phaseEnd ( updateVersionsRequest .getReleaseManagerListener () );
521
520
}
522
521
523
522
clean ( updateVersionsRequest );
524
523
525
- updateListener ( updateVersionsRequest .getReleaseManagerListener (), "updateVersions" , GOAL_END );
524
+ goalEnd ( updateVersionsRequest .getReleaseManagerListener () );
526
525
}
527
526
528
527
/**
@@ -560,15 +559,10 @@ private ReleaseDescriptorBuilder loadReleaseDescriptorBuilder( ReleaseDescriptor
560
559
{
561
560
try
562
561
{
563
- updateListener ( listener , "verify-release-configuration" , PHASE_START );
564
- ReleaseDescriptorBuilder result = configStore .get ().read ( builder );
565
- updateListener ( listener , "verify-release-configuration" , PHASE_END );
566
- return result ;
562
+ return configStore .get ().read ( builder );
567
563
}
568
564
catch ( ReleaseDescriptorStoreException e )
569
565
{
570
- updateListener ( listener , e .getMessage (), ERROR );
571
-
572
566
throw new ReleaseExecutionException ( "Error reading stored configuration: " + e .getMessage (), e );
573
567
}
574
568
}
@@ -592,8 +586,6 @@ protected void clean( AbstractReleaseRequest releaseRequest ) throws ReleaseFai
592
586
@ Override
593
587
public void clean ( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureException
594
588
{
595
- updateListener ( cleanRequest .getReleaseManagerListener (), "cleanup" , PHASE_START );
596
-
597
589
logger .info ( "Cleaning up after release..." );
598
590
599
591
ReleaseDescriptor releaseDescriptor =
@@ -616,8 +608,6 @@ public void clean( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureExcep
616
608
( (ResourceGenerator ) phase ).clean ( cleanRequest .getReactorProjects () );
617
609
}
618
610
}
619
-
620
- updateListener ( cleanRequest .getReleaseManagerListener (), "cleanup" , PHASE_END );
621
611
}
622
612
623
613
void goalStart ( ReleaseManagerListener listener , String goal , List <String > phases )
@@ -628,27 +618,43 @@ void goalStart( ReleaseManagerListener listener, String goal, List<String> phase
628
618
}
629
619
}
630
620
631
- void updateListener ( ReleaseManagerListener listener , String name , int state )
621
+ void goalEnd ( ReleaseManagerListener listener )
632
622
{
633
623
if ( listener != null )
634
624
{
635
- switch ( state )
636
- {
637
- case GOAL_END :
638
- listener .goalEnd ();
639
- break ;
640
- case PHASE_SKIP :
641
- listener .phaseSkip ( name );
642
- break ;
643
- case PHASE_START :
644
- listener .phaseStart ( name );
645
- break ;
646
- case PHASE_END :
647
- listener .phaseEnd ();
648
- break ;
649
- default :
650
- listener .error ( name );
651
- }
625
+ listener .goalEnd ();
626
+ }
627
+ }
628
+
629
+ void phaseSkip ( ReleaseManagerListener listener , String name )
630
+ {
631
+ if ( listener != null )
632
+ {
633
+ listener .phaseSkip ( name );
634
+ }
635
+ }
636
+
637
+ void phaseStart ( ReleaseManagerListener listener , String name )
638
+ {
639
+ if ( listener != null )
640
+ {
641
+ listener .phaseStart ( name );
642
+ }
643
+ }
644
+
645
+ void phaseEnd ( ReleaseManagerListener listener )
646
+ {
647
+ if ( listener != null )
648
+ {
649
+ listener .phaseEnd ();
650
+ }
651
+ }
652
+
653
+ void error ( ReleaseManagerListener listener , String name )
654
+ {
655
+ if ( listener != null )
656
+ {
657
+ listener .error ( name );
652
658
}
653
659
}
654
660
@@ -726,7 +732,10 @@ private void logInfo( ReleaseResult result, String message )
726
732
727
733
private void captureException ( ReleaseResult result , ReleaseManagerListener listener , Exception e )
728
734
{
729
- updateListener ( listener , e .getMessage (), ERROR );
735
+ if ( listener != null )
736
+ {
737
+ listener .error ( e .getMessage () );
738
+ }
730
739
731
740
result .appendError ( e );
732
741
0 commit comments