1 package it.serendigity.maven.plugin.lifecycle.helper.output;
2
3 import java.util.EnumSet;
4 import java.util.Set;
5
6 import it.serendigity.maven.plugin.lifecycle.helper.vo.MavenExecutionAttribute;
7 import it.serendigity.maven.plugin.lifecycle.helper.vo.MavenExecutionInfo;
8 import it.serendigity.maven.plugin.lifecycle.helper.vo.MavenExecutionPlanInfo;
9 import it.serendigity.maven.plugin.lifecycle.helper.vo.MavenExecutionSummary;
10
11 public abstract class TxtOutput {
12
13 private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
14 private Set<MavenExecutionAttribute> columns;
15 private String rowFormat;
16 private final MavenExecutionPlanInfo executionPlanInfo;
17
18 protected TxtOutput( MavenExecutionPlanInfo executionPlanInfo ) {
19
20 this.executionPlanInfo = executionPlanInfo;
21
22 }
23
24
25
26
27
28
29
30 protected void initTable() {
31 this.columns = createColumns();
32
33 this.rowFormat = createRowFormat();
34 }
35
36
37
38
39
40
41 protected String createTable() {
42 initTable();
43 return "";
44 }
45
46 protected abstract String createRowFormat();
47
48 protected String getHeaderTitle( MavenExecutionAttribute mavenExecutionAttribute ) {
49 return mavenExecutionAttribute.getShortDescription().toUpperCase();
50 }
51
52 protected MavenExecutionSummary getSummary() {
53 return executionPlanInfo.getSummary();
54 }
55
56 protected Set<MavenExecutionAttribute> createColumns() {
57 return EnumSet.allOf( MavenExecutionAttribute.class );
58 }
59
60 protected String headerTitle() {
61
62 Object[] columnTitle = new String[getColumns().size()];
63
64 int count = 0;
65 for ( MavenExecutionAttribute mavenExecutionAttribute : getColumns() ) {
66 columnTitle[count] = getHeaderTitle( mavenExecutionAttribute );
67 count++;
68 }
69
70 return String.format( getRowFormat(), columnTitle );
71 }
72
73 protected String tableRow( MavenExecutionInfo info ) {
74
75 Object[] rowValues = new Object[getColumns().size()];
76
77 int count = 0;
78 for ( MavenExecutionAttribute mavenExecutionAttribute : getColumns() ) {
79 rowValues[count] = info.getValueOrEmpty( mavenExecutionAttribute );
80 count++;
81 }
82
83 return String.format( getRowFormat(), rowValues );
84
85 }
86
87 public Set<MavenExecutionAttribute> getColumns() {
88 return columns;
89 }
90
91 public static String newLineSeparator() {
92 return LINE_SEPARATOR;
93 }
94
95 public String getRowFormat() {
96 return rowFormat;
97 }
98
99 protected MavenExecutionPlanInfo getExecutionPlanInfo() {
100 return executionPlanInfo;
101 }
102
103 }