This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch MPIR-412 in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git
commit b85385b63d857c8b691a90f9a79b921046fd0f0d Author: Jukka Matilainen <[email protected]> AuthorDate: Sun Jan 30 15:48:09 2022 +0200 [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 --- src/it/MPIR-412/invoker.properties | 18 +++++++ src/it/MPIR-412/pom.xml | 55 ++++++++++++++++++++++ src/it/MPIR-412/verify.groovy | 24 ++++++++++ .../renderer/DependenciesRenderer.java | 19 +++++--- 4 files changed, 110 insertions(+), 6 deletions(-) diff --git a/src/it/MPIR-412/invoker.properties b/src/it/MPIR-412/invoker.properties new file mode 100644 index 0000000..e62a065 --- /dev/null +++ b/src/it/MPIR-412/invoker.properties @@ -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 diff --git a/src/it/MPIR-412/pom.xml b/src/it/MPIR-412/pom.xml new file mode 100644 index 0000000..251d5fe --- /dev/null +++ b/src/it/MPIR-412/pom.xml @@ -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> diff --git a/src/it/MPIR-412/verify.groovy b/src/it/MPIR-412/verify.groovy new file mode 100644 index 0000000..b1e5036 --- /dev/null +++ b/src/it/MPIR-412/verify.groovy @@ -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; diff --git a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java index b8fa96a..e44fdb7 100644 --- a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java +++ b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java @@ -889,8 +889,6 @@ public class DependenciesRenderer sink.rawText( "<div id=\"" + uid + "\" style=\"display:none\">" ); - sink.table(); - if ( !Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) { try @@ -902,6 +900,8 @@ public class DependenciesRenderer List<License> licenses = artifactProject.getLicenses(); + sink.table(); + sink.tableRow(); sink.tableHeaderCell(); sink.text( artifactName ); @@ -989,6 +989,11 @@ public class DependenciesRenderer licenseMap.put( unknownLicenseMessage, artifactName ); } sink.paragraph_(); + + sink.tableCell_(); + sink.tableRow_(); + + sink.table_(); } catch ( ProjectBuildingException e ) { @@ -1006,6 +1011,8 @@ public class DependenciesRenderer } else { + sink.table(); + sink.tableRow(); sink.tableHeaderCell(); sink.text( id ); @@ -1031,12 +1038,12 @@ public class DependenciesRenderer sink.text( artifact.getFile().getAbsolutePath() ); sink.paragraph_(); } - } - sink.tableCell_(); - sink.tableRow_(); + sink.tableCell_(); + sink.tableRow_(); - sink.table_(); + sink.table_(); + } sink.rawText( "</div>" ); }
