maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r585268 - in /maven/components/branches/maven-2.0.x: bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/ maven-core/src/main/java/org/apache/maven/plugin/version/ maven-plugin-registry/src/main/java/org/apache/maven/...
Date Tue, 16 Oct 2007 21:43:08 GMT
Author: hboutemy
Date: Tue Oct 16 14:43:07 2007
New Revision: 585268

URL: http://svn.apache.org/viewvc?rev=585268&view=rev
Log:
[MNG-2254] support XML file encoding when reading/writing settings and pom files

Modified:
    maven/components/branches/maven-2.0.x/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java
    maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
    maven/components/branches/maven-2.0.x/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java
    maven/components/branches/maven-2.0.x/maven-profile/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
    maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java
    maven/components/branches/maven-2.0.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java

Modified: maven/components/branches/maven-2.0.x/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java
(original)
+++ maven/components/branches/maven-2.0.x/bootstrap/bootstrap-mini/src/main/java/org/apache/maven/bootstrap/download/RepositoryMetadata.java
Tue Oct 16 14:43:07 2007
@@ -23,8 +23,9 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.text.DateFormat;
 import java.text.ParseException;
@@ -177,13 +178,13 @@
         }
         return baseVersion;
     }
-    
+
     public long getLastUpdatedUtc()
     {
         TimeZone timezone = TimeZone.getTimeZone( "UTC" );
         DateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss" );
         fmt.setTimeZone( timezone );
-        
+
         try
         {
             return fmt.parse( lastUpdated ).getTime();
@@ -345,7 +346,7 @@
         public void write( File file )
             throws IOException
         {
-            PrintWriter w = new PrintWriter( new FileWriter( file ) );
+            PrintWriter w = new PrintWriter( new OutputStreamWriter( new FileOutputStream(
file ), "UTF-8" ) );
 
             try
             {

Modified: maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java
Tue Oct 16 14:43:07 2007
@@ -48,11 +48,12 @@
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.Writer;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -599,12 +600,12 @@
         // only rewrite the user-level registry if one existed before, or if we've created
user-level data here.
         if ( extractedUserRegistry != null )
         {
-            FileWriter fWriter = null;
+            Writer fWriter = null;
 
             try
             {
                 pluginRegistryFile.getParentFile().mkdirs();
-                fWriter = new FileWriter( pluginRegistryFile );
+                fWriter = WriterFactory.newXmlWriter( pluginRegistryFile );
 
                 PluginRegistryXpp3Writer writer = new PluginRegistryXpp3Writer();
 

Modified: maven/components/branches/maven-2.0.x/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java
Tue Oct 16 14:43:07 2007
@@ -23,12 +23,13 @@
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 
 public class DefaultPluginRegistryBuilder
     extends AbstractLogEnabled
@@ -69,19 +70,19 @@
             getLogger().debug( "Building Maven global-level plugin registry from: '" + globalRegistryFile.getAbsolutePath()
+ "'" );
         }
     }
-    
+
     public PluginRegistry buildPluginRegistry()
         throws IOException, XmlPullParserException
     {
         PluginRegistry global = readPluginRegistry( globalRegistryFile );
-        
+
         PluginRegistry user = readPluginRegistry( userRegistryFile );
 
         if ( user == null && global != null )
         {
             // we'll use the globals, but first we have to recursively mark them as global...
             PluginRegistryUtils.recursivelySetSourceLevel( global, PluginRegistry.GLOBAL_LEVEL
);
-            
+
             user = global;
         }
         else
@@ -100,19 +101,19 @@
 
         if ( registryFile != null && registryFile.exists() && registryFile.isFile()
)
         {
-            FileReader reader = null;
+            Reader reader = null;
             try
             {
-                reader = new FileReader( registryFile );
+                reader = ReaderFactory.newXmlReader( registryFile );
 
                 PluginRegistryXpp3Reader modelReader = new PluginRegistryXpp3Reader();
 
                 registry = modelReader.read( reader );
-                
+
                 RuntimeInfo rtInfo = new RuntimeInfo( registry );
-                
+
                 registry.setRuntimeInfo( rtInfo );
-                
+
                 rtInfo.setFile( registryFile );
             }
             finally
@@ -138,7 +139,7 @@
         // the path character before we operate on the string as a regex input, and 
         // in order to avoid surprises with the File construction...
         // -------------------------------------------------------------------------------------
-        
+
         String path = System.getProperty( altLocationSysProp );
 
         if ( StringUtils.isEmpty( path ) )
@@ -149,7 +150,7 @@
 
             basedir = basedir.replaceAll( "\\\\", "/" );
             basedir = basedir.replaceAll("\\$", "\\\\\\$");
-            
+
             path = pathPattern.replaceAll( "\\$\\{" + basedirSysProp + "\\}", basedir );
             path = path.replaceAll( "\\\\", "/" );
             path = path.replaceAll( "//", "/" );
@@ -165,14 +166,14 @@
     public PluginRegistry createUserPluginRegistry()
     {
         PluginRegistry registry = new PluginRegistry();
-        
+
         RuntimeInfo rtInfo = new RuntimeInfo( registry );
-        
+
         registry.setRuntimeInfo( rtInfo );
-        
+
         rtInfo.setFile( userRegistryFile );
-        
+
         return registry;
     }
-    
+
 }

Modified: maven/components/branches/maven-2.0.x/maven-profile/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-profile/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-profile/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-profile/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
Tue Oct 16 14:43:07 2007
@@ -22,13 +22,14 @@
 import org.apache.maven.profiles.io.xpp3.ProfilesXpp3Reader;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.interpolation.EnvarBasedValueSource;
 import org.codehaus.plexus.util.interpolation.RegexBasedInterpolator;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 
@@ -48,22 +49,22 @@
         if ( profilesXml.exists() )
         {
             ProfilesXpp3Reader reader = new ProfilesXpp3Reader();
-            FileReader fileReader = null;
+            Reader profileReader = null;
             try
             {
-                fileReader = new FileReader( profilesXml );
-                
+                profileReader = ReaderFactory.newXmlReader( profilesXml );
+
                 StringWriter sWriter = new StringWriter();
-                
-                IOUtil.copy( fileReader, sWriter );
-                
+
+                IOUtil.copy( profileReader, sWriter );
+
                 String rawInput = sWriter.toString();
-                
+
                 try
                 {
                     RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
                     interpolator.addValueSource( new EnvarBasedValueSource() );
-                    
+
                     rawInput = interpolator.interpolate( rawInput, "settings" );
                 }
                 catch ( Exception e )
@@ -78,7 +79,7 @@
             }
             finally
             {
-                IOUtil.close( fileReader );
+                IOUtil.close( profileReader );
             }
         }
 

Modified: maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
Tue Oct 16 14:43:07 2007
@@ -76,16 +76,14 @@
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringReader;
-import java.io.StringWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -134,8 +132,7 @@
 */
 
 /**
- * @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22
- *          trygvis Exp $
+ * @version $Id$
  */
 public class DefaultMavenProjectBuilder
     extends AbstractLogEnabled
@@ -1376,7 +1373,7 @@
         Reader reader = null;
         try
         {
-            reader = new FileReader( file );
+            reader = ReaderFactory.newXmlReader( file );
             return readModel( projectId, file.getAbsolutePath(), reader, strict );
         }
         catch ( FileNotFoundException e )
@@ -1401,15 +1398,11 @@
                              boolean strict )
         throws IOException, InvalidProjectModelException
     {
-        StringWriter sw = new StringWriter();
+        String modelSource = IOUtil.toString( reader );
 
-        IOUtil.copy( reader, sw );
-
-        String modelSource = sw.toString();
-
-        if ( modelSource.indexOf( "<modelVersion>4.0.0" ) < 0 )
+        if ( modelSource.indexOf( "<modelVersion>" + MAVEN_MODEL_VERSION ) < 0 )
         {
-            throw new InvalidProjectModelException( projectId, pomLocation, "Not a v4.0.0
POM." );
+            throw new InvalidProjectModelException( projectId, pomLocation, "Not a v" + MAVEN_MODEL_VERSION
 + " POM." );
         }
 
         StringReader sReader = new StringReader( modelSource );
@@ -1430,10 +1423,10 @@
                              boolean strict )
         throws ProjectBuildingException
     {
-        InputStreamReader reader = null;
+        Reader reader = null;
         try
         {
-            reader = new InputStreamReader( url.openStream() );
+            reader = ReaderFactory.newXmlReader( url.openStream() );
             return readModel( projectId, url.toExternalForm(), reader, strict );
         }
         catch ( IOException e )

Modified: maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java
Tue Oct 16 14:43:07 2007
@@ -22,8 +22,8 @@
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.project.AbstractMavenProjectTestCase;
+import org.codehaus.plexus.util.ReaderFactory;
 
-import java.io.FileReader;
 import java.io.Reader;
 import java.util.List;
 
@@ -219,7 +219,7 @@
     private ModelValidationResult validate( String testName )
         throws Exception
     {
-        Reader input = new FileReader( getFileForClasspathResource( "validation/" + testName
) );
+        Reader input = ReaderFactory.newXmlReader( getFileForClasspathResource( "validation/"
+ testName ) );
 
         MavenXpp3Reader reader = new MavenXpp3Reader();
 

Modified: maven/components/branches/maven-2.0.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java?rev=585268&r1=585267&r2=585268&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
Tue Oct 16 14:43:07 2007
@@ -23,14 +23,15 @@
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.interpolation.EnvarBasedValueSource;
 import org.codehaus.plexus.util.interpolation.RegexBasedInterpolator;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Iterator;
@@ -90,10 +91,10 @@
 
         if ( settingsFile.exists() && settingsFile.isFile() )
         {
-            FileReader reader = null;
+            Reader reader = null;
             try
             {
-                reader = new FileReader( settingsFile );
+                reader = ReaderFactory.newXmlReader( settingsFile );
                 StringWriter sWriter = new StringWriter();
 
                 IOUtil.copy( reader, sWriter );



Mime
View raw message