mirror of
https://github.com/apache/maven.git
synced 2025-03-08 17:49:15 +00:00
o Migrated from StAX to XPP to have us focus on a single XML parser for now
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@772013 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5d077ce8e5
commit
81006b21aa
@ -37,14 +37,6 @@
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.woodstox</groupId>
|
||||
<artifactId>wstx-asl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>stax</groupId>
|
||||
<artifactId>stax-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -5,6 +5,7 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -20,11 +21,6 @@
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.DomainModel;
|
||||
import org.apache.maven.model.Model;
|
||||
@ -32,7 +28,12 @@
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
import org.codehaus.plexus.util.WriterFactory;
|
||||
import org.codehaus.plexus.util.xml.pull.MXParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
@Component(role = Interpolator.class)
|
||||
public class DefaultInterpolator
|
||||
@ -580,9 +581,6 @@ private static List<ModelProperty> marshallXmlToModelProperties( InputStream inp
|
||||
}
|
||||
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
XMLInputFactory xmlInputFactory = new com.ctc.wstx.stax.WstxInputFactory();
|
||||
xmlInputFactory.setProperty( XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE );
|
||||
xmlInputFactory.setProperty( XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE );
|
||||
|
||||
Uri uri = new Uri( baseUri );
|
||||
String tagName = baseUri;
|
||||
@ -590,29 +588,28 @@ private static List<ModelProperty> marshallXmlToModelProperties( InputStream inp
|
||||
|
||||
int depth = 0;
|
||||
int depthOfTagValue = depth;
|
||||
XMLStreamReader xmlStreamReader = null;
|
||||
Reader reader = null;
|
||||
try
|
||||
{
|
||||
xmlStreamReader = xmlInputFactory.createXMLStreamReader( inputStream );
|
||||
reader = ReaderFactory.newXmlReader( inputStream );
|
||||
|
||||
XmlPullParser parser = new MXParser();
|
||||
parser.setInput( reader );
|
||||
|
||||
Map<String, String> attributes = new HashMap<String, String>();
|
||||
for ( ;; xmlStreamReader.next() )
|
||||
for ( int type = parser.getEventType();; type = parser.next() )
|
||||
{
|
||||
int type = xmlStreamReader.getEventType();
|
||||
switch ( type )
|
||||
{
|
||||
|
||||
case XMLStreamConstants.CDATA:
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
case XmlPullParser.TEXT:
|
||||
{
|
||||
if ( depth == depthOfTagValue )
|
||||
{
|
||||
tagValue.append( xmlStreamReader.getTextCharacters(), xmlStreamReader.getTextStart(), xmlStreamReader.getTextLength() );
|
||||
tagValue.append( parser.getText() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
case XmlPullParser.START_TAG:
|
||||
{
|
||||
if ( !tagName.equals( baseUri ) )
|
||||
{
|
||||
@ -633,39 +630,38 @@ private static List<ModelProperty> marshallXmlToModelProperties( InputStream inp
|
||||
}
|
||||
|
||||
depth++;
|
||||
tagName = uri.getUriFor( xmlStreamReader.getName().getLocalPart(), depth );
|
||||
tagName = uri.getUriFor( parser.getName(), depth );
|
||||
if ( collections.contains( tagName + "#collection" ) )
|
||||
{
|
||||
tagName = tagName + "#collection";
|
||||
uri.addTag( xmlStreamReader.getName().getLocalPart() + "#collection" );
|
||||
uri.addTag( parser.getName() + "#collection" );
|
||||
}
|
||||
else if ( collections.contains( tagName + "#set" ) )
|
||||
{
|
||||
tagName = tagName + "#set";
|
||||
uri.addTag( xmlStreamReader.getName().getLocalPart() + "#set" );
|
||||
uri.addTag( parser.getName() + "#set" );
|
||||
}
|
||||
else
|
||||
{
|
||||
uri.addTag( xmlStreamReader.getName().getLocalPart() );
|
||||
uri.addTag( parser.getName() );
|
||||
}
|
||||
tagValue.setLength( 0 );
|
||||
depthOfTagValue = depth;
|
||||
}
|
||||
case XMLStreamConstants.ATTRIBUTE:
|
||||
{
|
||||
for ( int i = 0; i < xmlStreamReader.getAttributeCount(); i++ )
|
||||
|
||||
for ( int i = 0; i < parser.getAttributeCount(); i++ )
|
||||
{
|
||||
|
||||
attributes.put( tagName + "#property/" + xmlStreamReader.getAttributeName( i ).getLocalPart(), xmlStreamReader.getAttributeValue( i ) );
|
||||
attributes.put( tagName + "#property/" + parser.getAttributeName( i ),
|
||||
parser.getAttributeValue( i ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
case XmlPullParser.END_TAG:
|
||||
{
|
||||
depth--;
|
||||
break;
|
||||
}
|
||||
case XMLStreamConstants.END_DOCUMENT:
|
||||
case XmlPullParser.END_DOCUMENT:
|
||||
{
|
||||
modelProperties.add( new ModelProperty( tagName, tagValue.toString().trim() ) );
|
||||
if ( !attributes.isEmpty() )
|
||||
@ -674,38 +670,20 @@ else if ( collections.contains( tagName + "#set" ) )
|
||||
{
|
||||
modelProperties.add( new ModelProperty( e.getKey(), e.getValue() ) );
|
||||
}
|
||||
attributes.clear();
|
||||
}
|
||||
return modelProperties;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch ( XMLStreamException e )
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( ":" + e.toString() );
|
||||
throw (IOException) new IOException( "Failed to parser POM:" + e.toString() ).initCause( e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( xmlStreamReader != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
xmlStreamReader.close();
|
||||
}
|
||||
catch ( XMLStreamException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
inputStream.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
||||
}
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
|
18
pom.xml
18
pom.xml
@ -69,10 +69,8 @@ under the License.
|
||||
<mercuryVersion>1.0-alpha-7-SNAPSHOT</mercuryVersion>
|
||||
<mercuryMp3Version>1.0-alpha-1</mercuryMp3Version>
|
||||
<securityDispatcherVersion>1.2</securityDispatcherVersion>
|
||||
<woodstoxVersion>3.2.6</woodstoxVersion>
|
||||
<modelloVersion>1.0.1</modelloVersion>
|
||||
<jxpathVersion>1.3</jxpathVersion>
|
||||
<staxVersion>1.0.1</staxVersion>
|
||||
</properties>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
@ -324,22 +322,6 @@ under the License.
|
||||
<artifactId>doxia-sink-api</artifactId>
|
||||
<version>${doxiaVersion}</version>
|
||||
</dependency>
|
||||
<!-- Maven Shared -->
|
||||
<dependency>
|
||||
<groupId>org.sonatype.spice</groupId>
|
||||
<artifactId>model-builder</artifactId>
|
||||
<version>${modelBuilderVersion}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.woodstox</groupId>
|
||||
<artifactId>wstx-asl</artifactId>
|
||||
<version>${woodstoxVersion}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>stax</groupId>
|
||||
<artifactId>stax-api</artifactId>
|
||||
<version>${staxVersion}</version>
|
||||
</dependency>
|
||||
<!-- Commons -->
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
|
Loading…
x
Reference in New Issue
Block a user