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 java.util.Collection;
19  import java.util.Map;
20  import org.apache.maven.lifecycle.DefaultLifecycles;
21  import org.apache.maven.plugin.MojoExecution;
22  
23  public class ListPhaseTableDescriptor extends AbstractTableDescriptor {
24  
25      private static final int SEPARATOR_SIZE = ROW_START.length() + 2 * SEPARATOR.length();
26  
27      private int pluginSize;
28      private int executionIdSize;
29      private int goalSize;
30  
31      public static ListPhaseTableDescriptor of(
32              Collection<MojoExecution> executions, DefaultLifecycles defaultLifecycles) {
33  
34          Map<TableColumn, Integer> maxSize = findMaxSize(
35                  executions, defaultLifecycles, TableColumn.ARTIFACT_ID, TableColumn.EXECUTION_ID, TableColumn.GOAL);
36  
37          return new ListPhaseTableDescriptor()
38                  .setPluginSize(maxSize.get(TableColumn.ARTIFACT_ID))
39                  .setGoalSize(maxSize.get(TableColumn.GOAL))
40                  .setExecutionIdSize(maxSize.get(TableColumn.EXECUTION_ID));
41      }
42  
43      public String rowFormat() {
44          return new StringBuilder()
45                  .append(ROW_START)
46                  .append(FORMAT_LEFT_ALIGN)
47                  .append(getPluginSize())
48                  .append(FORMAT_STRING)
49                  .append(SEPARATOR)
50                  .append(FORMAT_LEFT_ALIGN)
51                  .append(getGoalSize())
52                  .append(FORMAT_STRING)
53                  .append(SEPARATOR)
54                  .append(FORMAT_LEFT_ALIGN)
55                  .append(getExecutionIdSize())
56                  .append(FORMAT_STRING)
57                  .toString();
58      }
59  
60      public int width() {
61          return getExecutionIdSize() + getGoalSize() + getPluginSize() + SEPARATOR_SIZE;
62      }
63  
64      public int getPluginSize() {
65          return pluginSize;
66      }
67  
68      public int getExecutionIdSize() {
69          return executionIdSize;
70      }
71  
72      public int getGoalSize() {
73          return goalSize;
74      }
75  
76      public ListPhaseTableDescriptor setPluginSize(int pluginSize) {
77          this.pluginSize = pluginSize;
78          return this;
79      }
80  
81      public ListPhaseTableDescriptor setExecutionIdSize(int executionIdSize) {
82          this.executionIdSize = executionIdSize;
83          return this;
84      }
85  
86      public ListPhaseTableDescriptor setGoalSize(int goalSize) {
87          this.goalSize = goalSize;
88          return this;
89      }
90  }