o Added sourceLevel (meaning global vs. user) to most base classes in the model, to track for the purposes of rewriting the user-level settings ONLY.

o Added an identity base class for many of these same base classes, to allow sorting/merging based on id (shallow merging) using a common piece of code.

o Added support for pluginUpdates (first pass) within the settings.xml, and support for merging this new section based on plugin key (g:a)

Working toward: MNG-379



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@190704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-15 03:01:48 +00:00
parent 685ba3412b
commit d15513bd60
3 changed files with 235 additions and 195 deletions

View File

@ -12,9 +12,63 @@
</default>
</defaults>
<classes>
<class>
<name>TrackableBase</name>
<version>1.0.0</version>
<description>common base class that contains code to track the source for this instance (USER|GLOBAL)</description>
<codeSegments>
<codeSegment>
<version>1.0.0</version>
<code><![CDATA[
public static final String USER_LEVEL = "user-level";
public static final String GLOBAL_LEVEL = "global-level";
private String sourceLevel = USER_LEVEL;
private boolean sourceLevelSet = false;
public void setSourceLevel( String sourceLevel )
{
if ( sourceLevelSet )
{
throw new IllegalStateException( "Cannot reset sourceLevel attribute; it is already set to: " + sourceLevel );
}
else if ( !( USER_LEVEL.equals( sourceLevel ) || GLOBAL_LEVEL.equals( sourceLevel ) ) )
{
throw new IllegalArgumentException( "sourceLevel must be one of: {" + USER_LEVEL + "," + GLOBAL_LEVEL + "}" );
}
else
{
this.sourceLevel = sourceLevel;
this.sourceLevelSet = true;
}
}
public String getSourceLevel()
{
return sourceLevel;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class>
<name>IdentifiableBase</name>
<superClass>TrackableBase</superClass>
<version>1.0.0</version>
<fields>
<field>
<name>id</name>
<version>1.0.0</version>
<type>String</type>
<default>default</default>
<required>true</required>
</field>
</fields>
</class>
<class rootElement="true" xml.tagName="settings">
<name>Settings</name>
<version>1.0.0</version>
<superClass>TrackableBase</superClass>
<description>Root element of the user configuration file.</description>
<fields>
<field>
@ -119,6 +173,15 @@
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>pluginUpdates</name>
<version>1.0.0</version>
<description>Specified plugin update policy information.</description>
<association>
<type>PluginUpdate</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
@ -161,102 +224,6 @@
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 )
{
Server match = null;
@ -298,6 +265,63 @@
return match;
}
private Map activeProfileToSourceLevel = new HashMap();
public void setActiveProfileSourceLevel( String activeProfile, String sourceLevel )
{
activeProfileToSourceLevel.put( activeProfile, sourceLevel );
}
public String getSourceLevelForActiveProfile( String activeProfile )
{
String sourceLevel = (String) activeProfileToSourceLevel.get( activeProfile );
if ( sourceLevel != null )
{
return sourceLevel;
}
else
{
return getSourceLevel();
}
}
private String localRepositorySourceLevel = TrackableBase.USER_LEVEL;
public void setLocalRepositorySourceLevel( String localRepoSourceLevel )
{
this.localRepositorySourceLevel = localRepoSourceLevel;
}
public String getLocalRepositorySourceLevel()
{
return localRepositorySourceLevel;
}
private Map pluginUpdatesByKey;
public Map getPluginUpdatesByKey()
{
if ( pluginUpdatesByKey == null )
{
pluginUpdatesByKey = new HashMap();
for ( Iterator it = getPluginUpdates().iterator(); it.hasNext(); )
{
PluginUpdate pluginUpdate = (PluginUpdate) it.next();
pluginUpdatesByKey.put( pluginUpdate.getKey(), pluginUpdate );
}
}
return pluginUpdatesByKey;
}
public void flushPluginUpdatesByKey()
{
this.pluginUpdatesByKey = null;
}
]]></code>
</codeSegment>
</codeSegments>
@ -307,6 +331,7 @@
<!-- class>
<name>Jdk</name>
<version>1.0.0</version>
<superClass>TrackableBase</superClass>
<description><![CDATA[Describes one Java environment]]></description>
<fields>
<field>
@ -336,13 +361,8 @@
<class>
<name>Proxy</name>
<version>1.0.0</version>
<superClass>IdentifiableBase</superClass>
<fields>
<field>
<name>id</name>
<required>true</required>
<default>default</default>
<type>String</type>
</field>
<field>
<name>active</name>
<version>1.0.0</version>
@ -397,17 +417,8 @@
<class>
<name>Server</name>
<version>1.0.0</version>
<superClass>IdentifiableBase</superClass>
<fields>
<field>
<name>id</name>
<version>1.0.0</version>
<required>true</required>
<description><![CDATA[
The ID of this configuration for indicating the default or "active"
profile.
]]></description>
<type>String</type>
</field>
<field>
<name>username</name>
<version>1.0.0</version>
@ -443,23 +454,16 @@
<class>
<name>Mirror</name>
<version>1.0.0</version>
<superClass>IdentifiableBase</superClass>
<description> A download mirror for a given repository. </description>
<fields>
<field>
<name>id</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description> The server ID of this mirror. This must -not- be the
same as that of the repository you are mirroring. </description>
</field>
<field>
<name>mirrorOf</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description> The server ID of the repository being mirrored, eg
"central". </description>
"central". This MUST NOT match the mirror id. </description>
</field>
<field>
<name>name</name>
@ -493,19 +497,12 @@
<class>
<name>Profile</name>
<version>1.0.0</version>
<superClass>IdentifiableBase</superClass>
<description><![CDATA[
Modifications to the build process which is keyed on some
sort of environmental parameter.
]]></description>
<fields>
<field>
<name>id</name>
<required>true</required>
<version>1.0.0</version>
<type>String</type>
<description>The ID of this build profile, for activation
purposes.</description>
</field>
<field>
<name>activation</name>
<version>1.0.0</version>
@ -675,5 +672,58 @@
</fields>
</class>
<!-- /BuildProfile support -->
<class>
<name>PluginUpdate</name>
<version>1.0.0</version>
<superClass>TrackableBase</superClass>
<description>Policy for updating a single plugin.</description>
<fields>
<field>
<name>groupId</name>
<version>1.0.0</version>
<required>true</required>
<type>String</type>
</field>
<field>
<name>artifactId</name>
<version>1.0.0</version>
<required>true</required>
<type>String</type>
</field>
<field>
<name>autoUpdate</name>
<version>1.0.0</version>
<type>boolean</type>
<default>false</default>
<description>Whether to automatically update this plugin - false means prompt the user.</description>
</field>
<field>
<name>useVersion</name>
<version>1.0.0</version>
<type>String</type>
<description>The current version of this plugin, to be used until the appropriate update actions happen.</description>
</field>
<field>
<name>rejectedVersions</name>
<version>1.0.0</version>
<description>The list of versions for this plugin that the user declined to "install"</description>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0</version>
<code><![CDATA[
public String getKey()
{
return getGroupId() + ":" + getArtifactId();
}
]]></code>
</codeSegment>
</codeSegments>
</class>
</classes>
</model>

