Skip to content

Commit 083381e

Browse files
committed
Fixes after review
1 parent fcc2c9f commit 083381e

File tree

10 files changed

+29
-243
lines changed

10 files changed

+29
-243
lines changed

maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ void testReadInvalidPom() throws Exception {
234234
getContainer().lookup(org.apache.maven.project.ProjectBuilder.class);
235235

236236
// single project build entry point
237-
Exception ex = assertThrows(Exception.class, () -> projectBuilder.build(pomFile, configuration));
238-
assertThat(ex.getMessage(), containsString("expected START_TAG or END_TAG, not CHARACTERS"));
237+
ProjectBuildingException ex =
238+
assertThrows(ProjectBuildingException.class, () -> projectBuilder.build(pomFile, configuration));
239239

240240
// multi projects build entry point
241241
ProjectBuildingException pex = assertThrows(
@@ -244,9 +244,6 @@ void testReadInvalidPom() throws Exception {
244244
assertEquals(1, pex.getResults().size());
245245
assertNotNull(pex.getResults().get(0).getPomFile());
246246
assertThat(pex.getResults().get(0).getProblems().size(), greaterThan(0));
247-
assertThat(
248-
pex.getResults(),
249-
contains(projectBuildingResultWithProblemMessage("expected START_TAG or END_TAG, not CHARACTERS")));
250247
}
251248

252249
@Test

maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ public DefaultModelReader(ModelSourceTransformer transformer) {
6262
public Model read(File input, Map<String, ?> options) throws IOException {
6363
Objects.requireNonNull(input, "input cannot be null");
6464

65-
try (InputStream in = Files.newInputStream(input.toPath())) {
66-
Model model = read(in, input.toPath(), options);
65+
Model model = read(null, input, options);
6766

68-
model.setPomFile(input);
67+
model.setPomFile(input);
6968

70-
return model;
71-
}
69+
return model;
7270
}
7371

7472
@Override
@@ -109,25 +107,21 @@ private boolean getXInclude(Map<String, ?> options) {
109107
return value instanceof Boolean && (Boolean) value;
110108
}
111109

112-
private Model read(InputStream input, Path pomFile, Map<String, ?> options) throws IOException {
110+
private Model read(InputStream input, File pomFile, Map<String, ?> options) throws IOException {
113111
try {
114112
InputSource source = getSource(options);
115113
boolean strict = isStrict(options);
116114
Path rootDirectory = getRootDirectory(options);
117115

118116
Source xmlSource;
119117
if (pomFile != null) {
120-
if (input != null) {
121-
xmlSource = new StaxPathInputSource(pomFile, input);
122-
} else {
123-
xmlSource = new Stax2FileSource(pomFile.toFile());
124-
}
118+
xmlSource = new Stax2FileSource(pomFile);
125119
} else {
126120
xmlSource = new StreamSource(input);
127121
}
128122

129123
XMLStreamReader parser;
130-
// We only support xml entities and xinclude when reading a file in strict mode
124+
// We only support general external entities and XInclude when reading a file in strict mode
131125
if (pomFile != null && strict && getXInclude(options)) {
132126
parser = XInclude.xinclude(xmlSource, new LocalXmlResolver(rootDirectory));
133127
} else {
@@ -176,17 +170,4 @@ private Model read(Reader reader, Path pomFile, Map<String, ?> options) throws I
176170
}
177171
}
178172

179-
private static class StaxPathInputSource extends Stax2FileSource {
180-
private final InputStream input;
181-
182-
StaxPathInputSource(Path pomFile, InputStream input) {
183-
super(pomFile.toFile());
184-
this.input = input;
185-
}
186-
187-
@Override
188-
public InputStream constructInputStream() throws IOException {
189-
return input;
190-
}
191-
}
192173
}

maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface ModelReader {
4646
String INPUT_SOURCE = "org.apache.maven.model.io.inputSource";
4747

4848
/**
49-
* Name of the property used to store a boolean {@code true} if XInclude supports
49+
* Name of the property used to store a boolean {@code true} if XInclude support
5050
* is needed.
5151
*/
5252
String XINCLUDE = "xinclude";

maven-stax-xinclude/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ under the License.
2626
</parent>
2727

2828
<artifactId>maven-stax-xinclude</artifactId>
29-
<name>Implementation of Maven API XML</name>
30-
<description>Provides the implementation classes for the Maven API XML</description>
29+
<name>Maven StaX XInclude implementation</name>
30+
<description>Provides the classes for StaX XInclude implementation</description>
3131

3232
<dependencies>
3333
<dependency>

maven-stax-xinclude/src/main/java/org/apache/maven/stax/xinclude/DOMXMLElementEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public boolean testElementShorthand(XMLElement<Element> element, String shorthan
7979
/**
8080
* Evaluates the XPointer on the root Element and returns the resulting Element or null.
8181
*
82-
* @return an Element from the resultant evaluation of the root Element or null if evaluation fails
82+
* @return an Element from the evaluation of the root Element or null if evaluation fails
8383
*/
8484
public Element evaluateElement() {
8585
XMLElement<Element> element = evaluate();

maven-stax-xinclude/src/main/java/org/apache/maven/stax/xinclude/ElementPointerPart.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,23 @@ private String serialiseChildSequence() {
167167
static ElementPointerPart parseFromString(final String schemeData) throws InvalidXPointerException {
168168
List<Integer> childSequence;
169169
String elementID = null;
170-
int startChar;
171-
int endChar;
172170

173171
// Find an NCName if it exists?
174-
startChar = schemeData.indexOf("/");
172+
int startChar = schemeData.indexOf("/");
175173
// -1 Only an NCName. 0 No NCName. > 1 An NCName.
176174

177175
switch (startChar) {
178176
case -1: // Only an NCName.
179177
elementID = schemeData;
180-
if (!NCName.isValid(elementID)) {
178+
if (XPointerParser.isInvalidNCName(elementID)) {
181179
throw new InvalidXPointerException("Invalid NCName in the XPointer", schemeData);
182180
}
183181
return new ElementPointerPart(elementID);
184182
case 0: // No NCName.
185183
break;
186184
default: // An NCName.
187185
elementID = schemeData.substring(0, startChar);
188-
if (!NCName.isValid(elementID)) {
186+
if (XPointerParser.isInvalidNCName(elementID)) {
189187
throw new InvalidXPointerException("Invalid NCName in the XPointer", schemeData, 0, startChar);
190188
}
191189
break;
@@ -194,7 +192,7 @@ static ElementPointerPart parseFromString(final String schemeData) throws Invali
194192
// Find remaining child sequence.
195193
childSequence = new ArrayList<>();
196194

197-
endChar = schemeData.indexOf("/", startChar + 1);
195+
int endChar = schemeData.indexOf("/", startChar + 1);
198196
// -1 Only single child sequence element. > 0 A childSequence.
199197

200198
if (endChar < 0) { // Only single child sequence element.

maven-stax-xinclude/src/main/java/org/apache/maven/stax/xinclude/InvalidXPointerException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.maven.stax.xinclude;
2020

2121
/**
22-
* This class represents Exceptions that can happen during parsing an XPointer Expression.
22+
* This class represents Exceptions that can happen while parsing an XPointer Expression.
2323
* <p>
2424
* This class is based upon a class of the same name in Apache Woden.
2525
*/

maven-stax-xinclude/src/main/java/org/apache/maven/stax/xinclude/NCName.java

Lines changed: 0 additions & 176 deletions
This file was deleted.

maven-stax-xinclude/src/main/java/org/apache/maven/stax/xinclude/XMLElementEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract class XMLElementEvaluator<T> {
5252
/**
5353
* Evaluates the XPointer on the root XMLElement and returns the resulting XMLElement or null.
5454
*
55-
* @return an XMLElement from the resultant evaluation of the root XMLElement or null if evaluation fails.
55+
* @return an XMLElement from the evaluation of the root XMLElement or null if evaluation fails.
5656
*/
5757
public XMLElement<T> evaluate() {
5858
if (xpointer.hasPointerParts()) { // Scheme based pointer.

0 commit comments

Comments
 (0)