Skip to content

Commit

Permalink
[MPIR-412] Dependency report generates non-well-formed output if the …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jkmatila authored and michael-o committed Jan 30, 2022
1 parent 3c155a8 commit d85aec3
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/it/MPIR-412/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependencies
55 changes: 55 additions & 0 deletions src/it/MPIR-412/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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-412</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>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>@pom.version@</version>
</plugin>
</plugins>
</build>

</project>
24 changes: 24 additions & 0 deletions src/it/MPIR-412/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

// should be able to parse the output as XML
parser = new XmlParser();
parser.setFeature( 'http://apache.org/xml/features/disallow-doctype-decl', false );
result = parser.parse( new File( basedir, 'target/site/dependencies.html' ) );
assert result instanceof Node;
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,6 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )

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

sink.table();

if ( !Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
{
try
Expand All @@ -902,6 +900,8 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )

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

sink.table();

sink.tableRow();
sink.tableHeaderCell();
sink.text( artifactName );
Expand Down Expand Up @@ -989,6 +989,11 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
licenseMap.put( unknownLicenseMessage, artifactName );
}
sink.paragraph_();

sink.tableCell_();
sink.tableRow_();

sink.table_();
}
catch ( ProjectBuildingException e )
{
Expand All @@ -1006,6 +1011,8 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
}
else
{
sink.table();

sink.tableRow();
sink.tableHeaderCell();
sink.text( id );
Expand All @@ -1031,12 +1038,12 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
sink.text( artifact.getFile().getAbsolutePath() );
sink.paragraph_();
}
}

sink.tableCell_();
sink.tableRow_();
sink.tableCell_();
sink.tableRow_();

sink.table_();
sink.table_();
}

sink.rawText( "</div>" );
}
Expand Down

0 comments on commit d85aec3

Please sign in to comment.