1 package org.apache.maven.shared.release;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.plugin.logging.Log;
25 import org.codehaus.plexus.util.StringUtils;
26
27 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
28
29
30
31
32
33
34 public class DefaultReleaseManagerListener
35 implements ReleaseManagerListener
36 {
37 private final Log log;
38
39 private final boolean dryRun;
40
41 private String goal;
42
43 private List<String> phases;
44
45 private int currentPhase;
46
47
48
49
50
51
52 public DefaultReleaseManagerListener( Log log )
53 {
54 this( log, false );
55 }
56
57
58
59
60
61
62
63 public DefaultReleaseManagerListener( Log log, boolean dryRun )
64 {
65 this.log = log;
66 this.dryRun = dryRun;
67 }
68
69 private void nextPhase( String name )
70 {
71 currentPhase++;
72 if ( !name.equals( phases.get( currentPhase ) ) )
73 {
74 log.warn( "inconsistent phase name: expected '" + phases.get( currentPhase ) + "' but got '" + name + "'" );
75 }
76 }
77
78 public void goalStart( String goal, List<String> phases )
79 {
80 log.info( "starting " + buffer().strong( goal ) + " goal" + ( dryRun ? " in dry-run mode" : "" )
81 + ", composed of " + phases.size() + " phases: " + StringUtils.join( phases.iterator(), ", " ) );
82 currentPhase = -1;
83 this.phases = phases;
84 this.goal = goal;
85 }
86
87 public void phaseStart( String name )
88 {
89 if ( goal == null || ( ( currentPhase + 1 ) >= phases.size() ) )
90 {
91
92 log.info( "phase " + buffer().strong( name ) + ( dryRun ? " (dry-run)" : "" ) );
93 return;
94 }
95
96 nextPhase( name );
97 log.info( buffer().strong( "[" + goal + ( dryRun ? " dry-run" : "" ) + "] " ).toString() + ( currentPhase + 1 )
98 + "/" + phases.size() + " " + buffer().strong( name ) );
99 }
100
101
102
103
104 public void phaseEnd()
105 {
106
107 }
108
109 public void phaseSkip( String name )
110 {
111 nextPhase( name );
112 }
113
114
115
116
117 public void goalEnd()
118 {
119 goal = null;
120 phases = null;
121 }
122
123 public void error( String reason )
124 {
125 log.error( "error during phase " + ( currentPhase + 1 ) + "/" + phases.size() + " " + phases.get( currentPhase )
126 + ": " + reason );
127 }
128 }