Skip to content

Commit

Permalink
[MPIR-431] Dependency file details section: segregate Java version
Browse files Browse the repository at this point in the history
column into execution and test versions
  • Loading branch information
belingueres committed May 20, 2023
1 parent 2d60f95 commit aedb2b6
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 33 deletions.
81 changes: 81 additions & 0 deletions src/it/MPIR-431/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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.its</groupId>
<artifactId>MPIR-431</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<url>http://maven.apache.org/plugins/it/${project.artifactId}</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<!-- an example of a dependency with a problematic POM -->
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis-ext</artifactId>
<version>1.3.04</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<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>
55 changes: 55 additions & 0 deletions src/it/MPIR-431/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.
*/
String html = new File( basedir, 'target/site/dependencies.html' ).text

def summaryLine = '''\
<tr class="b">
<td align="right">compile: 1</td>
<td align="right">compile: 45.5 kB</td>
<td align="right">compile: 47</td>
<td align="right">compile: 36</td>
<td align="right">compile: 4</td>
<td rowspan="3" style="vertical-align: middle" align="center">1.3</td>
<td align="right">compile: 1</td></tr>
<tr class="a">
<td align="right">runtime: 1</td>
<td align="right">runtime: 284.2 kB</td>
<td align="right">runtime: 155</td>
<td align="right">runtime: 133</td>
<td align="right">runtime: 10</td>
<td align="right">runtime: 1</td></tr>
<tr class="b">
<td align="right">provided: 1</td>
<td align="right">provided: 85.7 kB</td>
<td align="right">provided: 209</td>
<td align="right">provided: 192</td>
<td align="right">provided: 4</td>
<td align="right">-</td></tr>
<tr class="a">
<td align="right">test: 3</td>
<td align="right">test: 2.2 MB</td>
<td align="right">test: 1619</td>
<td align="right">test: 1493</td>
<td align="right">test: 91</td>
<td align="center">1.8</td>
<td align="right">test: 3</td></tr>
'''
summaryLine = summaryLine.stripTrailing()

assert html.contains( summaryLine.replaceAll( "\n", System.lineSeparator() ) )
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.report.projectinfo.dependencies.renderer;

