Skip to content

Commit 82227a0

Browse files
committed
Fix Reports Success/Warning icons, counts
1 parent 954a853 commit 82227a0

16 files changed

+187
-256
lines changed

src/it/it-dependency-updates-report-001/verify.bsh

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ try
2323
System.out.println( "Result = \"" + result +"\"" );
2424
return false;
2525
}
26-
if ( result.indexOf( "1.1.1 Next Incremental" ) < 0)
26+
if ( result.indexOf( "1.1.1" ) < 0)
2727
{
2828
System.out.println( "Did not identify next incremental" );
2929
System.out.println( "Result = \"" + result +"\"" );
@@ -35,7 +35,7 @@ try
3535
System.out.println( "Result = \"" + result +"\"" );
3636
return false;
3737
}
38-
if ( result.indexOf( "1.2 Next Minor" ) < 0)
38+
if ( result.indexOf( "1.2" ) < 0)
3939
{
4040
System.out.println( "Did not identify next minor version" );
4141
System.out.println( "Result = \"" + result +"\"" );
@@ -47,7 +47,7 @@ try
4747
System.out.println( "Result = \"" + result +"\"" );
4848
return false;
4949
}
50-
if ( result.indexOf( "2.0 Next Major" ) < 0)
50+
if ( result.indexOf( "2.0" ) < 0)
5151
{
5252
System.out.println( "Did not identify next major version" );
5353
System.out.println( "Result = \"" + result +"\"" );

src/it/it-dependency-updates-report-002/verify.bsh

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ try
1717
// System.out.println( "Result = \"" + result +"\"" );
1818
// return false;
1919
// }
20-
// if ( result.indexOf( "1.1.0-2 Next Version" ) < 0)
20+
// if ( result.indexOf( "1.1.0-2" ) < 0)
2121
// {
2222
// System.out.println( "Did not identify next version" );
2323
// System.out.println( "Result = \"" + result +"\"" );
2424
// return false;
2525
// }
26-
// if ( result.indexOf( "1.1.1 Next Incremental" ) < 0)
26+
// if ( result.indexOf( "1.1.1" ) < 0)
2727
// {
2828
// System.out.println( "Did not identify next incremental" );
2929
// System.out.println( "Result = \"" + result +"\"" );
@@ -35,7 +35,7 @@ try
3535
// System.out.println( "Result = \"" + result +"\"" );
3636
// return false;
3737
// }
38-
// if ( result.indexOf( "1.2 Next Minor" ) < 0)
38+
// if ( result.indexOf( "1.2" ) < 0)
3939
// {
4040
// System.out.println( "Did not identify next minor version" );
4141
// System.out.println( "Result = \"" + result +"\"" );
@@ -47,7 +47,7 @@ try
4747
// System.out.println( "Result = \"" + result +"\"" );
4848
// return false;
4949
// }
50-
// if ( result.indexOf( "2.0 Next Major" ) < 0)
50+
// if ( result.indexOf( "2.0" ) < 0)
5151
// {
5252
// System.out.println( "Did not identify next major version" );
5353
// System.out.println( "Result = \"" + result +"\"" );

src/it/it-plugin-updates-report-001/verify.bsh

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ try
3232
return false;
3333
}
3434
if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 "
35-
+ "Next Major 2.1 3.0 3.1 Latest Major" ) < 0)
35+
+ "2.1 3.0 3.1 Latest Major" ) < 0)
3636
{
3737
System.out.println( "Did not identify plugin next versions" );
3838
System.out.println( "Result = \"" + result +"\"" );
3939
return false;
4040
}
4141
if ( result.indexOf( "Group Id localhost Artifact Id dummy-api Current Version 1.1 Classifier Type jar Newer "
42-
+ "versions 1.1.0-2 Latest Subincremental 1.1.1 Next Incremental 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 Next "
43-
+ "Minor 1.2.1 1.2.2 1.3 Latest Minor 2.0 Next Major 2.1 3.0 Latest Major" ) < 0)
42+
+ "versions 1.1.0-2 Latest Subincremental 1.1.1 1.1.1-2 1.1.2 1.1.3 Latest Incremental 1.2 "
43+
+ "1.2.1 1.2.2 1.3 Latest Minor 2.0 2.1 3.0 Latest Major" ) < 0)
4444
{
4545
System.out.println( "Did not identify dependency next versions" );
4646
System.out.println( "Result = \"" + result +"\"" );

src/it/it-plugin-updates-report-002/verify.bsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try
2626
return false;
2727
}
2828
if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 "
29-
+ "Next Major 2.1 3.0 3.1 Latest Major" ) < 0)
29+
+ "2.1 3.0 3.1 Latest Major" ) < 0)
3030
{
3131
System.out.println( "Did not identify plugin next versions" );
3232
System.out.println( "Result = \"" + result +"\"" );

src/it/it-plugin-updates-report-003/verify.bsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ try
2626
return false;
2727
}
2828
if ( result.indexOf( "Group Id localhost Artifact Id dummy-maven-plugin Current Version 1.0 Newer versions 2.0 "
29-
+ "Next Major 2.1 3.0 3.1 Latest Major" ) < 0)
29+
+ "2.1 3.0 3.1 Latest Major" ) < 0)
3030
{
3131
System.out.println( "Did not identify plugin next versions" );
3232
System.out.println( "Result = \"" + result +"\"" );

src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.commons.lang3.tuple.Pair;
2929

3030
/**
31-
* Utility providing a cached {@link ArtifactVersions#getOldestUpdate(Optional)} API
31+
* Utility providing a cached {@link ArtifactVersions#getNewestUpdate(Optional)} API
3232
*/
3333
public class ArtifactVersionsCache
3434
{

src/main/java/org/codehaus/mojo/versions/ordering/AbstractVersionComparator.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,8 @@ public final int getSegmentCount( ArtifactVersion v )
5959
*/
6060
public final ArtifactVersion incrementSegment( ArtifactVersion v, Segment segment ) throws InvalidSegmentException
6161
{
62-
if ( VersionComparators.isSnapshot( v ) )
63-
{
64-
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
65-
segment ) );
66-
}
67-
int segmentCount = getSegmentCount( v );
68-
if ( segment.value() >= segmentCount )
69-
{
70-
throw new InvalidSegmentException( segment, segmentCount, v );
71-
}
72-
return innerIncrementSegment( v, segment );
62+
return VersionComparators.copySnapshot( v, innerIncrementSegment( VersionComparators.stripSnapshot( v ),
63+
segment ) );
7364
}
7465

