Author: jdcasey Date: Tue Jun 14 20:01:48 2005 New Revision: 190704 URL: http://svn.apache.org/viewcvs?rev=190704&view=rev Log: 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 Modified: maven/components/trunk/maven-settings/settings.mdo maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java Modified: maven/components/trunk/maven-settings/settings.mdo URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/settings.mdo?rev=190704&r1=190703&r2=190704&view=diff ============================================================================== --- maven/components/trunk/maven-settings/settings.mdo (original) +++ maven/components/trunk/maven-settings/settings.mdo Tue Jun 14 20:01:48 2005 @@ -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,14 +361,9 @@ <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> <required>false</required> @@ -397,18 +417,9 @@ <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> <description><![CDATA[The username used to authenticate.]]> @@ -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,20 +497,13 @@ <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> <description><![CDATA[The conditional logic which will automatically @@ -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> Modified: maven/components/trunk/maven-settings/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?rev=190704&r1=190703&r2=190704&view=diff ============================================================================== --- maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java (original) +++ maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java Tue Jun 14 20:01:48 2005 @@ -105,7 +105,7 @@ userSettings = new Settings(); } - SettingsUtils.merge( userSettings, globalSettings ); + SettingsUtils.merge( userSettings, globalSettings, TrackableBase.GLOBAL_LEVEL ); if ( userSettings.getLocalRepository() == null || userSettings.getLocalRepository().length() < 1 ) { Modified: maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java?rev=190704&r1=190703&r2=190704&view=diff ============================================================================== --- maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java (original) +++ maven/components/trunk/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java Tue Jun 14 20:01:48 2005 @@ -2,7 +2,7 @@ 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 @@ 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 @@ 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() ); - - 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(); + shallowMergeById( dominant.getMirrors(), recessive.getMirrors(), recessiveSourceLevel ); + shallowMergeById( dominant.getServers(), recessive.getServers(), recessiveSourceLevel ); + shallowMergeById( dominant.getProxies(), recessive.getProxies(), recessiveSourceLevel ); + shallowMergeById( dominant.getProfiles(), recessive.getProfiles(), recessiveSourceLevel ); - if ( !dominantServers.containsKey( recessiveServer.getId() ) ) + 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(); ) + { + PluginUpdate recessivePluginUpdate = (PluginUpdate) it.next(); + + if( !dominantByKey.containsKey( recessivePluginUpdate.getKey() ) ) { - mergedServers.add( recessiveServer ); + recessivePluginUpdate.setSourceLevel( recessiveSourceLevel ); + + dominantPluginUpdates.add( recessivePluginUpdate ); } } + + dominant.flushPluginUpdatesByKey(); + } - 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 ) ) + private static void shallowMergeById( List dominant, List recessive, String recessiveSourceLevel ) + { + Map dominantById = mapById( dominant ); + + for ( Iterator it = recessive.iterator(); it.hasNext(); ) + { + IdentifiableBase identifiable = (IdentifiableBase) it.next(); + + if( !dominantById.containsKey(identifiable.getId())) { - mergedProxies.add( recessiveProxy ); + identifiable.setSourceLevel( recessiveSourceLevel ); + + dominant.add( 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 ); - } + } + + private static Map mapById( List identifiables ) + { + Map byId = new HashMap(); + + for ( Iterator it = identifiables.iterator(); it.hasNext(); ) + { + IdentifiableBase identifiable = (IdentifiableBase) it.next(); + + byId.put( identifiable.getId(), identifiable ); } - - dominant.setProfiles( mergedProfiles ); - + + return byId; } public static org.apache.maven.model.Profile convertFromSettingsProfile( Profile settingsProfile ) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]