View Javadoc
1   package org.apache.maven.shared.release;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * <p>DefaultReleaseManagerListener class.</p>
31   *
32   * @author Hervé Boutemy
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       * <p>Constructor for DefaultReleaseManagerListener.</p>
49       *
50       * @param log a {@link org.apache.maven.plugin.logging.Log} object
51       */
52      public DefaultReleaseManagerListener( Log log )
53      {
54          this( log, false );
55      }
56  
57      /**
58       * <p>Constructor for DefaultReleaseManagerListener.</p>
59       *
60       * @param log a {@link org.apache.maven.plugin.logging.Log} object
61       * @param dryRun a boolean
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              // out of goal phase
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      * <p>phaseEnd.</p>
103      */
104     public void phaseEnd()
105     {
106         // NOOP
107     }
108 
109     public void phaseSkip( String name )
110     {
111         nextPhase( name );
112     }
113 
114     /**
115      * <p>goalEnd.</p>
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 }