7566
protected abstract ArtifactVersion innerIncrementSegment( ArtifactVersion v, Segment segment )

src/main/java/org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java

+59-78
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public abstract class AbstractVersionsReportRenderer<T> extends VersionsReportRe
5858
*/
5959
protected T model;
6060

61-
protected ArtifactVersionsCache oldestUpdateCache
62-
= new ArtifactVersionsCache( AbstractVersionDetails::getOldestUpdate );
61+
protected ArtifactVersionsCache newestUpdateCache
62+
= new ArtifactVersionsCache( AbstractVersionDetails::getNewestUpdate );
6363

6464
protected ArtifactVersionsCache allUpdatesCache
6565
= new ArtifactVersionsCache( AbstractVersionDetails::getAllUpdates );
@@ -136,59 +136,11 @@ protected void renderOverview()
136136
*/
137137
protected <Q extends OverviewStats> void renderOverviewTableRow( Q stats )
138138
{
139-
sink.tableCell();
140-
renderSuccessIcon();
141-
sink.tableCell_();
142-
sink.tableCell();
143-
sink.text( getText( "report.overview.numUpToDate" ) );
144-
sink.tableCell_();
145-
sink.tableCell();
146-
sink.text( Integer.toString( stats.getUpToDate() ) );
147-
sink.tableCell_();
148-
sink.tableRow_();
149-
sink.tableRow();
150-
sink.tableCell();
151-
renderWarningIcon();
152-
sink.tableCell_();
153-
sink.tableCell();
154-
sink.text( getText( "report.overview.numNewerVersionAvailable" ) );
155-
sink.tableCell_();
156-
sink.tableCell();
157-
sink.text( Integer.toString( stats.getAny() ) );
158-
sink.tableCell_();
159-
sink.tableRow_();
160-
sink.tableRow();
161-
sink.tableCell();
162-
renderWarningIcon();
163-
sink.tableCell_();
164-
sink.tableCell();
165-
sink.text( getText( "report.overview.numNewerIncrementalAvailable" ) );
166-
sink.tableCell_();
167-
sink.tableCell();
168-
sink.text( Integer.toString( stats.getIncremental() ) );
169-
sink.tableCell_();
170-
sink.tableRow_();
171-
sink.tableRow();
172-
sink.tableCell();
173-
renderWarningIcon();
174-
sink.tableCell_();
175-
sink.tableCell();
176-
sink.text( getText( "report.overview.numNewerMinorAvailable" ) );
177-
sink.tableCell_();
178-
sink.tableCell();
179-
sink.text( Integer.toString( stats.getMinor() ) );
180-
sink.tableCell_();
181-
sink.tableRow_();
182-
sink.tableRow();
183-
sink.tableCell();
184-
renderWarningIcon();
185-
sink.tableCell_();
186-
sink.tableCell();
187-
sink.text( getText( "report.overview.numNewerMajorAvailable" ) );
188-
sink.tableCell_();
189-
sink.tableCell();
190-
sink.text( Integer.toString( stats.getMajor() ) );
191-
sink.tableCell_();
139+
renderStatRow( "report.overview.numUpToDate", stats.getUpToDate() );
140+
renderStatRow( "report.overview.numNewerVersionAvailable", stats.getAny() );
141+
renderStatRow( "report.overview.numNewerIncrementalAvailable", stats.getIncremental() );
142+
renderStatRow( "report.overview.numNewerMinorAvailable", stats.getMinor() );
143+
renderStatRow( "report.overview.numNewerMajorAvailable", stats.getMajor() );
192144
}
193145

