Fixing code to locate the settings files.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-14 15:11:26 +00:00
parent 140e01d80a
commit fc378a7ade
1 changed files with 26 additions and 27 deletions

View File

@ -57,8 +57,9 @@ public class DefaultMavenSettingsBuilder
public void initialize() public void initialize()
{ {
userSettingsFile = getUserSettingsFile(); userSettingsFile = getFile( userSettingsPath, "user.home", MavenSettingsBuilder.ALT_USER_SETTINGS_XML_LOCATION );
globalSettingsFile = getGlobalSettingsFile();
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 global-level settings from: '" + globalSettingsFile.getAbsolutePath() + "'" );
getLogger().debug( "Building Maven user-level settings from: '" + userSettingsFile.getAbsolutePath() + "'" ); getLogger().debug( "Building Maven user-level settings from: '" + userSettingsFile.getAbsolutePath() + "'" );
@ -125,17 +126,34 @@ public Settings buildSettings()
return userSettings; return userSettings;
} }
private File getUserSettingsFile() private File getFile( String pathPattern, String basedirSysProp, String altLocationSysProp )
{ {
String path = System.getProperty( MavenSettingsBuilder.ALT_USER_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 ) ) if ( StringUtils.isEmpty( path ) )
{ {
// TODO: This replacing shouldn't be necessary as user.home should be in the // 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 // context of the container and thus the value would be interpolated by Plexus
String userHome = System.getProperty( "user.home" ); String basedir = System.getProperty( basedirSysProp );
path = userSettingsPath.replaceAll( "\\$\\{user.home\\}", userHome ); basedir = basedir.replaceAll( "\\\\", "/" );
path = pathPattern.replaceAll( "\\$\\{" + basedirSysProp + "\\}", basedir );
path = path.replaceAll( "\\\\", "/" );
path = path.replaceAll( "//", "/" );
return new File( path ).getAbsoluteFile(); return new File( path ).getAbsoluteFile();
} }
@ -145,23 +163,4 @@ private File getUserSettingsFile()
} }
} }
private File getGlobalSettingsFile()
{
String path = System.getProperty( MavenSettingsBuilder.ALT_GLOBAL_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 mavenHome = System.getProperty( "maven.home" );
path = globalSettingsPath.replaceAll( "\\$\\{maven.home\\}", mavenHome );
return new File( path ).getAbsoluteFile();
}
else
{
return new File( path ).getAbsoluteFile();
}
}
} }