You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/05/20 22:23:28 UTC

[maven] branch MNG-6401 updated (36e0e64 -> 41e220b)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MNG-6401
in repository https://gitbox.apache.org/repos/asf/maven.git.


 discard 36e0e64  [MNG-6401] Cannot interpolate property in proxy port of settings.xml
     new 41e220b  [MNG-6401] Cannot interpolate property in proxy port of settings.xml

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (36e0e64)
            \
             N -- N -- N   refs/heads/MNG-6401 (41e220b)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.

[maven] 01/01: [MNG-6401] Cannot interpolate property in proxy port of settings.xml

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-6401
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 41e220bbc1d8064d8c572141f9c21001d100efd9
Author: KATADA Junya <jk...@gmail.com>
AuthorDate: Tue May 1 18:28:28 2018 +0900

    [MNG-6401] Cannot interpolate property in proxy port of settings.xml
    
    This closes #163
---
 .../settings/building/DefaultSettingsBuilder.java  | 57 +++++++++-------------
 1 file changed, 22 insertions(+), 35 deletions(-)

diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java
index 3cdae7d..cb77e95 100644
--- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java
+++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java
@@ -21,14 +21,13 @@ package org.apache.maven.settings.building;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.maven.building.FileSource;
 import org.apache.maven.building.Source;
+import org.apache.maven.building.StringSource;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.TrackableBase;
 import org.apache.maven.settings.io.SettingsParseException;
@@ -43,6 +42,8 @@ import org.codehaus.plexus.interpolation.InterpolationException;
 import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
 import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
 
 /**
  * Builds the effective settings from a user settings file and/or a global settings file.
@@ -101,8 +102,6 @@ public class DefaultSettingsBuilder
 
         problems.setSource( "" );
 
-        userSettings = interpolate( userSettings, request, problems );
-
         // for the special case of a drive-relative Windows path, make sure it's absolute to save plugins from trouble
         String localRepository = userSettings.getLocalRepository();
         if ( localRepository != null && localRepository.length() > 0 )
@@ -161,6 +160,19 @@ public class DefaultSettingsBuilder
 
         problems.setSource( settingsSource.getLocation() );
 
+        Source interpolatedSettingsSource;
+        try ( XmlStreamReader xmlStreamReader = new XmlStreamReader( settingsSource.getInputStream() ) )
+        {
+            String serializedSettings = IOUtil.toString( xmlStreamReader );
+            interpolatedSettingsSource = new StringSource( interpolate( serializedSettings, request, problems ) );
+        }
+        catch ( IOException e )
+        {
+            problems.add( SettingsProblem.Severity.FATAL, "Non-readable settings " + settingsSource.getLocation()
+                + ": " + e.getMessage(), -1, -1, e );
+            return new Settings();
+        }
+
         Settings settings;
 
         try
@@ -169,13 +181,13 @@ public class DefaultSettingsBuilder
 
             try
             {
-                settings = settingsReader.read( settingsSource.getInputStream(), options );
+                settings = settingsReader.read( interpolatedSettingsSource.getInputStream(), options );
             }
             catch ( SettingsParseException e )
             {
                 options = Collections.singletonMap( SettingsReader.IS_STRICT, Boolean.FALSE );
 
-                settings = settingsReader.read( settingsSource.getInputStream(), options );
+                settings = settingsReader.read( interpolatedSettingsSource.getInputStream(), options );
 
                 problems.add( SettingsProblem.Severity.WARNING, e.getMessage(), e.getLineNumber(), e.getColumnNumber(),
                               e );
@@ -199,22 +211,9 @@ public class DefaultSettingsBuilder
         return settings;
     }
 
-    private Settings interpolate( Settings settings, SettingsBuildingRequest request,
+    private String interpolate( String serializedSettings, SettingsBuildingRequest request,
                                   SettingsProblemCollector problems )
     {
-        StringWriter writer = new StringWriter( 1024 * 4 );
-
-        try
-        {
-            settingsWriter.write( writer, null, settings );
-        }
-        catch ( IOException e )
-        {
-            throw new IllegalStateException( "Failed to serialize settings to memory", e );
-        }
-
-        String serializedSettings = writer.toString();
-
         RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
 
         interpolator.addValueSource( new PropertiesBasedValueSource( request.getUserProperties() ) );
@@ -246,29 +245,17 @@ public class DefaultSettingsBuilder
             }
         } );
 
+        String result;
         try
         {
-            serializedSettings = interpolator.interpolate( serializedSettings, "settings" );
+            result = interpolator.interpolate( serializedSettings, "settings" );
         }
         catch ( InterpolationException e )
         {
             problems.add( SettingsProblem.Severity.ERROR, "Failed to interpolate settings: " + e.getMessage(), -1, -1,
                           e );
 
-            return settings;
-        }
-
-        Settings result;
-        try
-        {
-            Map<String, ?> options = Collections.singletonMap( SettingsReader.IS_STRICT, Boolean.FALSE );
-            result = settingsReader.read( new StringReader( serializedSettings ), options );
-        }
-        catch ( IOException e )
-        {
-            problems.add( SettingsProblem.Severity.ERROR, "Failed to interpolate settings: " + e.getMessage(), -1, -1,
-                          e );
-            return settings;
+            return serializedSettings;
         }
 
         return result;

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.