Skip to content

Commit ea9ecbf

Browse files
committed
Fix compilation
1 parent a24ab03 commit ea9ecbf

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

  • maven-plugin/rcptt-maven-plugin/src/main/java/org/eclipse/rcptt/maven

maven-plugin/rcptt-maven-plugin/src/main/java/org/eclipse/rcptt/maven/PackageMojo.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111
package org.eclipse.rcptt.maven;
1212

1313
import java.io.File;
14-
import java.io.FileInputStream;
1514
import java.io.IOException;
1615
import java.util.regex.Matcher;
1716
import java.util.regex.Pattern;
1817

18+
import javax.xml.stream.XMLInputFactory;
19+
import javax.xml.stream.XMLStreamConstants;
20+
import javax.xml.stream.XMLStreamException;
21+
import javax.xml.stream.XMLStreamReader;
22+
import javax.xml.transform.stream.StreamSource;
23+
1924
import org.apache.maven.plugin.MojoExecutionException;
2025
import org.apache.maven.plugin.MojoFailureException;
2126
import org.apache.maven.project.MavenProjectHelper;
2227
import org.codehaus.plexus.archiver.Archiver;
2328
import org.codehaus.plexus.archiver.ArchiverException;
2429
import org.codehaus.plexus.archiver.util.DefaultFileSet;
25-
import org.codehaus.plexus.util.xml.pull.MXParser;
26-
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
27-
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
2830

2931
/**
3032
* Packages two artifacts: - project with q7 tests itself - test results -
@@ -65,11 +67,16 @@ private void failBuildIfFailingTests() throws MojoFailureException {
6567
throw readError(junitReport);
6668
}
6769

68-
try (FileInputStream inputStream = new FileInputStream(junitReport)) {
69-
XmlPullParser parser = new MXParser();
70-
parser.setInput(inputStream, "UTF-8");
71-
int tag = parser.nextTag();
72-
if (tag != XmlPullParser.START_TAG || !parser.getName().equals("testsuite")) {
70+
XMLInputFactory factory = XMLInputFactory.newInstance();
71+
XMLStreamReader parser;
72+
try {
73+
parser = factory.createXMLStreamReader(new StreamSource(junitReport));
74+
} catch (XMLStreamException e) {
75+
throw readError(junitReport, e);
76+
}
77+
try {
78+
int tag = parser.next();
79+
if (tag != XMLStreamConstants.START_ELEMENT || !parser.getName().getLocalPart().equals("testsuite")) {
7380
throw invalidFormat(junitReport);
7481
}
7582

@@ -80,11 +87,16 @@ private void failBuildIfFailingTests() throws MojoFailureException {
8087
if (failures > 0) {
8188
throw new MojoFailureException("There are test failures");
8289
}
83-
84-
} catch (IOException e) {
85-
throw readError(junitReport);
86-
} catch (XmlPullParserException e) {
87-
throw readError(junitReport);
90+
} catch (XMLStreamException e) {
91+
throw readError(junitReport, e);
92+
} finally {
93+
if (parser != null) {
94+
try {
95+
parser.close();
96+
} catch (XMLStreamException e) {
97+
throw readError(junitReport, e);
98+
}
99+
}
88100
}
89101
}
90102

@@ -112,7 +124,11 @@ private static Integer parseInt(String val) {
112124
}
113125

114126
private static MojoFailureException readError(File file) {
115-
return new MojoFailureException(String.format("Could not read test results file %s", file));
127+
return readError(file, null);
128+
}
129+
130+
private static MojoFailureException readError(File file, Throwable e) {
131+
return new MojoFailureException(String.format("Could not read test results file %s", file), e);
116132
}
117133

118134
private static MojoFailureException invalidFormat(File file) {

0 commit comments

Comments
 (0)