Skip to content

Commit

Permalink
[MPIR-437] 'Java version' is set to 0.0 when no JDK details are detec…
Browse files Browse the repository at this point in the history
…ted in dependencies

This closes #51
  • Loading branch information
belingueres authored and michael-o committed May 14, 2023
1 parent f942ba1 commit 9209a7a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
71 changes: 71 additions & 0 deletions src/it/MPIR-437/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.project-info-reports</groupId>
<artifactId>MPIR-437</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Detect dependencies with no jdk details</name>
<description>
MPIR retrieves class version information from dependencies to display that Java detected,
but when no detected should display a dash.
</description>

<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-i18n-de</artifactId>
<version>9.0.74</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>@sitePluginVersion@</version>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>@project.version@</version>
<reportSets>
<reportSet>
<reports>
<report>dependencies</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
31 changes: 31 additions & 0 deletions src/it/MPIR-437/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/
File dependencies = new File( basedir, 'target/site/dependencies.html' )
def summaryRow = '''\
<tr class="b">
<td align="right">1</td>
<td align="right">78.8 kB</td>
<td align="right">141</td>
<td align="right">-</td>
<td align="right">-</td>
<td align="center">-</td>
<td align="right">-</td></tr>
'''

assert dependencies.text.contains( summaryRow.replaceAll( "\n", System.lineSeparator() ) )
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.FieldPosition;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -90,6 +91,9 @@ public class DependenciesRenderer extends AbstractProjectInfoRenderer {
/** Used to format file length values */
private final DecimalFormat fileLengthDecimalFormat;

private final MessageFormat javaVersionFormat =
new MessageFormat("{0,choice,0#|1.1<{0,number,0.0}|9#{0,number,0}}", Locale.ROOT);

/**
* @since 2.1.1
*/
Expand Down Expand Up @@ -611,7 +615,7 @@ private void renderSectionDependencyFileDetails() {
totalentries.getTotalString(i),
totalclasses.getTotalString(i),
totalpackages.getTotalString(i),
(i < 0) ? String.valueOf(highestJavaVersion) : "",
(i < 0) ? javaVersionFormat.format(new Object[] {highestJavaVersion}) : "",
totalDebugInformation.getTotalString(i),
totalsealed.getTotalString(i)
});
Expand Down

0 comments on commit 9209a7a

Please sign in to comment.