Author: bentmann
Date: Tue May 12 20:03:31 2009
New Revision: 774057

URL: http://svn.apache.org/viewvc?rev=774057&view=rev
Log:
o Introduced components to abstract from the Modello generated XPP 
reader/writer such that we can more easily switch the underlying XML parser

Added:
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/
   (with props)
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
   (with props)
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
   (with props)
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
   (with props)
    
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
   (with props)

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/
------------------------------------------------------------------------------
    bugtraq:label = Enter issue ID:

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/
------------------------------------------------------------------------------
    bugtraq:message = Issue id: %BUGID%

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/
------------------------------------------------------------------------------
    bugtraq:number = false

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java?rev=774057&view=auto
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
 (added)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
 Tue May 12 20:03:31 2009
@@ -0,0 +1,108 @@
+package org.apache.maven.model.io;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Handles deserialization of a model from some kind of textual format like 
XML.
+ * 
+ * @author Benjamin Bentmann
+ */
+...@component( role = ModelReader.class )
+public class DefaultModelReader
+    implements ModelReader
+{
+
+    public Model read( File input, Map<String, Object> options )
+        throws IOException
+    {
+        if ( input == null )
+        {
+            throw new IllegalArgumentException( "input file missing" );
+        }
+
+        return read( ReaderFactory.newXmlReader( input ), options );
+    }
+
+    public Model read( Reader input, Map<String, Object> options )
+        throws IOException
+    {
+        if ( input == null )
+        {
+            throw new IllegalArgumentException( "input reader missing" );
+        }
+
+        try
+        {
+            MavenXpp3Reader r = new MavenXpp3Reader();
+            return r.read( input, isStrict( options ) );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw (IOException) new IOException( "Failed to parse POM" 
).initCause( e );
+        }
+        finally
+        {
+            IOUtil.close( input );
+        }
+    }
+
+    public Model read( InputStream input, Map<String, Object> options )
+        throws IOException
+    {
+        if ( input == null )
+        {
+            throw new IllegalArgumentException( "input stream missing" );
+        }
+
+        try
+        {
+            MavenXpp3Reader r = new MavenXpp3Reader();
+            return r.read( input, isStrict( options ) );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw (IOException) new IOException( "Failed to parse POM" 
).initCause( e );
+        }
+        finally
+        {
+            IOUtil.close( input );
+        }
+    }
+
+    private boolean isStrict( Map<String, Object> options )
+    {
+        Object value = ( options != null ) ? options.get( IS_STRICT ) : null;
+        return value == null || Boolean.parseBoolean( value.toString() );
+    }
+
+}

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java?rev=774057&view=auto
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
 (added)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
 Tue May 12 20:03:31 2009
@@ -0,0 +1,115 @@
+package org.apache.maven.model.io;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Map;
+
+import org.apache.maven.model.Model;
+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.WriterFactory;
+
+/**
+ * Handles serialization of a model into some kind of textual format like XML.
+ * 
+ * @author Benjamin Bentmann
+ */
+...@component( role = ModelWriter.class )
+public class DefaultModelWriter
+    implements ModelWriter
+{
+
+    public void write( File output, Map<String, Object> options, Model model )
+        throws IOException
+    {
+        if ( output == null )
+        {
+            throw new IllegalArgumentException( "output file missing" );
+        }
+
+        if ( model == null )
+        {
+            throw new IllegalArgumentException( "model missing" );
+        }
+
+        output.getParentFile().mkdirs();
+
+        write( WriterFactory.newXmlWriter( output ), options, model );
+    }
+
+    public void write( Writer output, Map<String, Object> options, Model model 
)
+        throws IOException
+    {
+        if ( output == null )
+        {
+            throw new IllegalArgumentException( "output writer missing" );
+        }
+
+        if ( model == null )
+        {
+            throw new IllegalArgumentException( "model missing" );
+        }
+
+        try
+        {
+            MavenXpp3Writer w = new MavenXpp3Writer();
+            w.write( output, model );
+        }
+        finally
+        {
+            IOUtil.close( output );
+        }
+    }
+
+    public void write( OutputStream output, Map<String, Object> options, Model 
model )
+        throws IOException
+    {
+        if ( output == null )
+        {
+            throw new IllegalArgumentException( "output stream missing" );
+        }
+
+        if ( model == null )
+        {
+            throw new IllegalArgumentException( "model missing" );
+        }
+
+        try
+        {
+            String encoding = model.getModelEncoding();
+            if ( encoding == null || encoding.length() <= 0 )
+            {
+                encoding = "UTF-8";
+            }
+            write( new OutputStreamWriter( output, encoding ), options, model 
);
+        }
+        finally
+        {
+            IOUtil.close( output );
+        }
+    }
+
+}

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelWriter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java?rev=774057&view=auto
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
 (added)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
 Tue May 12 20:03:31 2009
