Author: jdcasey
Date: Mon Jun 13 14:56:00 2005
New Revision: 190517
URL: http://svn.apache.org/viewcvs?rev=190517&view=rev
Log:
o Re-adding support for user-level settings which are not assumed to be in ~
(for continuum and other server-style apps' convenience)
o Adding support for global (installation-level) settings.xml file which is
identical to the one in ~/.m2, and which will be overridden by user-level
settings. The default location for this is ${maven.home}/settings.xml.
o Adding IT to test merging of global- and user-level settings.xml files
o Moved DefaultMavenSettingsBuilder/MavenSettingsBuilder to maven-settings
project, to make them more generally available (to ant, for instance)
Resolves issue: MNG-294
Added:
maven/components/trunk/maven-core-it/it0026/
maven/components/trunk/maven-core-it/it0026/expected-results.txt (with
props)
maven/components/trunk/maven-core-it/it0026/global-settings.xml (with
props)
maven/components/trunk/maven-core-it/it0026/goals.txt (with props)
maven/components/trunk/maven-core-it/it0026/pom.xml (with props)
maven/components/trunk/maven-core-it/it0026/src/
maven/components/trunk/maven-core-it/it0026/src/main/
maven/components/trunk/maven-core-it/it0026/src/main/java/
maven/components/trunk/maven-core-it/it0026/src/main/java/org/
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java
(with props)
maven/components/trunk/maven-core-it/it0026/system.properties (with props)
maven/components/trunk/maven-core-it/it0026/user-settings.xml (with props)
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
- copied, changed from r190399,
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
- copied, changed from r190399,
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java
- copied, changed from r190399,
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsConversionUtils.java
maven/components/trunk/maven-settings/src/main/resources/
maven/components/trunk/maven-settings/src/main/resources/META-INF/
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
(with props)
Removed:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsConversionUtils.java
Modified:
maven/components/trunk/maven-core-it/README.txt
maven/components/trunk/maven-core-it/integration-tests.txt
maven/components/trunk/maven-core-it/it0023/system.properties
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
maven/components/trunk/maven-settings/pom.xml
maven/components/trunk/maven-settings/settings.mdo
Modified: maven/components/trunk/maven-core-it/README.txt
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Mon Jun 13 14:56:00 2005
@@ -81,6 +81,8 @@
it0025: Test multiple goal executions with different execution-level configs.
+it0026: Test merging of global- and user-level settings.xml files.
+
-------------------------------------------------------------------------------
- generated sources
Modified: maven/components/trunk/maven-core-it/integration-tests.txt
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/integration-tests.txt?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/integration-tests.txt (original)
+++ maven/components/trunk/maven-core-it/integration-tests.txt Mon Jun 13
14:56:00 2005
@@ -24,3 +24,4 @@
it0023
it0024
it0025
+it0026
Modified: maven/components/trunk/maven-core-it/it0023/system.properties
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0023/system.properties?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/it0023/system.properties (original)
+++ maven/components/trunk/maven-core-it/it0023/system.properties Mon Jun 13
14:56:00 2005
@@ -1 +1 @@
-org.apache.maven.SettingsXmlFile=settings.xml
+org.apache.maven.user-settings=settings.xml
Added: maven/components/trunk/maven-core-it/it0026/expected-results.txt
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/expected-results.txt?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/expected-results.txt (added)
+++ maven/components/trunk/maven-core-it/it0026/expected-results.txt Mon Jun 13
14:56:00 2005
@@ -0,0 +1 @@
+target/test.txt
Propchange: maven/components/trunk/maven-core-it/it0026/expected-results.txt
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Added: maven/components/trunk/maven-core-it/it0026/global-settings.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/global-settings.xml?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/global-settings.xml (added)
+++ maven/components/trunk/maven-core-it/it0026/global-settings.xml Mon Jun 13
14:56:00 2005
@@ -0,0 +1,17 @@
+<settings>
+ <profiles>
+ <profile>
+ <id>test-profile</id>
+
+ <activation>
+ <property>
+ <name>includeProfile</name>
+ </property>
+ </activation>
+
+ <properties>
+ <test>test.txt</test>
+ </properties>
+ </profile>
+ </profiles>
+</settings>
Propchange: maven/components/trunk/maven-core-it/it0026/global-settings.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Propchange: maven/components/trunk/maven-core-it/it0026/global-settings.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: maven/components/trunk/maven-core-it/it0026/goals.txt
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/goals.txt?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/goals.txt (added)
+++ maven/components/trunk/maven-core-it/it0026/goals.txt Mon Jun 13 14:56:00
2005
@@ -0,0 +1 @@
+core-it:touch
\ No newline at end of file
Propchange: maven/components/trunk/maven-core-it/it0026/goals.txt
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Added: maven/components/trunk/maven-core-it/it0026/pom.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/pom.xml?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/pom.xml (added)
+++ maven/components/trunk/maven-core-it/it0026/pom.xml Mon Jun 13 14:56:00 2005
@@ -0,0 +1,24 @@
+<model>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.</groupId>
+ <artifactId>maven-it0023</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-core-it-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <configuration>
+ <pluginItem>${test}</pluginItem>
+ </configuration>
+ </plugin>
+ <!-- plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-projecthelp-plugin</artifactId>
+ <version>2.0-alpha-3-SNAPSHOT</version>
+ </plugin -->
+ </plugins>
+ </build>
+</model>
Propchange: maven/components/trunk/maven-core-it/it0026/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Propchange: maven/components/trunk/maven-core-it/it0026/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java?rev=190517&view=auto
==============================================================================
---
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java
(added)
+++
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java
Mon Jun 13 14:56:00 2005
@@ -0,0 +1,16 @@
+package org.apache.maven.it0023;
+
+public class Person
+{
+ private String name;
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Propchange:
maven/components/trunk/maven-core-it/it0026/src/main/java/org/apache/maven/it0023/Person.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Added: maven/components/trunk/maven-core-it/it0026/system.properties
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/system.properties?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/system.properties (added)
+++ maven/components/trunk/maven-core-it/it0026/system.properties Mon Jun 13
14:56:00 2005
@@ -0,0 +1,2 @@
+org.apache.maven.user-settings=user-settings.xml
+org.apache.maven.global-settings=global-settings.xml
Propchange: maven/components/trunk/maven-core-it/it0026/system.properties
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Added: maven/components/trunk/maven-core-it/it0026/user-settings.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/it0026/user-settings.xml?rev=190517&view=auto
==============================================================================
--- maven/components/trunk/maven-core-it/it0026/user-settings.xml (added)
+++ maven/components/trunk/maven-core-it/it0026/user-settings.xml Mon Jun 13
14:56:00 2005
@@ -0,0 +1,5 @@
+<settings>
+ <activeProfiles>
+ <activeProfile>test-profile</activeProfile>
+ </activeProfiles>
+</settings>
Propchange: maven/components/trunk/maven-core-it/it0026/user-settings.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Propchange: maven/components/trunk/maven-core-it/it0026/user-settings.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
(original)
+++
maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Mon Jun 13 14:56:00 2005
@@ -41,7 +41,7 @@
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
-import org.apache.maven.settings.SettingsConversionUtils;
+import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.usability.ErrorDiagnoser;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
@@ -336,7 +336,7 @@
{
org.apache.maven.settings.Profile rawProfile =
(org.apache.maven.settings.Profile) it.next();
- Profile profile =
SettingsConversionUtils.convertFromSettingsProfile( rawProfile );
+ Profile profile = SettingsUtils.convertFromSettingsProfile(
rawProfile );
if( settingsActiveProfileIds.contains( rawProfile.getId() ) )
{
Modified: maven/components/trunk/maven-settings/pom.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/pom.xml?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
--- maven/components/trunk/maven-settings/pom.xml (original)
+++ maven/components/trunk/maven-settings/pom.xml Mon Jun 13 14:56:00 2005
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
- <version>1.0-alpha-3-SNAPSHOT</version>
+ <version>1.0-alpha-2</version>
<goals>
<goal>
<id>xpp3-writer</id>
Modified: maven/components/trunk/maven-settings/settings.mdo
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/settings.mdo?rev=190517&r1=190516&r2=190517&view=diff
==============================================================================
--- maven/components/trunk/maven-settings/settings.mdo (original)
+++ maven/components/trunk/maven-settings/settings.mdo Mon Jun 13 14:56:00 2005
@@ -125,6 +125,11 @@
<version>1.0.0</version>
<code><![CDATA[
private Proxy activeProxy;
+
+ public void flushActiveProxy()
+ {
+ this.activeProxy = null;
+ }
public synchronized Proxy getActiveProxy()
{
@@ -155,6 +160,102 @@
return activeProxy;
}
+
+ private Map mirrorMap;
+
+ public void flushMirrorMap()
+ {
+ this.mirrorMap = null;
+ }
+
+ public Map getMirrorsAsMap()
+ {
+ if ( mirrorMap == null )
+ {
+ mirrorMap = new HashMap();
+
+ for ( Iterator it = getMirrors().iterator(); it.hasNext(); )
+ {
+ Mirror mirror = (Mirror) it.next();
+
+ mirrorMap.put( mirror.getId(), mirror );
+ }
+ }
+
+ return mirrorMap;
+ }
+
+ private Map serverMap;
+
+ public void flushServerMap()
+ {
+ this.serverMap = null;
+ }
+
+ public Map getServersAsMap()
+ {
+ if ( serverMap == null )
+ {
+ serverMap = new HashMap();
+
+ for ( Iterator it = getServers().iterator(); it.hasNext(); )
+ {
+ Server server = (Server) it.next();
+
+ serverMap.put( server.getId(), server );
+ }
+ }
+
+ return serverMap;
+ }
+
+ private Map proxyMap;
+
+ public void flushProxyMap()
+ {
+ this.proxyMap = null;
+ }
+
+ public Map getProxiesAsMap()
+ {
+ if ( proxyMap == null )
+ {
+ proxyMap = new HashMap();
+
+ for ( Iterator it = getProxies().iterator(); it.hasNext(); )
+ {
+ Proxy proxy = (Proxy) it.next();
+
+ proxyMap.put( proxy.getId(), proxy );
+ }
+ }
+
+ return proxyMap;
+ }
+
+ private Map profileMap;
+
+ public void flushProfileMap()
+ {
+ this.profileMap = null;
+ }
+
+ public Map getProfilesAsMap()
+ {
+ if ( profileMap == null )
+ {
+ profileMap = new HashMap();
+
+ for ( Iterator it = getProfiles().iterator(); it.hasNext(); )
+ {
+ Profile profile = (Profile) it.next();
+
+ profileMap.put( profile.getId(), profile );
+ }
+ }
+
+ return profileMap;
+ }
public Server getServer( String serverId )
{
@@ -236,6 +337,12 @@
<name>Proxy</name>
<version>1.0.0</version>
<fields>
+ <field>
+ <name>id</name>
+ <required>true</required>
+ <default>default</default>
+ <type>String</type>
+ </field>
<field>
<name>active</name>
<version>1.0.0</version>
Copied:
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
(from r190399,
maven/components/trunk/maven-core/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?p2=maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java&p1=maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java&r1=190399&r2=190517&rev=190517&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
(original)
+++
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
Mon Jun 13 14:56:00 2005
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
@@ -25,7 +24,6 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@@ -42,9 +40,16 @@
/**
* @configuration
*/
- private String settingsPath;
+ private String userSettingsPath;
- private File settingsFile;
+ /**
+ * @configuration
+ */
+ private String globalSettingsPath;
+
+ private File userSettingsFile;
+
+ private File globalSettingsFile;
// ----------------------------------------------------------------------
// Component Lifecycle
@@ -52,16 +57,18 @@
public void initialize()
{
- settingsFile = getSettingsFile();
+ userSettingsFile = getUserSettingsFile();
+ globalSettingsFile = getGlobalSettingsFile();
- getLogger().debug( "Building Maven settings from: '" +
settingsFile.getAbsolutePath() + "'" );
+ getLogger().debug( "Building Maven global-level settings from: '" +
globalSettingsFile.getAbsolutePath() + "'" );
+ getLogger().debug( "Building Maven user-level settings from: '" +
userSettingsFile.getAbsolutePath() + "'" );
}
// ----------------------------------------------------------------------
// MavenProfilesBuilder Implementation
// ----------------------------------------------------------------------
- public Settings buildSettings()
+ private Settings readSettings( File settingsFile )
throws IOException, XmlPullParserException
{
Settings settings = null;
@@ -77,25 +84,29 @@
settings = modelReader.read( reader );
}
- catch ( FileNotFoundException e )
- {
- // Not possible - just ignore
- getLogger().warn( "Settings file disappeared - ignoring", e );
- }
finally
{
IOUtil.close( reader );
}
}
- if ( settings == null )
- {
- getLogger().debug( "Settings model not found. Creating empty
instance of MavenSettings." );
+ return settings;
+ }
+
+ public Settings buildSettings()
+ throws IOException, XmlPullParserException
+ {
+ Settings globalSettings = readSettings( globalSettingsFile );
+ Settings userSettings = readSettings( userSettingsFile );
- settings = new Settings();
+ if ( userSettings == null )
+ {
+ userSettings = new Settings();
}
-
- if( settings.getLocalRepository() == null ||
settings.getLocalRepository().length() < 1 )
+
+ SettingsUtils.merge( userSettings, globalSettings );
+
+ if ( userSettings.getLocalRepository() == null ||
userSettings.getLocalRepository().length() < 1 )
{
File mavenUserConfigurationDirectory = new File( userHome, ".m2" );
if ( !mavenUserConfigurationDirectory.exists() )
@@ -107,24 +118,46 @@
}
String localRepository = new File(
mavenUserConfigurationDirectory, "repository" ).getAbsolutePath();
-
- settings.setLocalRepository( localRepository );
+
+ userSettings.setLocalRepository( localRepository );
}
- return settings;
+ return userSettings;
}
- private File getSettingsFile()
+ private File getUserSettingsFile()
{
- String path = System.getProperty(
MavenSettingsBuilder.ALT_SETTINGS_XML_LOCATION );
-
- if( StringUtils.isEmpty( path ) )
+ 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" );
- return new File( userHome, settingsPath ).getAbsoluteFile();
+ path = userSettingsPath.replaceAll( "\\$\\{user.home\\}", userHome
);
+
+ return new File( path ).getAbsoluteFile();
+ }
+ else
+ {
+ return new File( path ).getAbsoluteFile();
+ }
+ }
+
+ 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
{
Copied:
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
(from r190399,
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java)
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java?p2=maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java&p1=maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java&r1=190399&r2=190517&rev=190517&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
(original)
+++
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/MavenSettingsBuilder.java
Mon Jun 13 14:56:00 2005
@@ -29,7 +29,8 @@
{
String ROLE = MavenSettingsBuilder.class.getName();
- String ALT_SETTINGS_XML_LOCATION = "org.apache.maven.SettingsXmlFile";
+ String ALT_USER_SETTINGS_XML_LOCATION = "org.apache.maven.user-settings";
+ String ALT_GLOBAL_SETTINGS_XML_LOCATION =
"org.apache.maven.global-settings";
Settings buildSettings()
throws IOException, XmlPullParserException;
Copied:
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java
(from r190399,
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsConversionUtils.java)
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java?p2=maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java&p1=maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsConversionUtils.java&r1=190399&r2=190517&rev=190517&view=diff
==============================================================================
---
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsConversionUtils.java
(original)
+++
maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java
Mon Jun 13 14:56:00 2005
@@ -1,12 +1,11 @@
package org.apache.maven.settings;
-import org.apache.maven.model.Activation;
-import org.apache.maven.model.ActivationProperty;
-import org.apache.maven.model.Profile;
-import org.apache.maven.model.Repository;
+import org.codehaus.plexus.util.StringUtils;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@@ -24,22 +23,127 @@
* limitations under the License.
*/
-public final class SettingsConversionUtils
+public final class SettingsUtils
{
- public static Profile convertFromSettingsProfile(
org.apache.maven.settings.Profile settingsProfile )
+ private SettingsUtils()
{
- Profile profile = new Profile();
-
+ }
+
+ public static void merge( Settings dominant, Settings recessive )
+ {
+ if ( dominant == null || recessive == null )
+ {
+ return;
+ }
+
+ List dominantActiveProfiles = dominant.getActiveProfiles();
+ List recessiveActiveProfiles = recessive.getActiveProfiles();
+
+ for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); )
+ {
+ String profileId = (String) it.next();
+
+ if ( !dominantActiveProfiles.contains( profileId ) )
+ {
+ dominantActiveProfiles.add( profileId );
+ }
+ }
+
+ if ( StringUtils.isEmpty( dominant.getLocalRepository() ) )
+ {
+ dominant.setLocalRepository( recessive.getLocalRepository() );
+ }
+
+ List mergedMirrors = new ArrayList( dominant.getMirrors() );
+
+ List recessiveMirrors = recessive.getMirrors();
+
+ Map dominantMirrors = dominant.getMirrorsAsMap();
+
+ for ( Iterator it = recessiveMirrors.iterator(); it.hasNext(); )
+ {
+ Mirror recessiveMirror = (Mirror) it.next();
+
+ Mirror dominantMirror = (Mirror) dominantMirrors.get(
recessiveMirror.getId() );
+
+ if ( dominantMirror == null )
+ {
+ mergedMirrors.add( recessiveMirror );
+ }
+ }
+
+ dominant.setMirrors( mergedMirrors );
+
+ List mergedServers = new ArrayList( dominant.getServers() );
+
+ List recessiveServers = recessive.getServers();
+
+ Map dominantServers = dominant.getServersAsMap();
+
+ for ( Iterator it = recessiveServers.iterator(); it.hasNext(); )
+ {
+ Server recessiveServer = (Server) it.next();
+
+ if ( !dominantServers.containsKey( recessiveServer.getId() ) )
+ {
+ mergedServers.add( recessiveServer );
+ }
+ }
+
+ dominant.setServers( mergedServers );
+
+ List mergedProxies = new ArrayList( dominant.getProxies() );
+
+ List recessiveProxies = recessive.getProxies();
+
+ Map dominantProxies = dominant.getProxiesAsMap();
+
+ for ( Iterator it = recessiveProxies.iterator(); it.hasNext(); )
+ {
+ Proxy recessiveProxy = (Proxy) it.next();
+
+ if ( !dominantProxies.containsKey( recessiveProxy ) )
+ {
+ mergedProxies.add( recessiveProxy );
+ }
+ }
+
+ dominant.setProxies( mergedProxies );
+
+ List mergedProfiles = new ArrayList( dominant.getProfiles() );
+
+ List recessiveProfiles = recessive.getProfiles();
+
+ Map dominantProfiles = dominant.getProfilesAsMap();
+
+ for ( Iterator it = recessiveProfiles.iterator(); it.hasNext(); )
+ {
+ Profile recessiveProfile = (Profile) it.next();
+
+ if ( !dominantProfiles.containsKey( recessiveProfile.getId() ) )
+ {
+ mergedProfiles.add( recessiveProfile );
+ }
+ }
+
+ dominant.setProfiles( mergedProfiles );
+
+ }
+
+ public static org.apache.maven.model.Profile convertFromSettingsProfile(
Profile settingsProfile )
+ {
+ org.apache.maven.model.Profile profile = new
org.apache.maven.model.Profile();
+
profile.setId( settingsProfile.getId() );
-
+
profile.setSource( "settings.xml" );
org.apache.maven.settings.Activation settingsActivation =
settingsProfile.getActivation();
if ( settingsActivation != null )
{
- Activation activation = new Activation();
+ org.apache.maven.model.Activation activation = new
org.apache.maven.model.Activation();
activation.setJdk( settingsActivation.getJdk() );
@@ -47,7 +151,7 @@
if ( settingsProp != null )
{
- ActivationProperty prop = new ActivationProperty();
+ org.apache.maven.model.ActivationProperty prop = new
org.apache.maven.model.ActivationProperty();
prop.setName( settingsProp.getName() );
prop.setValue( settingsProp.getValue() );
@@ -57,14 +161,13 @@
}
profile.setProperties( settingsProfile.getProperties() );
-
+
List repos = settingsProfile.getRepositories();
if ( repos != null )
{
for ( Iterator it = repos.iterator(); it.hasNext(); )
{
- profile
- .addRepository( convertFromSettingsRepository(
(org.apache.maven.settings.Repository) it.next() ) );
+ profile.addRepository( convertFromSettingsRepository(
(Repository) it.next() ) );
}
}
@@ -73,17 +176,16 @@
{
for ( Iterator it = pluginRepos.iterator(); it.hasNext(); )
{
- profile.addPluginRepository( convertFromSettingsRepository(
(org.apache.maven.settings.Repository) it
- .next() ) );
+ profile.addPluginRepository( convertFromSettingsRepository(
(Repository) it.next() ) );
}
}
return profile;
}
- private static Repository convertFromSettingsRepository(
org.apache.maven.settings.Repository settingsRepo )
+ private static org.apache.maven.model.Repository
convertFromSettingsRepository( Repository settingsRepo )
{
- Repository repo = new Repository();
+ org.apache.maven.model.Repository repo = new
org.apache.maven.model.Repository();
repo.setId( settingsRepo.getId() );
repo.setLayout( settingsRepo.getLayout() );
Added:
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml?rev=190517&view=auto
==============================================================================
---
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
(added)
+++
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
Mon Jun 13 14:56:00 2005
@@ -0,0 +1,14 @@
+<component-set>
+ <components>
+
+ <component>
+ <role>org.apache.maven.settings.MavenSettingsBuilder</role>
+
<implementation>org.apache.maven.settings.DefaultMavenSettingsBuilder</implementation>
+ <configuration>
+ <globalSettingsPath>${maven.home}/settings.xml</globalSettingsPath>
+ <userSettingsPath>${user.home}/.m2/settings.xml</userSettingsPath>
+ </configuration>
+ </component>
+
+ </components>
+</component-set>
Propchange:
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author"
Propchange:
maven/components/trunk/maven-settings/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]