View File

@ -105,7 +105,7 @@ public class DefaultMavenSettingsBuilder
userSettings = new Settings();
}
SettingsUtils.merge( userSettings, globalSettings );
SettingsUtils.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL );
if ( userSettings.getLocalRepository() == null || userSettings.getLocalRepository().length() < 1 )
{

View File

@ -2,7 +2,7 @@ package org.apache.maven.settings;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -29,13 +29,15 @@ public final class SettingsUtils
private SettingsUtils()
{
}
public static void merge( Settings dominant, Settings recessive )
public static void merge( Settings dominant, Settings recessive, String recessiveSourceLevel )
{
if ( dominant == null || recessive == null )
{
return;
}
recessive.setSourceLevel( recessiveSourceLevel );
List dominantActiveProfiles = dominant.getActiveProfiles();
List recessiveActiveProfiles = recessive.getActiveProfiles();
@ -47,88 +49,76 @@ public final class SettingsUtils
if ( !dominantActiveProfiles.contains( profileId ) )
{
dominantActiveProfiles.add( profileId );
dominant.setActiveProfileSourceLevel( profileId, recessiveSourceLevel );
}
}
if ( StringUtils.isEmpty( dominant.getLocalRepository() ) )
{
dominant.setLocalRepository( recessive.getLocalRepository() );
dominant.setLocalRepositorySourceLevel( recessiveSourceLevel );
}
List mergedMirrors = new ArrayList( dominant.getMirrors() );
shallowMergeById( dominant.getMirrors(), recessive.getMirrors(), recessiveSourceLevel );
shallowMergeById( dominant.getServers(), recessive.getServers(), recessiveSourceLevel );
shallowMergeById( dominant.getProxies(), recessive.getProxies(), recessiveSourceLevel );
shallowMergeById( dominant.getProfiles(), recessive.getProfiles(), recessiveSourceLevel );
List recessiveMirrors = recessive.getMirrors();
Map dominantMirrors = dominant.getMirrorsAsMap();
for ( Iterator it = recessiveMirrors.iterator(); it.hasNext(); )
shallowMergePluginUpdates( dominant, recessive.getPluginUpdates(), recessiveSourceLevel );
}
private static void shallowMergePluginUpdates( Settings dominant, List recessive, String recessiveSourceLevel )
{
Map dominantByKey = dominant.getPluginUpdatesByKey();
List dominantPluginUpdates = dominant.getPluginUpdates();
for ( Iterator it = recessive.iterator(); it.hasNext(); )
{
Mirror recessiveMirror = (Mirror) it.next();
Mirror dominantMirror = (Mirror) dominantMirrors.get( recessiveMirror.getId() );
if ( dominantMirror == null )
PluginUpdate recessivePluginUpdate = (PluginUpdate) it.next();
if( !dominantByKey.containsKey( recessivePluginUpdate.getKey() ) )
{
mergedMirrors.add( recessiveMirror );
recessivePluginUpdate.setSourceLevel( recessiveSourceLevel );
dominantPluginUpdates.add( recessivePluginUpdate );
}
}
dominant.flushPluginUpdatesByKey();
}
dominant.setMirrors( mergedMirrors );
List mergedServers = new ArrayList( dominant.getServers() );
List recessiveServers = recessive.getServers();
Map dominantServers = dominant.getServersAsMap();
for ( Iterator it = recessiveServers.iterator(); it.hasNext(); )
private static void shallowMergeById( List dominant, List recessive, String recessiveSourceLevel )
{
Map dominantById = mapById( dominant );
for ( Iterator it = recessive.iterator(); it.hasNext(); )
{
Server recessiveServer = (Server) it.next();
if ( !dominantServers.containsKey( recessiveServer.getId() ) )
IdentifiableBase identifiable = (IdentifiableBase) it.next();
if( !dominantById.containsKey(identifiable.getId()))
{
mergedServers.add( recessiveServer );
identifiable.setSourceLevel( recessiveSourceLevel );
dominant.add( identifiable );
}
}
dominant.setServers( mergedServers );
List mergedProxies = new ArrayList( dominant.getProxies() );
List recessiveProxies = recessive.getProxies();
Map dominantProxies = dominant.getProxiesAsMap();
for ( Iterator it = recessiveProxies.iterator(); it.hasNext(); )
}
private static Map mapById( List identifiables )
{
Map byId = new HashMap();
for ( Iterator it = identifiables.iterator(); it.hasNext(); )
{
Proxy recessiveProxy = (Proxy) it.next();
if ( !dominantProxies.containsKey( recessiveProxy ) )
{
mergedProxies.add( recessiveProxy );
}
IdentifiableBase identifiable = (IdentifiableBase) it.next();
byId.put( identifiable.getId(), identifiable );
}
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 );
return byId;
}
public static org.apache.maven.model.Profile convertFromSettingsProfile( Profile settingsProfile )