You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2023/06/26 09:57:55 UTC
[GitHub] [maven] gnodet opened a new pull request, #1185: Move XML to STAX api
gnodet opened a new pull request, #1185:
URL: https://github.com/apache/maven/pull/1185
Switch the underlying plexus-xml Xpp3 parser to the STAX api / aalto parser
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1185:
URL: https://github.com/apache/maven/pull/1185#discussion_r1245205028
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
Review Comment:
Not really, I'll remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet merged pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #1185:
URL: https://github.com/apache/maven/pull/1185
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on a diff in pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #1185:
URL: https://github.com/apache/maven/pull/1185#discussion_r1245091437
##########
maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java:
##########
@@ -120,23 +120,29 @@ private Model read(Reader reader, Path pomFile, Map<String, ?> options) throws I
} else {
return readModel(transformingParser, strict);
}
- } catch (XmlPullParserException e) {
- throw new ModelParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
+ } catch (XMLStreamException e) {
+ Location location = e.getLocation();
+ throw new ModelParseException(
+ e.getMessage(),
+ location != null ? location.getLineNumber() : -1,
+ location != null ? location.getColumnNumber() : -1,
+ e);
} catch (IOException e) {
throw e;
} catch (Exception e) {
Review Comment:
This catch block might not be needed any more
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
+
+ @Test
+ @Disabled
+ void readAll() throws IOException {
+ Path userHome = Paths.get(System.getProperty("user.home"));
+ Stream<Path> poms = Files.walk(userHome.resolve(".m2/repository/"))
+ .filter(p -> p.getFileName().toString().endsWith(".pom") && Files.isRegularFile(p));
+ poms.forEach(pom -> {
+ Model stax = null, xpp3 = null;
+ try (InputStream is = Files.newInputStream(pom)) {
+ xpp3 = new MavenXpp3ReaderEx().read(is, false, new InputSource("id", pom.toString()));
+ } catch (Exception e) {
+ System.err.println("Unable to parse using xpp3: " + pom + " (" + e.getMessage() + ")");
Review Comment:
The test should just fail here, or perhaps skip
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
+
+ @Test
+ @Disabled
+ void readAll() throws IOException {
+ Path userHome = Paths.get(System.getProperty("user.home"));
+ Stream<Path> poms = Files.walk(userHome.resolve(".m2/repository/"))
+ .filter(p -> p.getFileName().toString().endsWith(".pom") && Files.isRegularFile(p));
+ poms.forEach(pom -> {
+ Model stax = null, xpp3 = null;
+ try (InputStream is = Files.newInputStream(pom)) {
+ xpp3 = new MavenXpp3ReaderEx().read(is, false, new InputSource("id", pom.toString()));
+ } catch (Exception e) {
+ System.err.println("Unable to parse using xpp3: " + pom + " (" + e.getMessage() + ")");
+ }
+ try (InputStream is = Files.newInputStream(pom)) {
+ stax = new MavenStaxReader().read(is, false, new InputSource("id", pom.toString()));
+ } catch (Exception e) {
+ System.err.println("Unable to parse using stax: " + pom + " (" + e.getMessage() + ")");
+ }
+ if (stax != null && xpp3 != null) {
+ // fix encoding variations
+ if (stax.getModelEncoding() != null) {
+ stax = Model.newBuilder(stax, true)
+ .modelEncoding(
+ Charset.forName(stax.getModelEncoding()).toString())
+ .build();
+ }
+ if (xpp3.getModelEncoding() != null) {
+ xpp3 = Model.newBuilder(xpp3, true)
+ .modelEncoding(
+ Charset.forName(xpp3.getModelEncoding()).toString())
+ .build();
+ }
+ // compare models
+ try {
+ MavenXpp3Writer w = new MavenXpp3Writer();
+ StringWriter sw1 = new StringWriter();
+ StringWriter sw2 = new StringWriter();
+ w.write(sw1, xpp3);
+ w.write(sw2, stax);
+ String s1 = sw1.toString();
+ String s2 = sw2.toString();
+ if (!Objects.equals(s1, s2)) {
+ int idx = 0;
+ while (idx < s1.length() && idx < s2.length()) {
+ if (s1.charAt(idx) != s2.charAt(idx)) {
+ break;
+ }
+ idx++;
+ }
+ int nb = 25;
+ System.err.println("Mismatch reading: " + pom + " (at: " + idx
+ + ", xpp3: '" + getSubstring(s1, idx, nb) + "'"
+ + " vs stax: '" + getSubstring(s2, idx, nb)
+ + "')");
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Error writing", e);
Review Comment:
no need to convert the exception; just bubble the IOException
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
Review Comment:
Looks like this might just be a tool during development. Do you want to commit it to the repo?
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
+
+ @Test
+ @Disabled
Review Comment:
why disabled?
##########
maven-model-transform/pom.xml:
##########
@@ -32,6 +32,14 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>stax2-api</artifactId>
Review Comment:
Do we need stax2 or could we get away with the stax version in the JDK?
##########
maven-model-transform/src/main/java/org/apache/maven/model/transform/stax/XmlUtils.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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 org.apache.maven.model.transform.stax;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+import com.ctc.wstx.api.WstxOutputProperties;
+
+public class XmlUtils {
+
+ public static InputStream writeDocument(XMLStreamReader parser) throws XMLStreamException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writeDocument(parser, baos);
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ public static void writeDocument(XMLStreamReader parser, OutputStream output) throws XMLStreamException {
+ XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ factory.setProperty(WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
+ XMLStreamWriter serializer = factory.createXMLStreamWriter(output, parser.getCharacterEncodingScheme());
+ copy(parser, serializer);
+ }
+
+ private static String normalize(String input) {
+ if (input != null) {
+ return input.replace("\r\n", "\n");
+ }
+ return input;
+ }
+
+ /**
+ * Copies the reader to the writer. The start and end document methods must
+ * be handled on the writer manually.
+ */
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ copy(reader, writer, false, false);
+ }
+
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment)
+ throws XMLStreamException {
+ copy(reader, writer, fragment, false);
+ }
+
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment, boolean isThreshold)
+ throws XMLStreamException {
+ // number of elements read in
+ int read = 0;
+ int elementCount = 0;
+ final Deque<Integer> countStack = new ArrayDeque<>();
+ int event = reader.getEventType();
+
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ read++;
+ if (isThreshold) {
+ elementCount++;
+ countStack.push(elementCount);
+ elementCount = 0;
+ }
+ writeStartElement(reader, writer);
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (read > 0) {
+ writer.writeEndElement();
+ }
+ read--;
+ if (read < 0 && fragment) {
+ return;
+ }
+ if (isThreshold && !countStack.isEmpty()) {
+ elementCount = countStack.pop();
+ }
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ case XMLStreamConstants.SPACE:
+ String s = normalize(reader.getText());
+ if (s != null) {
+ writer.writeCharacters(normalize(s));
+ }
+ break;
+ case XMLStreamConstants.ENTITY_REFERENCE:
+ writer.writeEntityRef(reader.getLocalName());
+ break;
+ case XMLStreamConstants.COMMENT:
+ writer.writeComment(normalize(reader.getText()));
+ break;
+ case XMLStreamConstants.CDATA:
+ writer.writeCData(normalize(reader.getText()));
+ break;
+ case XMLStreamConstants.START_DOCUMENT:
+ if (reader.getVersion() != null) {
+ writer.writeStartDocument(reader.getCharacterEncodingScheme(), reader.getVersion());
+ }
+ break;
+ case XMLStreamConstants.END_DOCUMENT:
+ writer.writeEndDocument();
+ return;
+ case XMLStreamConstants.ATTRIBUTE:
Review Comment:
break
##########
maven-model-transform/src/main/java/org/apache/maven/model/transform/stax/XmlUtils.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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 org.apache.maven.model.transform.stax;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+import com.ctc.wstx.api.WstxOutputProperties;
+
+public class XmlUtils {
+
+ public static InputStream writeDocument(XMLStreamReader parser) throws XMLStreamException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writeDocument(parser, baos);
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ public static void writeDocument(XMLStreamReader parser, OutputStream output) throws XMLStreamException {
+ XMLOutputFactory factory = new com.ctc.wstx.stax.WstxOutputFactory();
+ factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+ factory.setProperty(WstxOutputProperties.P_USE_DOUBLE_QUOTES_IN_XML_DECL, true);
+ XMLStreamWriter serializer = factory.createXMLStreamWriter(output, parser.getCharacterEncodingScheme());
+ copy(parser, serializer);
+ }
+
+ private static String normalize(String input) {
+ if (input != null) {
+ return input.replace("\r\n", "\n");
+ }
+ return input;
+ }
+
+ /**
+ * Copies the reader to the writer. The start and end document methods must
+ * be handled on the writer manually.
+ */
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ copy(reader, writer, false, false);
+ }
+
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment)
+ throws XMLStreamException {
+ copy(reader, writer, fragment, false);
+ }
+
+ public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment, boolean isThreshold)
+ throws XMLStreamException {
+ // number of elements read in
+ int read = 0;
+ int elementCount = 0;
+ final Deque<Integer> countStack = new ArrayDeque<>();
+ int event = reader.getEventType();
+
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ read++;
+ if (isThreshold) {
+ elementCount++;
+ countStack.push(elementCount);
+ elementCount = 0;
+ }
+ writeStartElement(reader, writer);
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (read > 0) {
+ writer.writeEndElement();
+ }
+ read--;
+ if (read < 0 && fragment) {
+ return;
+ }
+ if (isThreshold && !countStack.isEmpty()) {
+ elementCount = countStack.pop();
+ }
+ break;
+ case XMLStreamConstants.CHARACTERS:
Review Comment:
switch fall-through is error-prone during maintenance
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611802061
Might or might not be related:
[INFO]
Error: Errors:
Error: DefaultMavenProjectBuilderTest.rereadPom_mng7063:334 � FileSystem C:\Users\RUNNER~1\AppData\Local\Temp\junit5723635972946138167\pom.xml: The process cannot access the file because it is being used by another process.
Error: ProjectBuilderTest.testReadModifiedPoms(Path) � IO Failed to delete temp directory C:\Users\RUNNER~1\AppData\Local\Temp\junit3720659451607426598. The following paths could not be deleted (see suppressed exceptions for details): , child
[INFO]
Error: Tests run: 428, Failures: 0, Errors: 2, Skipped: 1
[INFO]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611800708
I am sure there are ways to fix that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611403721
> Wow. This looks great. definitely a big leap forward.
>
> I might have missed it, but I didn't find any explicit use of the Stax2 API or Woodstox classes. Could this be done with JDK classes only? classes?
Stax2 / woodstox is actually needed for the consumer POM transformation: the stax api is not sufficient and does not allow full round tripping with xml as spaces in prolog are not reported. Even aalto-xml does not support it. The effect is that when using another implementation, the line breaks before the first element of the POM are removed, so the generated POM will usually contains the xml declaration, the license and the `<project>` element on a single line. Most importantly, this breaks tests :-)
Apart from this use case, changing the implementation leads to various small issues as they do sometimes slightly differ in the specific events they generate. Writing namespaces is particularly challenging, though there's certainly a way to solve those discrepancies, but again, it breaks a few ITs which are particularly sensitive to the exact XML generated.
Also, woodstox is 50% faster than the JDK implementation, so I definitely think we should use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611612736
> Depending on spaces in the prolog is a bug. Tests should be comparing XML to XML, not XML to strings. The latter is extremely brittle and can cause tests to break even in minor upgrades of a library. Alternately, we can canonicalize documents before comparing them. If you file issues on specific tests that do that, I can take a look.
That's not really the problem. I could hack the tests. However, the result xml is the one uploaded on central, and that one is ugly (because of the missing line breaks). So I think this is important to keep.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] elharo commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611590027
Depending on spaces in the prolog is a bug. Tests should be comparing XML to XML, not XML to strings. The latter is extremely brittle and can cause tests to break even in minor upgrades of a library. Alternately, we can canonicalize documents before comparing them. If you file issues on specific tests that do that, I can take a look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1185:
URL: https://github.com/apache/maven/pull/1185#discussion_r1245204583
##########
maven-model/src/test/java/org/apache/maven/model/v4/StaxTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.maven.model.v4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.model.InputSource;
+import org.apache.maven.api.model.Model;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+class StaxTest {
+
+ @Test
+ @Disabled
Review Comment:
See below ...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1185:
URL: https://github.com/apache/maven/pull/1185#discussion_r1245206728
##########
maven-model-transform/pom.xml:
##########
@@ -32,6 +32,14 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>stax2-api</artifactId>
Review Comment:
Yes, the round tripping (i.e. read the xml using stax and write it back to a string without any difference) is only supported by woodstox (the `stax2-api` is a mandatory dependency of woodstox anyway).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #1185:
URL: https://github.com/apache/maven/pull/1185#issuecomment-1611971802
I plan to provide additional support for xml namespaces, but I think a follow-up PR may be better. I'll stop on that one.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] gnodet commented on a diff in pull request #1185: [MNG-7830] Switch from plexus-xml to stax / woodstox
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #1185:
URL: https://github.com/apache/maven/pull/1185#discussion_r1245404521
##########
maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java:
##########
@@ -120,23 +120,29 @@ private Model read(Reader reader, Path pomFile, Map<String, ?> options) throws I
} else {
return readModel(transformingParser, strict);
}
- } catch (XmlPullParserException e) {
- throw new ModelParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
+ } catch (XMLStreamException e) {
+ Location location = e.getLocation();
+ throw new ModelParseException(
+ e.getMessage(),
+ location != null ? location.getLineNumber() : -1,
+ location != null ? location.getColumnNumber() : -1,
+ e);
} catch (IOException e) {
throw e;
} catch (Exception e) {
Review Comment:
The `IOException` can still occur during the call to `transformer.transform(...)` and we don't want to wrap it in another `IOException`...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org