30
30
import java .io .IOException ;
31
31
import java .io .InputStream ;
32
32
import java .io .Reader ;
33
+ import java .nio .file .Files ;
33
34
import java .nio .file .Path ;
34
35
import java .util .Map ;
35
36
import java .util .Objects ;
39
40
import org .apache .maven .model .building .ModelSourceTransformer ;
40
41
import org .apache .maven .model .building .TransformerContext ;
41
42
import org .apache .maven .model .v4 .MavenStaxReader ;
42
- import org .codehaus .plexus .util .ReaderFactory ;
43
- import org .codehaus .plexus .util .xml .XmlStreamReader ;
44
43
45
44
/**
46
45
* Handles deserialization of a model from some kind of textual format like XML.
@@ -61,7 +60,7 @@ public DefaultModelReader(ModelSourceTransformer transformer) {
61
60
public Model read (File input , Map <String , ?> options ) throws IOException {
62
61
Objects .requireNonNull (input , "input cannot be null" );
63
62
64
- try (XmlStreamReader in = ReaderFactory . newXmlReader (input )) {
63
+ try (InputStream in = Files . newInputStream (input . toPath () )) {
65
64
Model model = read (in , input .toPath (), options );
66
65
67
66
model .setPomFile (input );
@@ -83,9 +82,7 @@ public Model read(Reader input, Map<String, ?> options) throws IOException {
83
82
public Model read (InputStream input , Map <String , ?> options ) throws IOException {
84
83
Objects .requireNonNull (input , "input cannot be null" );
85
84
86
- try (XmlStreamReader in = ReaderFactory .newXmlReader (input )) {
87
- return read (in , null , options );
88
- }
85
+ return read (input , null , options );
89
86
}
90
87
91
88
private boolean isStrict (Map <String , ?> options ) {
@@ -103,6 +100,37 @@ private TransformerContext getTransformerContext(Map<String, ?> options) {
103
100
return (TransformerContext ) value ;
104
101
}
105
102
103
+ private Model read (InputStream input , Path pomFile , Map <String , ?> options ) throws IOException {
104
+ try {
105
+ XMLInputFactory factory = new com .ctc .wstx .stax .WstxInputFactory ();
106
+ factory .setProperty (XMLInputFactory .IS_REPLACING_ENTITY_REFERENCES , false );
107
+ XMLStreamReader parser = factory .createXMLStreamReader (input );
108
+
109
+ TransformerContext context = getTransformerContext (options );
110
+ XMLStreamReader transformingParser =
111
+ context != null ? transformer .transform (parser , pomFile , context ) : parser ;
112
+
113
+ InputSource source = getSource (options );
114
+ boolean strict = isStrict (options );
115
+ if (source != null ) {
116
+ return readModelEx (transformingParser , source , strict );
117
+ } else {
118
+ return readModel (transformingParser , strict );
119
+ }
120
+ } catch (XMLStreamException e ) {
121
+ Location location = e .getLocation ();
122
+ throw new ModelParseException (
123
+ e .getMessage (),
124
+ location != null ? location .getLineNumber () : -1 ,
125
+ location != null ? location .getColumnNumber () : -1 ,
126
+ e );
127
+ } catch (IOException e ) {
128
+ throw e ;
129
+ } catch (Exception e ) {
130
+ throw new IOException ("Unable to transform pom" , e );
131
+ }
132
+ }
133
+
106
134
private Model read (Reader reader , Path pomFile , Map <String , ?> options ) throws IOException {
107
135
try {
108
136
XMLInputFactory factory = new com .ctc .wstx .stax .WstxInputFactory ();
0 commit comments