[MNG-7901] Use MetadataStaxReader/Writer in MetadataXpp3Reader/Writer

This commit is contained in:
Slawomir Jaranowski 2023-10-06 23:15:21 +02:00
parent 523f8b7dc0
commit 79c09f2800
3 changed files with 61 additions and 30 deletions

View File

@ -99,8 +99,6 @@ under the License.
</models>
<templates>
<template>model-v3.vm</template>
<template>reader.vm</template>
<template>writer.vm</template>
</templates>
</configuration>
</execution>

View File

@ -26,22 +26,24 @@ import java.io.InputStream;
import java.io.Reader;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.io.MetadataStaxReader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Provide public methods from {@link org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Reader}
* Provide public methods from {@link MetadataStaxReader}
*
* @deprecated Maven 3 compatability
* @deprecated Maven 3 compatability - please use {@link MetadataStaxReader}
*/
@Deprecated
public class MetadataXpp3Reader {
private final org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Reader delegate;
private final MetadataStaxReader delegate;
/**
* Default constructor
*/
public MetadataXpp3Reader() {
delegate = new org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Reader();
delegate = new MetadataStaxReader();
}
/**
@ -50,8 +52,7 @@ public class MetadataXpp3Reader {
* @param contentTransformer a transformer
*/
public MetadataXpp3Reader(ContentTransformer contentTransformer) {
delegate =
new org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Reader(contentTransformer::transform);
delegate = new MetadataStaxReader(contentTransformer::transform);
}
/**
@ -79,11 +80,15 @@ public class MetadataXpp3Reader {
* @param strict a strict object.
* @return Metadata
* @throws IOException IOException if any.
* @throws XMLStreamException XmlPullParserException if
* @throws XmlPullParserException XmlPullParserException if
* any.
*/
public Metadata read(Reader reader, boolean strict) throws IOException, XMLStreamException {
public Metadata read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
try {
return new Metadata(delegate.read(reader, strict));
} catch (XMLStreamException e) {
throw new XmlPullParserException(e.getMessage(), null, e);
}
}
/**
@ -92,11 +97,15 @@ public class MetadataXpp3Reader {
* @param reader a reader object.
* @return Metadata
* @throws IOException IOException if any.
* @throws XMLStreamException XmlPullParserException if
* @throws XmlPullParserException XmlPullParserException if
* any.
*/
public Metadata read(Reader reader) throws IOException, XMLStreamException {
public Metadata read(Reader reader) throws IOException, XmlPullParserException {
try {
return new Metadata(delegate.read(reader));
} catch (XMLStreamException e) {
throw new XmlPullParserException(e.getMessage(), null, e);
}
}
/**
@ -106,11 +115,15 @@ public class MetadataXpp3Reader {
* @param strict a strict object.
* @return Metadata
* @throws IOException IOException if any.
* @throws XMLStreamException XmlPullParserException if
* @throws XmlPullParserException XmlPullParserException if
* any.
*/
public Metadata read(InputStream in, boolean strict) throws IOException, XMLStreamException {
public Metadata read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
try {
return new Metadata(delegate.read(in, strict));
} catch (XMLStreamException e) {
throw new XmlPullParserException(e.getMessage(), null, e);
}
}
/**
@ -119,11 +132,15 @@ public class MetadataXpp3Reader {
* @param in a in object.
* @return Metadata
* @throws IOException IOException if any.
* @throws XMLStreamException XmlPullParserException if
* @throws XmlPullParserException XmlPullParserException if
* any.
*/
public Metadata read(InputStream in) throws IOException, XMLStreamException {
public Metadata read(InputStream in) throws IOException, XmlPullParserException {
try {
return new Metadata(delegate.read(in));
} catch (XMLStreamException e) {
throw new XmlPullParserException(e.getMessage(), null, e);
}
}
/**
@ -133,15 +150,19 @@ public class MetadataXpp3Reader {
* @param strict a strict object.
* @return Metadata
* @throws IOException IOException if any.
* @throws XMLStreamException XmlPullParserException if
* @throws XmlPullParserException XmlPullParserException if
* any.
*/
public Metadata read(XMLStreamReader parser, boolean strict) throws IOException, XMLStreamException {
public Metadata read(XMLStreamReader parser, boolean strict) throws IOException, XmlPullParserException {
try {
return new Metadata(delegate.read(parser, strict));
} catch (XMLStreamException e) {
throw new XmlPullParserException(e.getMessage(), null, e);
}
}
/**
* {@link org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Reader.ContentTransformer}
* {@link MetadataStaxReader.ContentTransformer}
*/
public interface ContentTransformer {
/**

View File

@ -18,26 +18,30 @@
*/
package org.apache.maven.artifact.repository.metadata.io.xpp3;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.io.MetadataStaxWriter;
/**
* Provide public methods from {@link org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Writer}
* Provide public methods from {@link MetadataStaxWriter}
*
* @deprecated Maven 3 compatability
* @deprecated Maven 3 compatability - please use {@link MetadataStaxWriter}
*/
@Deprecated
public class MetadataXpp3Writer {
private final org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Writer delegate;
private final MetadataStaxWriter delegate;
/**
* Default constructor
*/
public MetadataXpp3Writer() {
delegate = new org.apache.maven.artifact.repository.metadata.io.MetadataXpp3Writer();
delegate = new MetadataStaxWriter();
}
/**
@ -57,7 +61,11 @@ public class MetadataXpp3Writer {
* @throws java.io.IOException java.io.IOException if any
*/
public void write(Writer writer, Metadata metadata) throws java.io.IOException {
try {
delegate.write(writer, metadata.getDelegate());
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
/**
@ -68,6 +76,10 @@ public class MetadataXpp3Writer {
* @throws java.io.IOException java.io.IOException if any
*/
public void write(OutputStream stream, Metadata metadata) throws java.io.IOException {
try {
delegate.write(stream, metadata.getDelegate());
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
}