View Javadoc
1   /*
2    * Copyright (c) 2012-present Sonatype, Inc. All rights reserved.
3    *
4    * This program is licensed to you under the Apache License Version 2.0,
5    * and you may not use this file except in compliance with the Apache License Version 2.0.
6    * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7    *
8    * Unless required by applicable law or agreed to in writing,
9    * software distributed under the Apache License Version 2.0 is distributed on an
10   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12   */
13  package org.sonatype.install4j.maven;
14  
15  import org.apache.maven.plugin.logging.Log;
16  import org.apache.tools.ant.DefaultLogger;
17  import org.apache.tools.ant.Project;
18  
19  import java.io.PrintStream;
20  
21  /**
22   * Adapts Ant logging to Maven Logging.
23   *
24   * @since 1.0
25   */
26  public class MavenAntLoggerAdapter
27      extends DefaultLogger
28  {
29    protected Log log;
30  
31    public MavenAntLoggerAdapter(final Log log) {
32      assert log != null;
33      this.log = log;
34    }
35  
36    @Override
37    protected void printMessage(final String message, final PrintStream stream, final int priority) {
38      assert message != null;
39      assert stream != null;
40  
41      switch (priority) {
42        case Project.MSG_ERR:
43          log.error(message);
44          break;
45  
46        case Project.MSG_WARN:
47          log.warn(message);
48          break;
49  
50        case Project.MSG_INFO:
51          log.info(message);
52          break;
53  
54        case Project.MSG_VERBOSE:
55        case Project.MSG_DEBUG:
56          log.debug(message);
57          break;
58      }
59    }
60  }