1 package org.apache.maven.plugin.registry; 2 3 import java.util.ArrayList ; 4 import java.util.Collections ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 24 25 public final class PluginRegistryUtils 26 { 27 28 private PluginRegistryUtils() 29 { 30 } 32 33 public static void merge( PluginRegistry dominant, PluginRegistry recessive, String recessiveSourceLevel ) 34 { 35 if ( dominant == null || recessive == null ) 37 { 38 return; 39 } 40 41 RuntimeInfo dominantRtInfo = dominant.getRuntimeInfo(); 42 43 String dominantUpdateInterval = dominant.getUpdateInterval(); 44 45 if ( dominantUpdateInterval == null ) 46 { 47 String recessiveUpdateInterval = recessive.getUpdateInterval(); 48 49 if ( recessiveUpdateInterval != null ) 50 { 51 dominant.setUpdateInterval( recessiveUpdateInterval ); 52 dominantRtInfo.setUpdateIntervalSourceLevel( recessiveSourceLevel ); 53 } 54 } 55 56 String dominantAutoUpdate = dominant.getAutoUpdate(); 57 58 if ( dominantAutoUpdate == null ) 59 { 60 String recessiveAutoUpdate = recessive.getAutoUpdate(); 61 62 if ( recessiveAutoUpdate != null ) 63 { 64 dominant.setAutoUpdate( recessiveAutoUpdate ); 65 dominantRtInfo.setAutoUpdateSourceLevel( recessiveSourceLevel ); 66 } 67 } 68 69 List recessivePlugins = null; 70 71 if ( recessive != null ) 72 { 73 recessivePlugins = recessive.getPlugins(); 74 } 75 else 76 { 77 recessivePlugins = Collections.EMPTY_LIST; 78 } 79 80 shallowMergePlugins( dominant, recessivePlugins, recessiveSourceLevel ); 81 } 82 83 public static void recursivelySetSourceLevel( PluginRegistry pluginRegistry, String sourceLevel ) 84 { 85 if ( pluginRegistry == null ) 86 { 87 return; 88 } 89 90 pluginRegistry.setSourceLevel( sourceLevel ); 91 92 for ( Iterator it = pluginRegistry.getPlugins().iterator(); it.hasNext(); ) 93 { 94 Plugin plugin = (Plugin) it.next(); 95 96 plugin.setSourceLevel( sourceLevel ); 97 } 98 } 99 100 private static void shallowMergePlugins( PluginRegistry dominant, List recessive, String recessiveSourceLevel ) 101 { 102 Map dominantByKey = dominant.getPluginsByKey(); 103 104 List dominantPlugins = dominant.getPlugins(); 105 106 for ( Iterator it = recessive.iterator(); it.hasNext(); ) 107 { 108 Plugin recessivePlugin = (Plugin) it.next(); 109 110 if ( !dominantByKey.containsKey( recessivePlugin.getKey() ) ) 111 { 112 recessivePlugin.setSourceLevel( recessiveSourceLevel ); 113 114 dominantPlugins.add( recessivePlugin ); 115 } 116 } 117 118 dominant.flushPluginsByKey(); 119 } 120 121 public static PluginRegistry extractUserPluginRegistry( PluginRegistry pluginRegistry ) 122 { 123 PluginRegistry userRegistry = null; 124 125 if ( pluginRegistry != null && !PluginRegistry.GLOBAL_LEVEL.equals( pluginRegistry.getSourceLevel() ) ) 127 { 128 userRegistry = new PluginRegistry(); 129 130 RuntimeInfo rtInfo = new RuntimeInfo( userRegistry ); 131 132 userRegistry.setRuntimeInfo( rtInfo ); 133 134 RuntimeInfo oldRtInfo = pluginRegistry.getRuntimeInfo(); 135 136 if ( TrackableBase.USER_LEVEL.equals( oldRtInfo.getAutoUpdateSourceLevel() ) ) 137 { 138 userRegistry.setAutoUpdate( pluginRegistry.getAutoUpdate() ); 139 } 140 141 if ( TrackableBase.USER_LEVEL.equals( oldRtInfo.getUpdateIntervalSourceLevel() ) ) 142 { 143 userRegistry.setUpdateInterval( pluginRegistry.getUpdateInterval() ); 144 } 145 146 List plugins = new ArrayList (); 147 148 for ( Iterator it = pluginRegistry.getPlugins().iterator(); it.hasNext(); ) 149 { 150 Plugin plugin = (Plugin) it.next(); 151 152 if ( TrackableBase.USER_LEVEL.equals( plugin.getSourceLevel() ) ) 153 { 154 plugins.add( plugin ); 155 } 156 } 157 158 userRegistry.setPlugins( plugins ); 159 160 rtInfo.setFile( pluginRegistry.getRuntimeInfo().getFile() ); 161 } 162 163 return userRegistry; 164 } 165 166 } 167 | Popular Tags |