mirror of https://github.com/apache/maven.git
o Moving the logging statement to initialize() to make the component less
verbose. o Moving the default settings path value to plexus.xml (and components.xml). o Setting the correct license and adding @version tags. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d3781103e8
commit
80b1b94fd3
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.settings;
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
/*
|
||||
* 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.
|
||||
|
@ -14,85 +14,88 @@ package org.apache.maven.settings;
|
|||
* 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 org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DefaultMavenSettingsBuilder
|
||||
extends AbstractLogEnabled
|
||||
implements MavenSettingsBuilder
|
||||
implements MavenSettingsBuilder, Initializable
|
||||
{
|
||||
/** @configuration */
|
||||
private String settingsPath;
|
||||
|
||||
private static final String DEFAULT_SETTINGS_PATH = "${user.home}/.m2/settings.xml";
|
||||
private File settingsFile;
|
||||
|
||||
private String settingsPath = DEFAULT_SETTINGS_PATH;
|
||||
// ----------------------------------------------------------------------
|
||||
// Component Lifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void initialize()
|
||||
throws Exception
|
||||
{
|
||||
settingsFile = getSettingsFile();
|
||||
|
||||
getLogger().debug( "Building Maven settings from: '" + settingsFile.getAbsolutePath() + "'" );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// MavenSettingsBuilder Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// TODO: don't throw Exception.
|
||||
public MavenSettings buildSettings() throws Exception
|
||||
public MavenSettings buildSettings()
|
||||
throws Exception
|
||||
{
|
||||
MavenSettings settings = null;
|
||||
|
||||
File modelFile = getSettingsFile();
|
||||
if ( modelFile.exists() && modelFile.isFile() )
|
||||
if ( settingsFile.exists() && settingsFile.isFile() )
|
||||
{
|
||||
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( modelFile );
|
||||
reader = new FileReader( settingsFile );
|
||||
|
||||
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
|
||||
|
||||
Settings model = modelReader.read( reader );
|
||||
settings = new MavenSettings( model );
|
||||
|
||||
return new MavenSettings( model );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( reader != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.close();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( settings == null )
|
||||
else
|
||||
{
|
||||
getLogger().debug( "Settings model not found. Creating empty instance of MavenSettings." );
|
||||
settings = new MavenSettings();
|
||||
}
|
||||
|
||||
return settings;
|
||||
return new MavenSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private File getSettingsFile()
|
||||
{
|
||||
String userDir = System.getProperty( "user.home" );
|
||||
userDir = userDir.replaceAll( "\\\\", "/" );
|
||||
|
||||
String path = settingsPath;
|
||||
|
||||
path = path.replaceAll( "\\$\\{user.home\\}", userDir );
|
||||
// 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 = path.replaceAll( "\\$\\{user.home\\}", userHome );
|
||||
path = path.replaceAll( "\\\\", "/" );
|
||||
path = path.replaceAll( "//", "/" );
|
||||
|
||||
File userModelFile = new File( path );
|
||||
|
||||
getLogger().debug( "Using userModel configured from: " + userModelFile );
|
||||
|
||||
return userModelFile;
|
||||
return new File( path );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package org.apache.maven.settings;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
/*
|
||||
* 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.
|
||||
|
@ -17,22 +14,24 @@ import java.util.List;
|
|||
* 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.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MavenSettings
|
||||
{
|
||||
|
||||
private static final String DEFAULT_LOCAL_REPOSITORY = "/.m2/repository";
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
public MavenSettings()
|
||||
{
|
||||
this.settings = new Settings();
|
||||
settings = new Settings();
|
||||
|
||||
Profile profile = new Profile();
|
||||
profile.setActive( true );
|
||||
|
@ -40,7 +39,7 @@ public class MavenSettings
|
|||
String userHome = System.getProperty( "user.home" );
|
||||
profile.setLocalRepository( userHome + DEFAULT_LOCAL_REPOSITORY );
|
||||
|
||||
this.settings.addProfile( profile );
|
||||
settings.addProfile( profile );
|
||||
}
|
||||
|
||||
public MavenSettings( Settings settings )
|
||||
|
@ -126,5 +125,4 @@ public class MavenSettings
|
|||
|
||||
return active;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.apache.maven.settings;
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
/*
|
||||
* 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.
|
||||
|
@ -14,18 +14,17 @@ package org.apache.maven.settings;
|
|||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface MavenSettingsBuilder
|
||||
{
|
||||
|
||||
public static final String ROLE = MavenSettingsBuilder.class.getName();
|
||||
String ROLE = MavenSettingsBuilder.class.getName();
|
||||
|
||||
// TODO: Don't throw Exception.
|
||||
MavenSettings buildSettings() throws Exception;
|
||||
|
||||
MavenSettings buildSettings()
|
||||
throws Exception;
|
||||
}
|
||||
|
|
|
@ -256,6 +256,9 @@
|
|||
<component>
|
||||
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
|
||||
<implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation>
|
||||
<configuration>
|
||||
<settingsPath>${user.home}/.m2/settings.xml</settingsPath>
|
||||
</configuration>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
<component>
|
||||
<role>org.apache.maven.settings.MavenSettingsBuilder</role>
|
||||
<implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation>
|
||||
<configuration>
|
||||
<settingsPath>${user.home}/.m2/settings.xml</settingsPath>
|
||||
</configuration>
|
||||
</component>
|
||||
</components>
|
||||
</plexus>
|
||||
|
|
Loading…
Reference in New Issue