trygvis 2005/03/29 09:06:30
Modified: maven-core/src/main/java/org/apache/maven/settings
DefaultMavenSettingsBuilder.java MavenSettings.java
MavenSettingsBuilder.java
maven-core/src/main/resources/META-INF/plexus components.xml
plexus.xml
Log:
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.
Revision Changes Path
1.3 +57 -54
maven-components/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
Index: DefaultMavenSettingsBuilder.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultMavenSettingsBuilder.java 17 Mar 2005 06:07:46 -0000 1.2
+++ DefaultMavenSettingsBuilder.java 29 Mar 2005 17:06:30 -0000 1.3
@@ -1,98 +1,101 @@
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.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * 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.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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 File settingsFile;
- private static final String DEFAULT_SETTINGS_PATH =
"${user.home}/.m2/settings.xml";
-
- 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.2 +18 -20
maven-components/maven-core/src/main/java/org/apache/maven/settings/MavenSettings.java
Index: MavenSettings.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/settings/MavenSettings.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenSettings.java 16 Mar 2005 06:29:34 -0000 1.1
+++ MavenSettings.java 29 Mar 2005 17:06:30 -0000 1.2
@@ -1,38 +1,37 @@
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.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * 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.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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 @@
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 @@
return active;
}
-
-}
\ No newline at end of file
+}
1.2 +16 -17
maven-components/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
Index: MavenSettingsBuilder.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenSettingsBuilder.java 16 Mar 2005 06:29:34 -0000 1.1
+++ MavenSettingsBuilder.java 29 Mar 2005 17:06:30 -0000 1.2
@@ -1,31 +1,30 @@
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.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * 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.
- * ====================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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();
-
- // TODO: Don't throw Exception.
- MavenSettings buildSettings() throws Exception;
+ String ROLE = MavenSettingsBuilder.class.getName();
+ // TODO: Don't throw Exception.
+ MavenSettings buildSettings()
+ throws Exception;
}
1.26 +5 -2
maven-components/maven-core/src/main/resources/META-INF/plexus/components.xml
Index: components.xml
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/resources/META-INF/plexus/components.xml,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- components.xml 18 Mar 2005 11:32:39 -0000 1.25
+++ components.xml 29 Mar 2005 17:06:30 -0000 1.26
@@ -121,7 +121,7 @@
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
</component>
-
+
<!--
|
| Lifecycle executor
@@ -233,7 +233,7 @@
</configuration>
</component>
<!-- ********************* FIXME
*******************************************
- | I realize this is duplicated but allows the project builder to work
by itself
+ | I realize this is duplicated but allows the project builder to work
by itself
-->
<component>
<role>org.apache.maven.project.path.PathTranslator</role>
@@ -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>
1.9 +3 -0
maven-components/maven-core/src/main/resources/META-INF/plexus/plexus.xml
Index: plexus.xml
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/resources/META-INF/plexus/plexus.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- plexus.xml 22 Mar 2005 10:46:55 -0000 1.8
+++ plexus.xml 29 Mar 2005 17:06:30 -0000 1.9
@@ -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>