View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.release;
20  
21  import java.util.List;
22  
23  import org.apache.maven.plugin.logging.Log;
24  
25  import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
26  
27  /**
28   * <p>DefaultReleaseManagerListener class.</p>
29   *
30   * @author Hervé Boutemy
31   */
32  public class DefaultReleaseManagerListener implements ReleaseManagerListener {
33      private final Log log;
34  
35      private final boolean dryRun;
36  
37      private String goal;
38  
39      private List<String> phases;
40  
41      private int currentPhase;
42  
43      /**
44       * <p>Constructor for DefaultReleaseManagerListener.</p>
45       *
46       * @param log a {@link org.apache.maven.plugin.logging.Log} object
47       */
48      public DefaultReleaseManagerListener(Log log) {
49          this(log, false);
50      }
51  
52      /**
53       * <p>Constructor for DefaultReleaseManagerListener.</p>
54       *
55       * @param log a {@link org.apache.maven.plugin.logging.Log} object
56       * @param dryRun a boolean
57       */
58      public DefaultReleaseManagerListener(Log log, boolean dryRun) {
59          this.log = log;
60          this.dryRun = dryRun;
61      }
62  
63      private void nextPhase(String name) {
64          currentPhase++;
65          if (!name.equals(phases.get(currentPhase))) {
66              log.warn("inconsistent phase name: expected '" + phases.get(currentPhase) + "' but got '" + name + "'");
67          }
68      }
69  
70      public void goalStart(String goal, List<String> phases) {
71          log.info("starting " + buffer().mojo(goal) + " goal" + (dryRun ? " in dry-run mode" : "") + ", composed of "
72                  + phases.size() + " phases: " + String.join(", ", phases));
73          currentPhase = -1;
74          this.phases = phases;
75          this.goal = goal;
76      }
77  
78      public void phaseStart(String name) {
79          nextPhase(name);
80          log.info((currentPhase + 1) + "/" + phases.size() + ' ' + buffer().mojo(goal + ':' + name)
81                  + (dryRun ? " dry-run" : ""));
82      }
83  
84      /**
85       * <p>phaseEnd.</p>
86       */
87      public void phaseEnd() {
88          // NOOP
89      }
90  
91      public void phaseSkip(String name) {
92          nextPhase(name);
93      }
94  
95      /**
96       * <p>goalEnd.</p>
97       */
98      public void goalEnd() {
99          goal = null;
100         phases = null;
101     }
102 
103     public void error(String reason) {
104         log.error("error during phase " + (currentPhase + 1) + "/" + phases.size() + " " + phases.get(currentPhase)
105                 + ": " + reason);
106     }
107 }