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.mojo;
17  
18  import org.apache.maven.plugin.AbstractMojo;
19  
20  import de.smartics.ci.comm.LogHelper;
21  import de.smartics.ci.comm.LogLevel;
22  import de.smartics.ci.maven.Logger;
23  
24  /**
25   * Logging aware mojo.
26   */
27  public abstract class AbstractLoggingMojo extends AbstractMojo // NOPMD
28  {
29  
30    /**
31     * Defines the verboseness of the output.
32     * <ul>
33     * <li><code>QUIET</code> - prints no info messages.</li>
34     * <li><code>NORMAL</code> - only prints inormation to get known what
35     * happened, but without any details.</li>
36     * <li><code>VERBOSE</code> - adds information about the called service and
37     * parameters.</li>
38     * <li><code>TRACE</code> - provides the most verbose output with dumping the
39     * contents of the returned pages.</li>
40     * </ul>
41     *
42     * @parameter expression="${verbose}" default-value="NORMAL"
43     * @since 1.0
44     */
45    protected String verbose;
46  
47    /**
48     * The delegate logger to the maven log.
49     */
50    protected final Logger logger;
51  
52    /**
53     * The log level to use.
54     */
55    protected final LogLevel logLevel;
56  
57    /**
58     * Default constructor.
59     *
60     */
61    public AbstractLoggingMojo()
62    {
63      this.logger = new Logger(super.getLog());
64      this.logLevel = new LogLevel(verbose);
65    }
66  
67    /**
68     * Log a message using the maven logger.
69     *
70     * @param message the message to log.
71     */
72    protected final void logDebug(final String message)
73    {
74      final Logger logger = getLog();
75      LogHelper.logDebug(logger, logLevel, message);
76    }
77  
78    /**
79     * Log a message using the maven logger.
80     *
81     * @param message the message to log.
82     */
83    protected final void logInfo(final String message)
84    {
85      final Logger logger = getLog();
86      LogHelper.logInfo(logger, logLevel, message);
87    }
88  
89    /**
90     * Log a message using the maven logger.
91     *
92     * @param message the message to log.
93     */
94    protected final void logWarn(final String message)
95    {
96      final Logger logger = getLog();
97      LogHelper.logWarn(logger, logLevel, message);
98    }
99  
100   /**
101    * Log a message using the maven logger.
102    *
103    * @param message the message to log.
104    */
105   protected final void logError(final String message)
106   {
107     final Logger logger = getLog();
108     LogHelper.logError(logger, logLevel, message);
109   }
110 
111   /**
112    * Get the logger.
113    *
114    * @return the logging bridge between slf4j logging and maven.
115    */
116   public final Logger getLog()
117   {
118     return logger;
119   }
120   // --- object basics --------------------------------------------------------
121 
122 }