Author: jdcasey
Date: Tue Jun 14 08:11:26 2005
New Revision: 190610

URL: http://svn.apache.org/viewcvs?rev=190610&view=rev
Log:
Fixing code to locate the settings files.

Modified:
    
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java

Modified: 
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java?rev=190610&r1=190609&r2=190610&view=diff
==============================================================================
--- 
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
 (original)
+++ 
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
 Tue Jun 14 08:11:26 2005
@@ -57,8 +57,9 @@
 
     public void initialize()
     {
-        userSettingsFile = getUserSettingsFile();
-        globalSettingsFile = getGlobalSettingsFile();
+        userSettingsFile = getFile( userSettingsPath, "user.home", 
MavenSettingsBuilder.ALT_USER_SETTINGS_XML_LOCATION );
+        
+        globalSettingsFile = getFile( globalSettingsPath, "maven.home", 
MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION );
 
         getLogger().debug( "Building Maven global-level settings from: '" + 
globalSettingsFile.getAbsolutePath() + "'" );
         getLogger().debug( "Building Maven user-level settings from: '" + 
userSettingsFile.getAbsolutePath() + "'" );
@@ -124,38 +125,35 @@
 
         return userSettings;
     }
-
-    private File getUserSettingsFile()
-    {
-        String path = System.getProperty( 
MavenSettingsBuilder.ALT_USER_SETTINGS_XML_LOCATION );
-
-        if ( StringUtils.isEmpty( path ) )
-        {
-            // TODO: This replacing shouldn't be necessary as user.home should 
be in the
-            // context of the container and thus the value would be 
interpolated by Plexus
-            String userHome = System.getProperty( "user.home" );
-
-            path = userSettingsPath.replaceAll( "\\$\\{user.home\\}", userHome 
);
-
-            return new File( path ).getAbsoluteFile();
-        }
-        else
-        {
-            return new File( path ).getAbsoluteFile();
-        }
-    }
-
-    private File getGlobalSettingsFile()
+    
+    private File getFile( String pathPattern, String basedirSysProp, String 
altLocationSysProp )
     {
-        String path = System.getProperty( 
MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION );
+        // 
-------------------------------------------------------------------------------------
+        // Alright, here's the justification for all the regexp wizardry 
below...
+        //
+        // Continuum and other server-like apps may need to locate the 
user-level and 
+        // global-level settings somewhere other than ${user.home} and 
${maven.home},
+        // respectively. Using a simple replacement of these patterns will 
allow them
+        // to specify the absolute path to these files in a customized 
components.xml
+        // file. Ideally, we'd do full pattern-evaluation against the 
sysprops, but this
+        // is a first step. There are several replacements below, in order to 
normalize
+        // 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 ) )
         {
             // TODO: This replacing shouldn't be necessary as user.home should 
be in the
             // context of the container and thus the value would be 
interpolated by Plexus
-            String mavenHome = System.getProperty( "maven.home" );
+            String basedir = System.getProperty( basedirSysProp );
 
-            path = globalSettingsPath.replaceAll( "\\$\\{maven.home\\}", 
mavenHome );
+            basedir = basedir.replaceAll( "\\\\", "/" );
+            
+            path = pathPattern.replaceAll( "\\$\\{" + basedirSysProp + "\\}", 
basedir );
+            path = path.replaceAll( "\\\\", "/" );
+            path = path.replaceAll( "//", "/" );
 
             return new File( path ).getAbsoluteFile();
         }
@@ -164,4 +162,5 @@
             return new File( path ).getAbsoluteFile();
         }
     }
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to