Skip to content

Commit d85aec3

Browse files
jkmatilamichael-o
authored andcommitted
[MPIR-412] Dependency report generates non-well-formed output if the POM of a depdendency cannot be parsed
Make sure that open and close tags in the dependency report are kept balanced even if there is a ProjectBuildingException when the details of the dependency are being loaded. The integration test verifies that in the presence of a dependency with an erroneous POM, the generated dependencies report can be parsed as XML. This closes #31
1 parent 3c155a8 commit d85aec3

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

src/it/MPIR-412/invoker.properties

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependencies

src/it/MPIR-412/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.its</groupId>
27+
<artifactId>MPIR-412</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<packaging>pom</packaging>
30+
<url>http://maven.apache.org/plugins/it/${project.artifactId}</url>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
35+
</properties>
36+
37+
<dependencies>
38+
<!-- an example of a dependency with a problematic POM -->
39+
<dependency>
40+
<groupId>xml-apis</groupId>
41+
<artifactId>xml-apis-ext</artifactId>
42+
<version>1.3.04</version>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<artifactId>maven-project-info-reports-plugin</artifactId>
50+
<version>@pom.version@</version>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
55+
</project>

src/it/MPIR-412/verify.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
20+
// should be able to parse the output as XML
21+
parser = new XmlParser();
22+
parser.setFeature( 'http://apache.org/xml/features/disallow-doctype-decl', false );
23+
result = parser.parse( new File( basedir, 'target/site/dependencies.html' ) );
24+
assert result instanceof Node;

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,6 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
889889

890890
sink.rawText( "<div id=\"" + uid + "\" style=\"display:none\">" );
891891

892-
sink.table();
893-
894892
if ( !Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
895893
{
896894
try
@@ -902,6 +900,8 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
902900

903901
List<License> licenses = artifactProject.getLicenses();
904902

903+
sink.table();
904+
905905
sink.tableRow();
906906
sink.tableHeaderCell();
907907
sink.text( artifactName );
@@ -989,6 +989,11 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
989989
licenseMap.put( unknownLicenseMessage, artifactName );
990990
}
991991
sink.paragraph_();
992+
993+
sink.tableCell_();
994+
sink.tableRow_();
995+
996+
sink.table_();
992997
}
993998
catch ( ProjectBuildingException e )
994999
{
@@ -1006,6 +1011,8 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
10061011
}
10071012
else
10081013
{
1014+
sink.table();
1015+
10091016
sink.tableRow();
10101017
sink.tableHeaderCell();
10111018
sink.text( id );
@@ -1031,12 +1038,12 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
10311038
sink.text( artifact.getFile().getAbsolutePath() );
10321039
sink.paragraph_();
10331040
}
1034-
}
10351041

1036-
sink.tableCell_();
1037-
sink.tableRow_();
1042+
sink.tableCell_();
1043+
sink.tableRow_();
10381044

1039-
sink.table_();
1045+
sink.table_();
1046+
}
10401047

10411048
sink.rawText( "</div>" );
10421049
}

0 commit comments

Comments
 (0)