/
PropertyUpdatesReportRenderer.java
195 lines (165 loc) · 6.47 KB
/
PropertyUpdatesReportRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package org.codehaus.mojo.versions.reporting;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Locale;
import java.util.Map;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.mojo.versions.api.Property;
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesModel;
import org.codehaus.plexus.i18n.I18N;
import static java.util.Optional.empty;
/**
* @since 1.0-beta-1
*/
public class PropertyUpdatesReportRenderer extends AbstractVersionsReportRenderer<PropertyUpdatesModel>
{
public PropertyUpdatesReportRenderer( I18N i18n, Sink sink, Locale locale, String bundleName,
PropertyUpdatesModel model )
{
super( i18n, sink, locale, bundleName, model );
}
@Override
protected void renderManagementSummaryTable()
{
}
@Override
protected void renderSummaryTable()
{
renderTable( "report.overview.property", model.getAllUpdates(),
"report.overview.noProperty" );
}
/**
* {@inheritDoc}
*/
@Override
protected void renderDetails()
{
model.getAllUpdates().forEach( this::renderPropertyDetail );
}
protected void renderTable( String titleKey, Map<Property, PropertyVersions> contents, String emptyKey )
{
sink.section2();
sink.sectionTitle2();
sink.text( getText( titleKey ) );
sink.sectionTitle2_();
if ( contents.isEmpty() )
{
sink.paragraph();
sink.text( getText( emptyKey ) );
sink.paragraph_();
}
else
{
renderSummaryTable( contents );
}
sink.section2_();
}
protected void renderSummaryTable( Map<Property, PropertyVersions> contents )
{
sink.table();
sink.tableRow();
renderSummaryTableHeader( false, false );
sink.tableRow_();
contents.forEach( this::renderPropertySummaryTableRow );
sink.tableRow();
renderSummaryTableHeader( false, false );
sink.tableRow_();
sink.table_();
}
private void renderPropertySummaryTableRow( Property property, PropertyVersions details )
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
sink.tableRow();
sink.tableCell();
renderIcon( upToDate );
sink.tableCell_();
renderCells( "${" + property.getName() + "}", details.getCurrentVersion() );
renderNewestVersions( details );
sink.tableRow_();
}
protected void renderPropertyDetailTable( Property property, PropertyVersions details )
{
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
boolean upToDate = allUpdates == null || allUpdates.length == 0;
sink.table();
sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false );
renderTwoCellsRow( "report.status", () -> renderStatus( details ) );
renderTwoCellsRow( "report.property", "${" + property.getName() + "}" );
renderTwoCellsRow( "report.associations", () -> renderAssociations( details ) );
renderTwoCellsRow( "report.currentVersion", details.getCurrentVersion().toString() );
if ( !upToDate )
{
renderTwoCellsRow( "report.updateVersions", () -> renderVersions( allUpdates, details ) );
}
renderTwoCellsRow( "report.versionRange", details.getCurrentVersion().toString() );
renderTwoCellsRow( "report.autoLinkDependencies", property.isAutoLinkDependencies() );
renderTwoCellsRow( "report.banSnapshots", property.isBanSnapshots() );
renderTwoCellsRow( "report.searchReactor", property.isSearchReactor() );
renderTwoCellsRow( "report.preferReactor", property.isPreferReactor() );
sink.tableRows_();
sink.table_();
}
/**
* Renders a row of two cells, the first cell being an header and the second cell being a non-header cell.
* @param textKey the key of the text to be rendered in the header cell.
* @param b a yes/no value to be rendered in the non-header cell.
*/
private void renderTwoCellsRow( String textKey, boolean b )
{
renderTwoCellsRow( textKey, getText( b ? "report.yes" : "report.no" ) );
}
private void renderAssociations( PropertyVersions details )
{
ArtifactAssociation[] associations = details.getAssociations();
for ( int i = 0; i < associations.length; i++ )
{
if ( i > 0 )
{
sink.lineBreak();
}
sink.text( ArtifactUtils.versionlessKey( associations[i].getArtifact() ) );
}
}
@Override
protected void renderSummaryTableHeader( boolean hasScope, boolean hasType )
{
renderTableHeaderCells( "report.status", "report.property", "report.currentVersion",
"report.latestSubIncremental", "report.latestIncremental", "report.latestMinor",
"report.latestMajor" );
}
@Override
protected OverviewStats computeOverviewStats()
{
return OverviewStats.fromUpdates( model.getAllUpdates().values(), newestUpdateCache );
}
private void renderPropertyDetail( Property property, PropertyVersions details )
{
sink.section2();
sink.sectionTitle2();
sink.text( "${" + property.getName() + "}" );
sink.sectionTitle2_();
renderPropertyDetailTable( property, details );
sink.section2_();
}
}