Skip to content

Commit 1ca02fb

Browse files
[MINVOKER-351] Escape special xml character in junit report
- use StringEscapeUtils.escapeXml10 form commons-text
1 parent 0e572a9 commit 1ca02fb

File tree

8 files changed

+248
-3
lines changed

8 files changed

+248
-3
lines changed

pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ under the License.
145145
<version>${mavenVersion}</version>
146146
<scope>provided</scope>
147147
</dependency>
148+
<dependency>
149+
<groupId>org.apache.maven.resolver</groupId>
150+
<artifactId>maven-resolver-api</artifactId>
151+
<version>1.4.1</version>
152+
</dependency>
148153
<dependency>
149154
<groupId>org.apache.maven.resolver</groupId>
150155
<artifactId>maven-resolver-util</artifactId>
@@ -205,6 +210,16 @@ under the License.
205210
<artifactId>maven-script-interpreter</artifactId>
206211
<version>1.6</version>
207212
</dependency>
213+
<dependency>
214+
<groupId>org.apache.commons</groupId>
215+
<artifactId>commons-text</artifactId>
216+
<version>1.12.0</version>
217+
</dependency>
218+
<dependency>
219+
<groupId>org.slf4j</groupId>
220+
<artifactId>slf4j-api</artifactId>
221+
<version>1.7.36</version>
222+
</dependency>
208223

209224
<dependency>
210225
<groupId>${beanshell-groupId}</groupId>
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 = initialize site

src/it/MINVOKER-351/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>example.minvoker351</groupId>
27+
<artifactId>minvoker-351</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<packaging>pom</packaging>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
</properties>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.plugins</groupId>
39+
<artifactId>maven-site-plugin</artifactId>
40+
<version>@version.maven-site-plugin@</version>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-invoker-plugin</artifactId>
45+
<version>@project.version@</version>
46+
<configuration>
47+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
48+
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
49+
<writeJunitReport>true</writeJunitReport>
50+
</configuration>
51+
<executions>
52+
<execution>
53+
<id>integration-test</id>
54+
<phase>initialize</phase>
55+
<goals>
56+
<goal>install</goal>
57+
<goal>run</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
<!-- Run "mvn site" to see failure due to invalid XML characters -->
66+
<reporting>
67+
<excludeDefaults>true</excludeDefaults>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-surefire-report-plugin</artifactId>
72+
<version>@version.maven-surefire@</version>
73+
<configuration>
74+
<reportsDirectories>
75+
<reportsDirectory>${project.build.directory}/invoker-reports-test</reportsDirectory>
76+
</reportsDirectories>
77+
</configuration>
78+
<reportSets>
79+
<reportSet>
80+
<reports>
81+
<report>report-only</report>
82+
</reports>
83+
</reportSet>
84+
</reportSets>
85+
</plugin>
86+
</plugins>
87+
</reporting>
88+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>example.minvoker351</groupId>
27+
<artifactId>minvoker-351</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
<maven.compiler.source>8</maven.compiler.source>
33+
<maven.compiler.target>8</maven.compiler.target>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter</artifactId>
40+
<version>5.10.2</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
package example.minvoker351;
20+
21+
public class Example {
22+
public void printAscii() {
23+
for (int i = 0; i < Byte.MAX_VALUE; ++i) {
24+
System.out.println((char) i);
25+
}
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
package example.minvoker351;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
public class ExampleTest {
24+
@Test
25+
public void f() {
26+
new Example().printAscii();
27+
}
28+
}

src/it/MINVOKER-351/verify.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
def surefireReport = new File(basedir, 'target/site/surefire-report.html').text
21+
22+
assert surefireReport.contains('maven.invoker.it.minvoker-351')
23+

src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.TreeSet;
5151
import java.util.stream.Collectors;
5252

53+
import org.apache.commons.text.StringEscapeUtils;
5354
import org.apache.maven.artifact.Artifact;
5455
import org.apache.maven.execution.MavenSession;
5556
import org.apache.maven.model.Model;
@@ -98,6 +99,7 @@
9899
import org.codehaus.plexus.util.cli.CommandLineUtils;
99100
import org.codehaus.plexus.util.cli.Commandline;
100101
import org.codehaus.plexus.util.cli.StreamConsumer;
102+
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
101103
import org.codehaus.plexus.util.xml.XmlStreamReader;
102104
import org.codehaus.plexus.util.xml.XmlStreamWriter;
103105
import org.codehaus.plexus.util.xml.Xpp3Dom;
@@ -1640,7 +1642,7 @@ private void runBuild(
16401642
}
16411643
} catch (RunFailureException e) {
16421644
buildJob.setResult(e.getType());
1643-
buildJob.setFailureMessage(e.getMessage());
1645+
buildJob.setFailureMessage(StringEscapeUtils.escapeXml10(e.getMessage()));
16441646

16451647
if (!suppressSummaries) {
16461648
getLog().info(" " + e.getMessage());
@@ -1779,7 +1781,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
17791781
if (buildLogFile != null && buildLogFile.exists()) {
17801782
getLog().debug("fileLogger:" + buildLogFile);
17811783
try {
1782-
systemOut.setValue(FileUtils.fileRead(buildLogFile));
1784+
systemOut.setValue(StringEscapeUtils.escapeXml10(FileUtils.fileRead(buildLogFile)));
17831785
} catch (IOException e) {
17841786
throw new MojoExecutionException("Failed to read logfile " + buildLogFile, e);
17851787
}
@@ -1789,7 +1791,7 @@ private void writeJunitReport(BuildJob buildJob, String safeFileName) throws Moj
17891791

17901792
try (FileOutputStream fos = new FileOutputStream(reportFile);
17911793
Writer osw = new OutputStreamWriter(fos, buildJob.getModelEncoding())) {
1792-
Xpp3DomWriter.write(osw, testsuite);
1794+
Xpp3DomWriter.write(new PrettyPrintXMLWriter(osw), testsuite, false);
17931795
} catch (IOException e) {
17941796
throw new MojoExecutionException("Failed to write JUnit build report " + reportFile, e);
17951797
}

0 commit comments

Comments
 (0)