From d15513bd605afb9902fe93692c370306deff5515 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 15 Jun 2005 03:01:48 +0000 Subject: [PATCH] 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 --- maven-settings/settings.mdo | 308 ++++++++++-------- .../settings/DefaultMavenSettingsBuilder.java | 2 +- .../apache/maven/settings/SettingsUtils.java | 120 ++++--- 3 files changed, 235 insertions(+), 195 deletions(-) diff --git a/maven-settings/settings.mdo b/maven-settings/settings.mdo index 071a073c4e..b567dd741c 100644 --- a/maven-settings/settings.mdo +++ b/maven-settings/settings.mdo @@ -12,9 +12,63 @@ + + TrackableBase + 1.0.0 + common base class that contains code to track the source for this instance (USER|GLOBAL) + + + 1.0.0 + + + + + + IdentifiableBase + TrackableBase + 1.0.0 + + + id + 1.0.0 + String + default + true + + + Settings 1.0.0 + TrackableBase Root element of the user configuration file. @@ -119,6 +173,15 @@ * + + pluginUpdates + 1.0.0 + Specified plugin update policy information. + + PluginUpdate + * + + @@ -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; + } ]]> @@ -307,6 +331,7 @@ + + PluginUpdate + 1.0.0 + TrackableBase + Policy for updating a single plugin. + + + groupId + 1.0.0 + true + String + + + artifactId + 1.0.0 + true + String + + + autoUpdate + 1.0.0 + boolean + false + Whether to automatically update this plugin - false means prompt the user. + + + useVersion + 1.0.0 + String + The current version of this plugin, to be used until the appropriate update actions happen. + + + rejectedVersions + 1.0.0 + The list of versions for this plugin that the user declined to "install" + + String + * + + + + + + 1.0.0 + + + + \ No newline at end of file diff --git a/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index f15af499bc..13ab9bff8e 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -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 ) { diff --git a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java index b6dd6663ec..e716e35805 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java @@ -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 )