Index: trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java =================================================================== --- trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java (revision 0) +++ trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/AbstractMavenModelTestCase.java (revision 0) @@ -0,0 +1,47 @@ +package org.apache.maven.model.io.xpp3; + + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.FileNotFoundException; +import java.net.URL; + +import junit.framework.TestCase; + +public abstract class AbstractMavenModelTestCase extends TestCase +{ + protected File getFileForClasspathResource( String resource ) + throws FileNotFoundException + { + ClassLoader cloader = Thread.currentThread().getContextClassLoader(); + + URL resourceUrl = cloader.getResource( resource ); + + File resourceFile = null; + if ( resourceUrl != null ) + { + resourceFile = new File( resourceUrl.getPath() ); + } + else + { + throw new FileNotFoundException( "Unable to find: " + resource ); + } + + return resourceFile; + } +} Index: trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java =================================================================== --- trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java (revision 0) +++ trunk/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java (revision 0) @@ -0,0 +1,44 @@ +package org.apache.maven.model.io.xpp3; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.InputStreamReader; + +import org.apache.maven.model.Model; + +public class MavenXpp3ReaderTest extends AbstractMavenModelTestCase { + + /** + * This test case will not fail, because 8bit encodings won't corrupt the parser. + * @throws Exception + */ + public void testISOEncodedModel() throws Exception { + File f = getFileForClasspathResource( "iso-8859-15-encoded-pom.xml" ); + MavenXpp3Reader reader = new MavenXpp3Reader(); + + Model model = reader.read( new InputStreamReader( new FileInputStream( f ), "ISO-8859-15" ) ); + assertEquals( "öäüß", model.getDescription() ); + + model = reader.read( new FileReader( f ) ); + assertEquals( "öäüß", model.getDescription() ); + } + + /** + * This test case WILL FAIL, because FileReader-instances cannot cope with UTF-8 encoded files. + * Maven uses FileReaders by default to read POMs. + * @throws Exception + */ + public void testUTFEncodedModel() throws Exception { + File f = getFileForClasspathResource( "utf-8-encoded-pom.xml" ); + MavenXpp3Reader reader = new MavenXpp3Reader(); + + // Here's how to read the POM the right way, by telling the InputStream to use a certain encoding. + Model model = reader.read( new InputStreamReader( new FileInputStream( f ), "UTF-8" ) ); + assertEquals( "öäüß", model.getDescription() ); + + // Here's how Maven reads POMs: THIS TEST WILL FAIL + model = reader.read( new FileReader( f ) ); + assertEquals( "öäüß", model.getDescription() ); + } +} Index: trunk/maven-model/src/test/resources/iso-8859-15-encoded-pom.xml =================================================================== --- trunk/maven-model/src/test/resources/iso-8859-15-encoded-pom.xml (revision 0) +++ trunk/maven-model/src/test/resources/iso-8859-15-encoded-pom.xml (revision 0) @@ -0,0 +1,33 @@ + + + + 4.0.0 + maven + maven-core + Maven + 2.0-SNAPSHOT + öäüß + + + + maven-plexus-plugin + 1.0 + + src/conf/plexus.conf + src/conf/plexus.properties + Continuum + + + + + plexus:runtime + + + ContinuumPro + + + + + + + Index: trunk/maven-model/src/test/resources/utf-8-encoded-pom.xml =================================================================== --- trunk/maven-model/src/test/resources/utf-8-encoded-pom.xml (revision 0) +++ trunk/maven-model/src/test/resources/utf-8-encoded-pom.xml (revision 0) @@ -0,0 +1,33 @@ + + + + 4.0.0 + maven + maven-core + Maven + 2.0-SNAPSHOT + öäüß + + + + maven-plexus-plugin + 1.0 + + src/conf/plexus.conf + src/conf/plexus.properties + Continuum + + + + + plexus:runtime + + + ContinuumPro + + + + + + +