Skip to content

Commit 9209a7a

Browse files
belingueresmichael-o
authored andcommitted
[MPIR-437] 'Java version' is set to 0.0 when no JDK details are detected in dependencies
This closes #51
1 parent f942ba1 commit 9209a7a

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

src/it/MPIR-437/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.project-info-reports</groupId>
27+
<artifactId>MPIR-437</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<packaging>jar</packaging>
30+
31+
<name>Detect dependencies with no jdk details</name>
32+
<description>
33+
MPIR retrieves class version information from dependencies to display that Java detected,
34+
but when no detected should display a dash.
35+
</description>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.apache.tomcat</groupId>
40+
<artifactId>tomcat-i18n-de</artifactId>
41+
<version>9.0.74</version>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-site-plugin</artifactId>
50+
<version>@sitePluginVersion@</version>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
55+
<reporting>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-project-info-reports-plugin</artifactId>
60+
<version>@project.version@</version>
61+
<reportSets>
62+
<reportSet>
63+
<reports>
64+
<report>dependencies</report>
65+
</reports>
66+
</reportSet>
67+
</reportSets>
68+
</plugin>
69+
</plugins>
70+
</reporting>
71+
</project>

src/it/MPIR-437/verify.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
File dependencies = new File( basedir, 'target/site/dependencies.html' )
20+
def summaryRow = '''\
21+
<tr class="b">
22+
<td align="right">1</td>
23+
<td align="right">78.8 kB</td>
24+
<td align="right">141</td>
25+
<td align="right">-</td>
26+
<td align="right">-</td>
27+
<td align="center">-</td>
28+
<td align="right">-</td></tr>
29+
'''
30+
31+
assert dependencies.text.contains( summaryRow.replaceAll( "\n", System.lineSeparator() ) )

src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.text.DecimalFormat;
2626
import java.text.DecimalFormatSymbols;
2727
import java.text.FieldPosition;
28+
import java.text.MessageFormat;
2829
import java.util.ArrayList;
2930
import java.util.Collections;
3031
import java.util.Comparator;
@@ -90,6 +91,9 @@ public class DependenciesRenderer extends AbstractProjectInfoRenderer {
9091
/** Used to format file length values */
9192
private final DecimalFormat fileLengthDecimalFormat;
9293

94+
private final MessageFormat javaVersionFormat =
95+
new MessageFormat("{0,choice,0#|1.1<{0,number,0.0}|9#{0,number,0}}", Locale.ROOT);
96+
9397
/**
9498
* @since 2.1.1
9599
*/
@@ -611,7 +615,7 @@ private void renderSectionDependencyFileDetails() {
611615
totalentries.getTotalString(i),
612616
totalclasses.getTotalString(i),
613617
totalpackages.getTotalString(i),
614-
(i < 0) ? String.valueOf(highestJavaVersion) : "",
618+
(i < 0) ? javaVersionFormat.format(new Object[] {highestJavaVersion}) : "",
615619
totalDebugInformation.getTotalString(i),
616620
totalsealed.getTotalString(i)
617621
});

0 commit comments

Comments
 (0)