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:
Trygve Laugstol 2005-03-29 17:06:30 +00:00
parent d3781103e8
commit 80b1b94fd3
5 changed files with 101 additions and 95 deletions

View File

@ -1,7 +1,7 @@
package org.apache.maven.settings; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.File;
import java.io.FileReader; 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 * @author jdcasey
* @version $Id$
*/ */
public class DefaultMavenSettingsBuilder public class DefaultMavenSettingsBuilder
extends AbstractLogEnabled 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. // TODO: don't throw Exception.
public MavenSettings buildSettings() throws Exception public MavenSettings buildSettings()
throws Exception
{ {
MavenSettings settings = null; if ( settingsFile.exists() && settingsFile.isFile() )
File modelFile = getSettingsFile();
if ( modelFile.exists() && modelFile.isFile() )
{ {
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
FileReader reader = null; FileReader reader = null;
try try
{ {
reader = new FileReader( modelFile ); reader = new FileReader( settingsFile );
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
Settings model = modelReader.read( reader ); Settings model = modelReader.read( reader );
settings = new MavenSettings( model );
return new MavenSettings( model );
} }
finally finally
{ {
if ( reader != null ) IOUtil.close( reader );
{
try
{
reader.close();
}
catch ( IOException e )
{
} }
} }
} else
}
if ( settings == null )
{ {
getLogger().debug( "Settings model not found. Creating empty instance of MavenSettings." ); getLogger().debug( "Settings model not found. Creating empty instance of MavenSettings." );
settings = new MavenSettings();
}
return settings; return new MavenSettings();
}
} }
private File getSettingsFile() private File getSettingsFile()
{ {
String userDir = System.getProperty( "user.home" );
userDir = userDir.replaceAll( "\\\\", "/" );
String path = settingsPath; 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( "\\\\", "/" );
path = path.replaceAll( "//", "/" ); path = path.replaceAll( "//", "/" );
File userModelFile = new File( path ); return new File( path );
getLogger().debug( "Using userModel configured from: " + userModelFile );
return userModelFile;
} }
} }

View File

@ -1,10 +1,7 @@
package org.apache.maven.settings; package org.apache.maven.settings;
import java.util.Iterator; /*
import java.util.List; * Copyright 2001-2005 The Apache Software Foundation.
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ====================================================================
*/ */
import java.util.Iterator;
import java.util.List;
/** /**
* @author jdcasey * @author jdcasey
* @version $Id$
*/ */
public class MavenSettings public class MavenSettings
{ {
private static final String DEFAULT_LOCAL_REPOSITORY = "/.m2/repository"; private static final String DEFAULT_LOCAL_REPOSITORY = "/.m2/repository";
private final Settings settings; private final Settings settings;
public MavenSettings() public MavenSettings()
{ {
this.settings = new Settings(); settings = new Settings();
Profile profile = new Profile(); Profile profile = new Profile();
profile.setActive( true ); profile.setActive( true );
@ -40,7 +39,7 @@ public class MavenSettings
String userHome = System.getProperty( "user.home" ); String userHome = System.getProperty( "user.home" );
profile.setLocalRepository( userHome + DEFAULT_LOCAL_REPOSITORY ); profile.setLocalRepository( userHome + DEFAULT_LOCAL_REPOSITORY );
this.settings.addProfile( profile ); settings.addProfile( profile );
} }
public MavenSettings( Settings settings ) public MavenSettings( Settings settings )
@ -126,5 +125,4 @@ public class MavenSettings
return active; return active;
} }
} }

View File

@ -1,7 +1,7 @@
package org.apache.maven.settings; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* ====================================================================
*/ */
/** /**
* @author jdcasey * @author jdcasey
* @version $Id$
*/ */
public interface MavenSettingsBuilder public interface MavenSettingsBuilder
{ {
String ROLE = MavenSettingsBuilder.class.getName();
public static final String ROLE = MavenSettingsBuilder.class.getName();
// TODO: Don't throw Exception. // TODO: Don't throw Exception.
MavenSettings buildSettings() throws Exception; MavenSettings buildSettings()
throws Exception;
} }

View File

@ -256,6 +256,9 @@
<component> <component>
<role>org.apache.maven.settings.MavenSettingsBuilder</role> <role>org.apache.maven.settings.MavenSettingsBuilder</role>
<implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation> <implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation>
<configuration>
<settingsPath>${user.home}/.m2/settings.xml</settingsPath>
</configuration>
</component> </component>
</components> </components>
</component-set> </component-set>

View File

@ -46,6 +46,9 @@
<component> <component>
<role>org.apache.maven.settings.MavenSettingsBuilder</role> <role>org.apache.maven.settings.MavenSettingsBuilder</role>
<implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation> <implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation>
<configuration>
<settingsPath>${user.home}/.m2/settings.xml</settingsPath>
</configuration>
</component> </component>
</components> </components>
</plexus> </plexus>