@@ -0,0 +1,77 @@
+package org.apache.maven.model.io;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+
+import org.apache.maven.model.Model;
+
+/**
+ * Handles deserialization of a model from some kind of textual format like 
XML.
+ * 
+ * @author Benjamin Bentmann
+ */
+public interface ModelReader
+{
+
+    /**
+     * The key for the option to enable strict parsing. This option is of type 
{...@link Boolean} and defaults to {...@code
+     * true}. If {...@code false}, unknown elements will be ignored instead of 
causing a failure.
+     */
+    static final String IS_STRICT = "org.apache.maven.model.io.isStrict";
+
+    /**
+     * Reads the model from the specified file.
+     * 
+     * @param input The file to deserialize the model from, must not be 
{...@code null}.
+     * @param options The options to use for deserialization, may be {...@code 
null} to use the default values.
+     * @return The deserialized model, never {...@code null}.
+     * @throws IOException If the model could not be deserialized.
+     */
+    Model read( File input, Map<String, Object> options )
+        throws IOException;
+
+    /**
+     * Reads the model from the specified character reader.
+     * 
+     * @param input The reader to deserialize the model from, must not be 
{...@code null}.
+     * @param options The options to use for deserialization, may be {...@code 
null} to use the default values.
+     * @return The deserialized model, never {...@code null}.
+     * @throws IOException If the model could not be deserialized.
+     */
+    Model read( Reader input, Map<String, Object> options )
+        throws IOException;
+
+    /**
+     * Reads the model from the specified byte stream.
+     * 
+     * @param input The stream to deserialize the model from, must not be 
{...@code null}.
+     * @param options The options to use for deserialization, may be {...@code 
null} to use the default values.
+     * @return The deserialized model, never {...@code null}.
+     * @throws IOException If the model could not be deserialized.
+     */
+    Model read( InputStream input, Map<String, Object> options )
+        throws IOException;
+
+}

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelReader.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
URL: 
http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java?rev=774057&view=auto
==============================================================================
--- 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
 (added)
+++ 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
 Tue May 12 20:03:31 2009
@@ -0,0 +1,72 @@
+package org.apache.maven.model.io;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.Map;
+
+import org.apache.maven.model.Model;
+
+/**
+ * Handles serialization of a model into some kind of textual format like XML.
+ * 
+ * @author Benjamin Bentmann
+ */
+public interface ModelWriter
+{
+
+    /**
+     * Writes the supplied model to the specified file. Any non-existing 
parent directories of the output file will be
+     * created automatically.
+     * 
+     * @param output The file to serialize the model to, must not be {...@code 
null}.
+     * @param options The options to use for serialization, may be {...@code 
null} to use the default values.
+     * @param model The model to serialize, must not be {...@code null}.
+     * @throws IOException If the model could not be serialized.
+     */
+    void write( File output, Map<String, Object> options, Model model )
+        throws IOException;
+
+    /**
+     * Writes the supplied model to the specified character writer.
+     * 
+     * @param output The writer to serialize the model to, must not be 
{...@code null}.
+     * @param options The options to use for serialization, may be {...@code 
null} to use the default values.
+     * @param model The model to serialize, must not be {...@code null}.
+     * @throws IOException If the model could not be serialized.
+     */
+    void write( Writer output, Map<String, Object> options, Model model )
+        throws IOException;
+
+    /**
+     * Writes the supplied model to the specified byte stream.
+     * 
+     * @param output The stream to serialize the model to, must not be 
{...@code null}.
+     * @param options The options to use for serialization, may be {...@code 
null} to use the default values.
+     * @param model The model to serialize, must not be {...@code null}.
+     * @throws IOException If the model could not be serialized.
+     */
+    void write( OutputStream output, Map<String, Object> options, Model model )
+        throws IOException;
+
+}

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/components/branches/MNG-2766/maven-model-builder/src/main/java/org/apache/maven/model/io/ModelWriter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to