import javax.swing.text.html.HTML.Attribute;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -70,6 +72,7 @@
* @since 2.1
*/
public class DependenciesRenderer extends AbstractProjectInfoRenderer {

/** URL for the 'icon_info_sml.gif' image */
private static final String IMG_INFO_URL = "./images/icon_info_sml.gif";

Expand All @@ -93,7 +96,6 @@ public class DependenciesRenderer extends AbstractProjectInfoRenderer {

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 @@ -503,7 +505,8 @@ private void renderSectionDependencyFileDetails() {
TotalCell totalentries = new TotalCell();
TotalCell totalclasses = new TotalCell();
TotalCell totalpackages = new TotalCell();
double highestJavaVersion = 0.0;
double highestTestJavaVersion = 0.0;
double highestNonTestJavaVersion = 0.0;
TotalCell totalDebugInformation = new TotalCell();
TotalCell totalsealed = new TotalCell();

Expand Down Expand Up @@ -551,8 +554,13 @@ private void renderSectionDependencyFileDetails() {

try {
if (jarDetails.getJdkRevision() != null) {
highestJavaVersion =
Math.max(highestJavaVersion, Double.parseDouble(jarDetails.getJdkRevision()));
double jdkRevision = Double.parseDouble(jarDetails.getJdkRevision());
boolean isTestScope = Artifact.SCOPE_TEST.equalsIgnoreCase(artifact.getScope());
if (isTestScope) {
highestTestJavaVersion = Math.max(highestTestJavaVersion, jdkRevision);
} else {
highestNonTestJavaVersion = Math.max(highestNonTestJavaVersion, jdkRevision);
}
}
} catch (NumberFormatException e) {
// ignore
Expand Down Expand Up @@ -588,14 +596,7 @@ private void renderSectionDependencyFileDetails() {
}
} else {
tableRow(hasSealed, new String[] {
artifactFile.getName(),
fileLengthDecimalFormat.format(artifactFile.length()),
"",
"",
"",
"",
"",
""
artifactFile.getName(), fileLengthDecimalFormat.format(artifactFile.length()), "", "", "", "", ""
});
}
}
Expand All @@ -607,25 +608,76 @@ private void renderSectionDependencyFileDetails() {
justification[0] = Sink.JUSTIFY_RIGHT;
justification[6] = Sink.JUSTIFY_RIGHT;

for (int i = -1; i < TotalCell.SCOPES_COUNT; i++) {
if (totaldeps.getTotal(i) > 0) {
tableRow(hasSealed, new String[] {
totaldeps.getTotalString(i),
totaldepsize.getTotalString(i),
totalentries.getTotalString(i),
totalclasses.getTotalString(i),
totalpackages.getTotalString(i),
(i < 0) ? javaVersionFormat.format(new Object[] {highestJavaVersion}) : "",
totalDebugInformation.getTotalString(i),
totalsealed.getTotalString(i)
});
// calculate rowspan attr
int rowspan = computeRowspan(totaldeps);

if (rowspan > 1) {
boolean insertRowspanAttr = false;
int column = 5; // Java Version's column
for (int i = -1; i < TotalCell.SCOPES_COUNT; i++) {
if (totaldeps.getTotal(i) > 0) {
boolean alreadyInsertedRowspanAttr = insertRowspanAttr && (0 < i && i < 4);
insertRowspanAttr = (0 <= i && i < 4);
justification[column] = (insertRowspanAttr && alreadyInsertedRowspanAttr)
? justification[column + 1]
: Sink.JUSTIFY_CENTER;
tableRowWithRowspan(
hasSealed, insertRowspanAttr, alreadyInsertedRowspanAttr, column, rowspan, new String[] {
totaldeps.getTotalString(i),
totaldepsize.getTotalString(i),
totalentries.getTotalString(i),
totalclasses.getTotalString(i),
totalpackages.getTotalString(i),
formatMaxVersionForScope(i, highestTestJavaVersion, highestNonTestJavaVersion),
totalDebugInformation.getTotalString(i),
totalsealed.getTotalString(i)
});
}
}
} else {
for (int i = -1; i < TotalCell.SCOPES_COUNT; i++) {
if (totaldeps.getTotal(i) > 0) {
tableRow(hasSealed, new String[] {
totaldeps.getTotalString(i),
totaldepsize.getTotalString(i),
totalentries.getTotalString(i),
totalclasses.getTotalString(i),
totalpackages.getTotalString(i),
formatMaxVersionForScope(i, highestTestJavaVersion, highestNonTestJavaVersion),
totalDebugInformation.getTotalString(i),
totalsealed.getTotalString(i)
});
}
}
}

endTable();
endSection();
}

private int computeRowspan(TotalCell totaldeps) {
int rowspan = 0;
for (int i = 0; i < TotalCell.SCOPES_COUNT - 1; i++) {
if (totaldeps.getTotal(i) > 0) {
rowspan++;
}
}
return rowspan;
}

private String formatMaxVersionForScope(
int index, double highestTestJavaVersion, double highestNonTestJavaVersion) {
if (index < 0) {
double highestJavaVersion = Math.max(highestTestJavaVersion, highestNonTestJavaVersion);
return javaVersionFormat.format(new Object[] {highestJavaVersion});
} else if (0 <= index && index <= 3) {
return javaVersionFormat.format(new Object[] {highestNonTestJavaVersion});
} else if (index == 4) {
return javaVersionFormat.format(new Object[] {highestTestJavaVersion});
}
return "";
}

// Almost as same as in the abstract class but includes the title attribute
private void tableHeader(String[] content, String[] titles) {
sink.tableRow();
Expand Down Expand Up @@ -659,6 +711,30 @@ private void tableHeaderCell(String text, String title) {
sink.tableHeaderCell_();
}

private void tableRowWithRowspan(
boolean fullRow, boolean insert, boolean alreadyInserted, int contentIndex, int rowspan, String[] content) {
sink.tableRow();

int count = fullRow ? content.length : (content.length - 1);

for (int i = 0; i < count; i++) {
if (i == contentIndex && insert) {
if (!alreadyInserted) {
SinkEventAttributes att = new SinkEventAttributeSet();
att.addAttribute(Attribute.ROWSPAN, rowspan);
att.addAttribute(Attribute.STYLE, "vertical-align: middle");
sink.tableCell(att);
text(content[i]);
sink.tableCell_();
}
} else {
tableCell(content[i]);
}
}

sink.tableRow_();
}

private void tableRow(boolean fullRow, String[] content) {
sink.tableRow();

Expand All @@ -674,7 +750,7 @@ private void tableRow(boolean fullRow, String[] content) {
private void createExceptionInfoTableRow(Artifact artifact, File artifactFile, Exception e, boolean hasSealed) {
tableRow(
hasSealed,
new String[] {artifact.getId(), artifactFile.getAbsolutePath(), e.getMessage(), "", "", "", "", ""});
new String[] {artifact.getId(), artifactFile.getAbsolutePath(), e.getMessage(), "", "", "", ""});
}

private void renderSectionDependencyLicenseListing() {
Expand Down Expand Up @@ -1169,13 +1245,13 @@ static String getScope(int index) {
case 0:
return Artifact.SCOPE_COMPILE;
case 1:
return Artifact.SCOPE_TEST;
case 2:
return Artifact.SCOPE_RUNTIME;
case 3:
case 2:
return Artifact.SCOPE_PROVIDED;
case 4:
case 3:
return Artifact.SCOPE_SYSTEM;
case 4:
return Artifact.SCOPE_TEST;
default:
return null;
}
Expand All @@ -1186,13 +1262,13 @@ long getTotal(int index) {
case 0:
return totalCompileScope;
case 1:
return totalTestScope;
case 2:
return totalRuntimeScope;
case 3:
case 2:
return totalProvidedScope;
case 4:
case 3:
return totalSystemScope;
case 4:
return totalTestScope;
default:
return total;
}
Expand Down

0 comments on commit aedb2b6

Please sign in to comment.