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  import org.codehaus.plexus.util.StringUtils;
25  
26  import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
27  
28  /**
29   * <p>DefaultReleaseManagerListener class.</p>
30   *
31   * @author Hervé Boutemy
32   */
33  public class DefaultReleaseManagerListener implements ReleaseManagerListener {
34      private final Log log;
35  
36      private final boolean dryRun;
37  
38      private String goal;
39  
40      private List<String> phases;
41  
42      private int currentPhase;
43  
44      /**
45       * <p>Constructor for DefaultReleaseManagerListener.</p>
46       *
47       * @param log a {@link org.apache.maven.plugin.logging.Log} object
48       */
49      public DefaultReleaseManagerListener(Log log) {
50          this(log, false);
51      }
52  
53      /**
54       * <p>Constructor for DefaultReleaseManagerListener.</p>
55       *
56       * @param log a {@link org.apache.maven.plugin.logging.Log} object
57       * @param dryRun a boolean
58       */
59      public DefaultReleaseManagerListener(Log log, boolean dryRun) {
60          this.log = log;
61          this.dryRun = dryRun;
62      }
63  
64      private void nextPhase(String name) {
65          currentPhase++;
66          if (!name.equals(phases.get(currentPhase))) {
67              log.warn("inconsistent phase name: expected '" + phases.get(currentPhase) + "' but got '" + name + "'");
68          }
69      }
70  
71      public void goalStart(String goal, List<String> phases) {
72          log.info("starting " + buffer().mojo(goal) + " goal" + (dryRun ? " in dry-run mode" : "") + ", composed of "
73                  + phases.size() + " phases: " + StringUtils.join(phases.iterator(), ", "));
74          currentPhase = -1;
75          this.phases = phases;
76          this.goal = goal;
77      }
78  
79      public void phaseStart(String name) {
80          nextPhase(name);
81          log.info((currentPhase + 1) + "/" + phases.size() + ' ' + buffer().mojo(goal + ':' + name)
82                  + (dryRun ? " dry-run" : ""));
83      }
84  
85      /**
86       * <p>phaseEnd.</p>
87       */
88      public void phaseEnd() {
89          // NOOP
90      }
91  
92      public void phaseSkip(String name) {
93          nextPhase(name);
94      }
95  
96      /**
97       * <p>goalEnd.</p>
98       */
99      public void goalEnd() {
100         goal = null;
101         phases = null;
102     }
103 
104     public void error(String reason) {
105         log.error("error during phase " + (currentPhase + 1) + "/" + phases.size() + " " + phases.get(currentPhase)
106                 + ": " + reason);
107     }
108 }