View Javadoc
1   /*
2    * Copyright (C) 2012 Jean-Christophe Gay (contact@jeanchristophegay.com)
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 org.codehaus.mojo.buildplan.display;
17  
18  import static org.codehaus.plexus.util.StringUtils.defaultString;
19  
20  import org.apache.maven.lifecycle.DefaultLifecycles;
21  import org.apache.maven.lifecycle.Lifecycle;
22  import org.apache.maven.plugin.MojoExecution;
23  import org.apache.maven.plugin.descriptor.MojoDescriptor;
24  
25  public class MojoExecutionDisplay {
26  
27      protected final MojoExecution execution;
28  
29      public MojoExecutionDisplay(MojoExecution execution) {
30          this.execution = execution;
31      }
32  
33      public String getPhase() {
34          MojoDescriptor mojoDescriptor = execution.getMojoDescriptor();
35          if (mojoDescriptor != null && mojoDescriptor.getPhase() != null) {
36              return mojoDescriptor.getPhase();
37          }
38          return defaultString(execution.getLifecyclePhase());
39      }
40  
41      public String getLifecycle(DefaultLifecycles defaultLifecycles) {
42          Lifecycle lifecycle = defaultLifecycles.get(execution.getLifecyclePhase());
43          return defaultString(lifecycle == null ? null : lifecycle.getId());
44      }
45  
46      public String getArtifactId() {
47          if (execution.getArtifactId() == null) {
48              return "";
49          }
50          return MavenPluginPatterns.mayHighlightPrefix(execution.getArtifactId());
51      }
52  
53      public String getVersion() {
54          return defaultString(execution.getVersion());
55      }
56  
57      public String getGoal() {
58          return defaultString(execution.getGoal());
59      }
60  
61      public String getExecutionId() {
62          return defaultString(execution.getExecutionId());
63      }
64  }