View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.ci.maven;
17  
18  import org.apache.maven.plugin.AbstractMojo;
19  
20  import de.smartics.ci.comm.LogHelper;
21  import de.smartics.ci.comm.LogLevel;
22  
23  /**
24   * Logging aware mojo.
25   */
26  public abstract class AbstractLoggingMojo extends AbstractMojo // NOPMD
27  {
28  
29    /**
30     * Defines the verboseness of the output.
31     * <ul>
32     * <li><code>QUIET</code> - prints no info messages.</li>
33     * <li><code>NORMAL</code> - only prints inormation to get known what
34     * happened, but without any details.</li>
35     * <li><code>VERBOSE</code> - adds information about the called service and
36     * parameters.</li>
37     * <li><code>TRACE</code> - provides the most verbose output with dumping the
38     * contents of the returned pages.</li>
39     * </ul>
40     *
41     * @parameter expression="${verbose}" default-value="NORMAL"
42     * @since 1.0
43     */
44    protected String verbose;
45  
46    /**
47     * The delegate logger to the maven log.
48     */
49    protected final Logger logger;
50  
51    /**
52     * The log level to use.
53     */
54    protected final LogLevel logLevel;
55  
56    /**
57     * Default constructor.
58     *
59     */
60    public AbstractLoggingMojo()
61    {
62      this.logger = new Logger(super.getLog());
63      this.logLevel = new LogLevel(verbose);
64    }
65  
66    /**
67     * Log a message using the maven logger.
68     *
69     * @param message the message to log.
70     */
71    protected final void logDebug(final String message)
72    {
73      final Logger logger = getLog();
74      LogHelper.logDebug(logger, logLevel, message);
75    }
76  
77    /**
78     * Log a message using the maven logger.
79     *
80     * @param message the message to log.
81     */
82    protected final void logInfo(final String message)
83    {
84      final Logger logger = getLog();
85      LogHelper.logInfo(logger, logLevel, message);
86    }
87  
88    /**
89     * Log a message using the maven logger.
90     *
91     * @param message the message to log.
92     */
93    protected final void logWarn(final String message)
94    {
95      final Logger logger = getLog();
96      LogHelper.logWarn(logger, logLevel, message);
97    }
98  
99    /**
100    * Log a message using the maven logger.
101    *
102    * @param message the message to log.
103    */
104   protected final void logError(final String message)
105   {
106     final Logger logger = getLog();
107     LogHelper.logError(logger, logLevel, message);
108   }
109 
110   /**
111    * Get the logger.
112    *
113    * @return the logging bridge between slf4j logging and maven.
114    */
115   public final Logger getLog()
116   {
117     return logger;
118   }
119   // --- object basics --------------------------------------------------------
120 
121 }