You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/10/16 19:53:57 UTC
[maven] branch MNG-7904 created (now 906ca2ecb3)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a change to branch MNG-7904
in repository https://gitbox.apache.org/repos/asf/maven.git
at 906ca2ecb3 [MNG-7904] Use SettingsStaxReader/Writer for SettingsXpp3Reader/Writer
This branch includes the following new commits:
new 906ca2ecb3 [MNG-7904] Use SettingsStaxReader/Writer for SettingsXpp3Reader/Writer
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven] 01/01: [MNG-7904] Use SettingsStaxReader/Writer for SettingsXpp3Reader/Writer
Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MNG-7904
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 906ca2ecb3d5a404af86d4dfdbb6ab3a65bf8b09
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri Oct 13 15:45:32 2023 +0200
[MNG-7904] Use SettingsStaxReader/Writer for SettingsXpp3Reader/Writer
---
maven-settings/pom.xml | 2 -
.../maven/settings/io/xpp3/SettingsXpp3Reader.java | 108 +++++++++++----------
.../maven/settings/io/xpp3/SettingsXpp3Writer.java | 47 +++++----
3 files changed, 83 insertions(+), 74 deletions(-)
diff --git a/maven-settings/pom.xml b/maven-settings/pom.xml
index a971382d0d..af48983785 100644
--- a/maven-settings/pom.xml
+++ b/maven-settings/pom.xml
@@ -82,8 +82,6 @@ under the License.
<templates>
<template>merger.vm</template>
<template>transformer.vm</template>
- <template>reader.vm</template>
- <template>writer.vm</template>
<template>reader-stax.vm</template>
<template>writer-stax.vm</template>
</templates>
diff --git a/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java b/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
index e6af95e32e..4466ca44ae 100644
--- a/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
+++ b/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
@@ -18,29 +18,32 @@
*/
package org.apache.maven.settings.io.xpp3;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.v4.SettingsStaxReader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+/**
+ * @deprecated Maven 3 compatability - please use {@code org.apache.maven.api.services.xml.SettingsXmlFactory} from {@code maven-api-core}
+ * or {@link SettingsStaxReader}
+ */
@Deprecated
public class SettingsXpp3Reader {
- private boolean addDefaultEntities = true;
- private final ContentTransformer contentTransformer;
+ private final SettingsStaxReader delegate;
public SettingsXpp3Reader() {
- this((source, fieldName) -> source);
+ delegate = new SettingsStaxReader();
}
public SettingsXpp3Reader(ContentTransformer contentTransformer) {
- this.contentTransformer = contentTransformer;
+ delegate = new SettingsStaxReader(contentTransformer::transform);
}
/**
@@ -49,39 +52,48 @@ public class SettingsXpp3Reader {
* @return boolean
*/
public boolean getAddDefaultEntities() {
- return addDefaultEntities;
- } // -- boolean getAddDefaultEntities()
+ return delegate.getAddDefaultEntities();
+ }
+
+ /**
+ * Sets the state of the "add default entities" flag.
+ *
+ * @param addDefaultEntities a addDefaultEntities object.
+ */
+ public void setAddDefaultEntities(boolean addDefaultEntities) {
+ delegate.setAddDefaultEntities(addDefaultEntities);
+ }
/**
* @param reader a reader object.
* @param strict a strict object.
* @throws IOException IOException if any.
- * @throws XMLStreamException XMLStreamException if
+ * @throws XmlPullParserException XmlPullParserException if
* any.
* @return Settings
*/
- public Settings read(Reader reader, boolean strict) throws IOException, XMLStreamException {
- XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
- factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
- XMLStreamReader parser = null;
+ public Settings read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
try {
- parser = factory.createXMLStreamReader(reader);
+ return new Settings(delegate.read(reader, strict, null));
} catch (XMLStreamException e) {
- throw new RuntimeException(e);
+ throw new XmlPullParserException(e.getMessage(), null, e);
}
- return read(parser, strict);
- } // -- Model read( Reader, boolean )
+ }
/**
* @param reader a reader object.
* @throws IOException IOException if any.
- * @throws XMLStreamException XMLStreamException if
+ * @throws XmlPullParserException XmlPullParserException if
* any.
* @return Model
*/
- public Settings read(Reader reader) throws IOException, XMLStreamException {
- return read(reader, true);
- } // -- Model read( Reader )
+ public Settings read(Reader reader) throws IOException, XmlPullParserException {
+ try {
+ return new Settings(delegate.read(reader));
+ } catch (XMLStreamException e) {
+ throw new XmlPullParserException(e.getMessage(), null, e);
+ }
+ }
/**
* Method read.
@@ -89,30 +101,34 @@ public class SettingsXpp3Reader {
* @param in a in object.
* @param strict a strict object.
* @throws IOException IOException if any.
- * @throws XMLStreamException XMLStreamException if
+ * @throws XmlPullParserException XmlPullParserException if
* any.
* @return Settings
*/
- public Settings read(InputStream in, boolean strict) throws IOException, XMLStreamException {
- XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
- factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
- StreamSource streamSource = new StreamSource(in, null);
- XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
- return read(parser, strict);
- } // -- Model read( InputStream, boolean )
+ public Settings read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
+ try {
+ return new Settings(delegate.read(in, strict, null));
+ } catch (XMLStreamException e) {
+ throw new XmlPullParserException(e.getMessage(), null, e);
+ }
+ }
/**
* Method read.
*
* @param in a in object.
* @throws IOException IOException if any.
- * @throws XMLStreamException XMLStreamException if
+ * @throws XmlPullParserException XmlPullParserException if
* any.
* @return Settings
*/
- public Settings read(InputStream in) throws IOException, XMLStreamException {
- return read(in, true);
- } // -- Model read( InputStream )
+ public Settings read(InputStream in) throws IOException, XmlPullParserException {
+ try {
+ return new Settings(delegate.read(in));
+ } catch (XMLStreamException e) {
+ throw new XmlPullParserException(e.getMessage(), null, e);
+ }
+ }
/**
* Method read.
@@ -120,27 +136,17 @@ public class SettingsXpp3Reader {
* @param parser a parser object.
* @param strict a strict object.
* @throws IOException IOException if any.
- * @throws XMLStreamException XMLStreamException if
+ * @throws XmlPullParserException XmlPullParserException if
* any.
* @return Settings
*/
- public Settings read(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
- org.apache.maven.settings.v4.SettingsXpp3Reader reader = contentTransformer != null
- ? new org.apache.maven.settings.v4.SettingsXpp3Reader(contentTransformer::transform)
- : new org.apache.maven.settings.v4.SettingsXpp3Reader();
- reader.setAddDefaultEntities(addDefaultEntities);
- org.apache.maven.api.settings.Settings settings = reader.read(parser, strict);
- return new Settings(settings);
- } // -- Model read( XMLStreamReader, boolean )
-
- /**
- * Sets the state of the "add default entities" flag.
- *
- * @param addDefaultEntities a addDefaultEntities object.
- */
- public void setAddDefaultEntities(boolean addDefaultEntities) {
- this.addDefaultEntities = addDefaultEntities;
- } // -- void setAddDefaultEntities( boolean )
+ public Settings read(XMLStreamReader parser, boolean strict) throws IOException, XmlPullParserException {
+ try {
+ return new Settings(delegate.read(parser, strict, null));
+ } catch (XMLStreamException e) {
+ throw new XmlPullParserException(e.getMessage(), null, e);
+ }
+ }
public interface ContentTransformer {
/**
diff --git a/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Writer.java b/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Writer.java
index f1c53ac588..61dc99596a 100644
--- a/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Writer.java
+++ b/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Writer.java
@@ -18,35 +18,36 @@
*/
package org.apache.maven.settings.io.xpp3;
+import javax.xml.stream.XMLStreamException;
+
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.v4.SettingsStaxWriter;
+/**
+ * @deprecated Maven 3 compatability - please use {@code org.apache.maven.api.services.xml.SettingsXmlFactory} from {@code maven-api-core}
+ * or {@link SettingsStaxWriter}
+ */
@Deprecated
public class SettingsXpp3Writer {
- // --------------------------/
- // - Class/Member Variables -/
- // --------------------------/
-
- /**
- * Field fileComment.
- */
- private String fileComment = null;
- // -----------/
- // - Methods -/
- // -----------/
+ private final SettingsStaxWriter delegate;
+ public SettingsXpp3Writer() {
+ delegate = new SettingsStaxWriter();
+ delegate.setAddLocationInformation(false);
+ }
/**
* Method setFileComment.
*
* @param fileComment a fileComment object.
*/
public void setFileComment(String fileComment) {
- this.fileComment = fileComment;
- } // -- void setFileComment( String )
+ delegate.setFileComment(fileComment);
+ }
/**
* Method write.
@@ -56,10 +57,12 @@ public class SettingsXpp3Writer {
* @throws IOException java.io.IOException if any.
*/
public void write(Writer writer, Settings settings) throws IOException {
- org.apache.maven.settings.v4.SettingsXpp3Writer xw = new org.apache.maven.settings.v4.SettingsXpp3Writer();
- xw.setFileComment(fileComment);
- xw.write(writer, settings.getDelegate());
- } // -- void write( Writer, Model )
+ try {
+ delegate.write(writer, settings.getDelegate());
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
/**
* Method write.
@@ -69,8 +72,10 @@ public class SettingsXpp3Writer {
* @throws IOException java.io.IOException if any.
*/
public void write(OutputStream stream, Settings settings) throws IOException {
- org.apache.maven.settings.v4.SettingsXpp3Writer xw = new org.apache.maven.settings.v4.SettingsXpp3Writer();
- xw.setFileComment(fileComment);
- xw.write(stream, settings.getDelegate());
- } // -- void write( OutputStream, Model )
+ try {
+ delegate.write(stream, settings.getDelegate());
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
}