View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar;
21  
22  import org.apache.maven.plugin.logging.Log;
23  import org.apache.tools.ant.BuildEvent;
24  import org.apache.tools.ant.BuildListener;
25  import org.apache.tools.ant.Project;
26  
27  /**
28   * Logger to connect the Ant logging to the Maven logging.
29   *
30   * @author Mark Donszelmann
31   */
32  public class NarLogger implements BuildListener {
33  
34    private final Log log;
35  
36    public NarLogger(final Log log) {
37      this.log = log;
38    }
39  
40    @Override
41    public void buildFinished(final BuildEvent event) {
42    }
43  
44    @Override
45    public void buildStarted(final BuildEvent event) {
46    }
47  
48    @Override
49    public final void messageLogged(final BuildEvent event) {
50      final String msg = event.getMessage();
51      switch (event.getPriority()) {
52        case Project.MSG_ERR:
53          if (msg.contains("ar: creating archive")) {
54            this.log.debug(msg);
55          } else if (msg.contains("warning")) {
56            this.log.warn(msg);
57          } else {
58            this.log.error(msg);
59          }
60          break;
61        case Project.MSG_WARN:
62          this.log.warn(msg);
63          break;
64        case Project.MSG_INFO:
65          if (msg.contains("error")) {
66            this.log.error(msg);
67          } else {
68            this.log.info(msg);
69          }
70          break;
71        case Project.MSG_VERBOSE:
72          this.log.debug(msg);
73          break;
74        default:
75        case Project.MSG_DEBUG:
76          this.log.debug(msg);
77          break;
78      }
79    }
80  
81    @Override
82    public void targetFinished(final BuildEvent event) {
83    }
84  
85    @Override
86    public void targetStarted(final BuildEvent event) {
87    }
88  
89    @Override
90    public void taskFinished(final BuildEvent event) {
91    }
92  
93    @Override
94    public void taskStarted(final BuildEvent event) {
95    }
96  }