This is an automated email from the ASF dual-hosted git repository. sjaranowski pushed a commit to branch MINVOKER-351 in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
commit ac940df5c7441cf36f9d70c539aadd8fac558261 Author: Slawomir Jaranowski <s.jaranow...@gmail.com> AuthorDate: Thu May 16 22:18:43 2024 +0200 [MINVOKER-351] Escape special xml character in junit report - use StringEscapeUtils.escapeXml10 form commons-text --- pom.xml | 15 ++++ src/it/minvoker-351/invoker.properties | 18 +++++ src/it/minvoker-351/pom.xml | 83 ++++++++++++++++++++++ src/it/minvoker-351/src/it/minvoker-351/pom.xml | 42 +++++++++++ .../src/main/java/example/minvoker351/Example.java | 27 +++++++ .../test/java/example/minvoker351/ExampleTest.java | 28 ++++++++ src/it/minvoker-351/verify.groovy | 23 ++++++ .../maven/plugins/invoker/AbstractInvokerMojo.java | 6 +- 8 files changed, 240 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cc87562..d206363 100644 --- a/pom.xml +++ b/pom.xml @@ -145,6 +145,11 @@ under the License. <version>${mavenVersion}</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.maven.resolver</groupId> + <artifactId>maven-resolver-api</artifactId> + <version>1.4.1</version> + </dependency> <dependency> <groupId>org.apache.maven.resolver</groupId> <artifactId>maven-resolver-util</artifactId> @@ -205,6 +210,16 @@ under the License. <artifactId>maven-script-interpreter</artifactId> <version>1.6</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-text</artifactId> + <version>1.12.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.36</version> + </dependency> <dependency> <groupId>${beanshell-groupId}</groupId> diff --git a/src/it/minvoker-351/invoker.properties b/src/it/minvoker-351/invoker.properties new file mode 100644 index 0000000..c81e25f --- /dev/null +++ b/src/it/minvoker-351/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 = initialize site diff --git a/src/it/minvoker-351/pom.xml b/src/it/minvoker-351/pom.xml new file mode 100644 index 0000000..7f53bee --- /dev/null +++ b/src/it/minvoker-351/pom.xml @@ -0,0 +1,83 @@ +<?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>example.minvoker351</groupId> + <artifactId>minvoker-351</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + <writeJunitReport>true</writeJunitReport> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <phase>initialize</phase> + <goals> + <goal>install</goal> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <!-- Run "mvn site" to see failure due to invalid XML characters --> + <reporting> + <excludeDefaults>true</excludeDefaults> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-report-plugin</artifactId> + <version>@version.maven-surefire@</version> + <configuration> + <reportsDirectories> + <reportsDirectory>${project.build.directory}/invoker-reports-test</reportsDirectory> + </reportsDirectories> + </configuration> + <reportSets> + <reportSet> + <reports> + <report>report-only</report> + </reports> + </reportSet> + </reportSets> + </plugin> + </plugins> + </reporting> +</project> diff --git a/src/it/minvoker-351/src/it/minvoker-351/pom.xml b/src/it/minvoker-351/src/it/minvoker-351/pom.xml new file mode 100644 index 0000000..ab1129e --- /dev/null +++ b/src/it/minvoker-351/src/it/minvoker-351/pom.xml @@ -0,0 +1,42 @@ +<?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>example.minvoker351</groupId> + <artifactId>minvoker-351</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.10.2</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/src/it/minvoker-351/src/it/minvoker-351/src/main/java/example/minvoker351/Example.java b/src/it/minvoker-351/src/it/minvoker-351/src/main/java/example/minvoker351/Example.java new file mode 100644 index 0000000..164f023 --- /dev/null +++ b/src/it/minvoker-351/src/it/minvoker-351/src/main/java/example/minvoker351/Example.java @@ -0,0 +1,27 @@ +/* + * 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. + */ +package example.minvoker351; + +public class Example { + public void printAscii() { + for (int i = 0; i < Byte.MAX_VALUE; ++i) { + System.out.println((char) i); + } + } +} diff --git a/src/it/minvoker-351/src/it/minvoker-351/src/test/java/example/minvoker351/ExampleTest.java b/src/it/minvoker-351/src/it/minvoker-351/src/test/java/example/minvoker351/ExampleTest.java new file mode 100644 index 0000000..fec489d --- /dev/null +++ b/src/it/minvoker-351/src/it/minvoker-351/src/test/java/example/minvoker351/ExampleTest.java @@ -0,0 +1,28 @@ +/* + * 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. + */ +package example.minvoker351; + +import org.junit.jupiter.api.Test; + +public class ExampleTest { + @Test + public void f() { + new Example().printAscii(); + } +} diff --git a/src/it/minvoker-351/verify.groovy b/src/it/minvoker-351/verify.groovy new file mode 100644 index 0000000..c1dbdfd --- /dev/null +++ b/src/it/minvoker-351/verify.groovy @@ -0,0 +1,23 @@ +/* + * 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. + */ + +def surefireReport = new File(basedir, 'target/site/surefire-report.html').text + +assert surefireReport.contains('maven.invoker.it.minvoker-351') + diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 5644fe2..12eae7c 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -50,6 +50,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import org.apache.commons.text.StringEscapeUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; @@ -98,6 +99,7 @@ import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; +import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.XmlStreamWriter; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -1779,7 +1781,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { if (buildLogFile != null && buildLogFile.exists()) { getLog().debug("fileLogger:" + buildLogFile); try { - systemOut.setValue(FileUtils.fileRead(buildLogFile)); + systemOut.setValue(StringEscapeUtils.escapeXml10(FileUtils.fileRead(buildLogFile))); } catch (IOException e) { throw new MojoExecutionException("Failed to read logfile " + buildLogFile, e); } @@ -1789,7 +1791,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo { try (FileOutputStream fos = new FileOutputStream(reportFile); Writer osw = new OutputStreamWriter(fos, buildJob.getModelEncoding())) { - Xpp3DomWriter.write(osw, testsuite); + Xpp3DomWriter.write(new PrettyPrintXMLWriter(osw), testsuite, false); } catch (IOException e) { throw new MojoExecutionException("Failed to write JUnit build report " + reportFile, e); }