194146
/**
@@ -237,13 +189,15 @@ protected void renderSummaryTableHeader( boolean hasScope, boolean hasType )
237189
"report.latestIncremental", "report.latestMinor", "report.latestMajor" );
238190
}
239191

240-
protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions artifactVersions,
241-
boolean includeScope )
192+
protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions details,
193+
boolean includeScope )
242194
{
195+
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
196+
boolean upToDate = allUpdates == null || allUpdates.length == 0;
197+
243198
sink.tableRow();
244199
sink.tableCell();
245-
ArtifactVersion[] allUpdates = artifactVersions.getAllUpdates( empty() );
246-
if ( allUpdates == null || allUpdates.length == 0 )
200+
if ( upToDate )
247201
{
248202
renderSuccessIcon();
249203
}
@@ -275,37 +229,37 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions arti
275229
sink.tableCell_();
276230

277231
sink.tableCell();
278-
if ( artifactVersions.getNewestUpdate( of( SUBINCREMENTAL ) ) != null )
232+
if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
279233
{
280234
safeBold();
281-
sink.text( artifactVersions.getNewestUpdate( of( SUBINCREMENTAL ) ).toString() );
235+
sink.text( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ).toString() );
282236
safeBold_();
283237
}
284238
sink.tableCell_();
285239

286240
sink.tableCell();
287-
if ( artifactVersions.getNewestUpdate( of( INCREMENTAL ) ) != null )
241+
if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
288242
{
289243
safeBold();
290-
sink.text( artifactVersions.getNewestUpdate( of( INCREMENTAL ) ).toString() );
244+
sink.text( newestUpdateCache.get( details, of( INCREMENTAL ) ).toString() );
291245
safeBold_();
292246
}
293247
sink.tableCell_();
294248

295249
sink.tableCell();
296-
if ( artifactVersions.getNewestUpdate( of( MINOR ) ) != null )
250+
if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
297251
{
298252
safeBold();
299-
sink.text( artifactVersions.getNewestUpdate( of( MINOR ) ).toString() );
253+
sink.text( newestUpdateCache.get( details, of( MINOR ) ).toString() );
300254
safeBold_();
301255
}
302256
sink.tableCell_();
303257

304258
sink.tableCell();
305-
if ( artifactVersions.getNewestUpdate( of( MAJOR ) ) != null )
259+
if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
306260
{
307261
safeBold();
308-
sink.text( artifactVersions.getNewestUpdate( of( MAJOR ) ).toString() );
262+
sink.text( newestUpdateCache.get( details, of( MAJOR ) ).toString() );
309263
safeBold_();
310264
}
311265
sink.tableCell_();
@@ -316,37 +270,39 @@ protected void renderSummaryTableRow( Dependency artifact, ArtifactVersions arti
316270
@SuppressWarnings( "checkstyle:MethodLength" )
317271
protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope )
318272
{
273+
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
274+
boolean upToDate = allUpdates == null || allUpdates.length == 0;
275+
319276
final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
320-
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "20%" );
277+
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" );
321278
final SinkEventAttributes cellAttributes = new SinkEventAttributeSet();
322-
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "80%" );
279+
headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" );
323280
sink.table();
324281
sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false );
325282
sink.tableRow();
326283
sink.tableHeaderCell( headerAttributes );
327284
sink.text( getText( "report.status" ) );
328285
sink.tableHeaderCell_();
329286
sink.tableCell( cellAttributes );
330-
ArtifactVersion[] versions = allUpdatesCache.get( details, empty() );
331-
if ( oldestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
287+
if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
332288
{
333289
renderWarningIcon();
334290
sink.nonBreakingSpace();
335291
sink.text( getText( "report.otherUpdatesAvailable" ) );
336292
}
337-
else if ( oldestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
293+
else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
338294
{
339295
renderWarningIcon();
340296
sink.nonBreakingSpace();
341297
sink.text( getText( "report.incrementalUpdatesAvailable" ) );
342298
}
343-
else if ( oldestUpdateCache.get( details, of( MINOR ) ) != null )
299+
else if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
344300
{
345301
renderWarningIcon();
346302
sink.nonBreakingSpace();
347303
sink.text( getText( "report.minorUpdatesAvailable" ) );
348304
}
349-
else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null )
305+
else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
350306
{
351307
renderWarningIcon();
352308
sink.nonBreakingSpace();
@@ -411,25 +367,25 @@ else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null )
411367
sink.text( artifact.getType() );
412368
sink.tableCell_();
413369
sink.tableRow_();
414-
if ( versions != null && versions.length > 0 )
370+
if ( !upToDate )
415371
{
416372
sink.tableRow();
417373
sink.tableHeaderCell( headerAttributes );
418374
sink.text( getText( "report.updateVersions" ) );
419375
sink.tableHeaderCell_();
420376
sink.tableCell( cellAttributes );
421-
for ( int i = 0; i < versions.length; i++ )
377+
for ( int i = 0; i < allUpdates.length; i++ )
422378
{
423379
if ( i > 0 )
424380
{
425381
sink.lineBreak();
426382
}
427-
String label = getLabel( versions[i], details );
383+
String label = getLabel( allUpdates[i], details );
428384
if ( label != null )
429385
{
430386
safeBold();
431387
}
432-
sink.text( versions[i].toString() );
388+
sink.text( allUpdates[i].toString() );
433389
if ( label != null )
434390
{
435391
safeBold_();
@@ -462,4 +418,29 @@ protected void renderTableHeaderCells( String... keys )
462418
sink.tableHeaderCell_();
463419
} );
464420
}
421+
422+
protected String getLabel( ArtifactVersion version, AbstractVersionDetails details )
423+
{
424+
if ( equals( version, newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) ) )
425+
{
426+
return getText( "report.latestSubIncremental" );
427+
}
428+
429+
if ( equals( version, newestUpdateCache.get( details, of( INCREMENTAL ) ) ) )
430+
{
431+
return getText( "report.latestIncremental" );
432+
}
433+
434+
if ( equals( version, newestUpdateCache.get( details, of( MINOR ) ) ) )
435+
{
436+
return getText( "report.latestMinor" );
437+
}
438+
439+
if ( equals( version, newestUpdateCache.get( details, of( MAJOR ) ) ) )
440+
{
441+
return getText( "report.latestMajor" );
442+
}
443+
444+
return null;
445+
}
465446
}

src/main/java/org/codehaus/mojo/versions/reporting/DependencyUpdatesReportRenderer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ protected OverviewStats computeOverviewStats()
9595
OverviewStats stats = new OverviewStats();
9696
model.getAllUpdates().values().forEach( details ->
9797
{
98-
if ( oldestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
98+
if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
9999
{
100100
stats.incrementAny();
101101
}
102-
else if ( oldestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
102+
else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
103103
{
104104
stats.incrementIncremental();
105105
}
106-
else if ( oldestUpdateCache.get( details, of( MINOR ) ) != null )
106+
else if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
107107
{
108108
stats.incrementMinor();
109109
}
110-
else if ( oldestUpdateCache.get( details, of( MAJOR ) ) != null )
110+
else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
111111
{
112112
stats.incrementMajor();
113113
}

0 commit comments

Comments
 (0)