Coverage Report - org.apache.maven.plugin.registry.PluginRegistryUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
PluginRegistryUtils
0%
0/60
0%
0/34
4.4
 
 1  
 package org.apache.maven.plugin.registry;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Collections;
 24  
 import java.util.Iterator;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 public final class PluginRegistryUtils
 29  
 {
 30  
 
 31  
     private PluginRegistryUtils()
 32  0
     {
 33  
         // don't allow construction.
 34  0
     }
 35  
 
 36  
     public static void merge( PluginRegistry dominant, PluginRegistry recessive, String recessiveSourceLevel )
 37  
     {
 38  
         // nothing to merge...
 39  0
         if ( dominant == null || recessive == null )
 40  
         {
 41  0
             return;
 42  
         }
 43  
 
 44  0
         RuntimeInfo dominantRtInfo = dominant.getRuntimeInfo();
 45  
 
 46  0
         String dominantUpdateInterval = dominant.getUpdateInterval();
 47  
 
 48  0
         if ( dominantUpdateInterval == null )
 49  
         {
 50  0
             String recessiveUpdateInterval = recessive.getUpdateInterval();
 51  
 
 52  0
             if ( recessiveUpdateInterval != null )
 53  
             {
 54  0
                 dominant.setUpdateInterval( recessiveUpdateInterval );
 55  0
                 dominantRtInfo.setUpdateIntervalSourceLevel( recessiveSourceLevel );
 56  
             }
 57  
         }
 58  
 
 59  0
         String dominantAutoUpdate = dominant.getAutoUpdate();
 60  
 
 61  0
         if ( dominantAutoUpdate == null )
 62  
         {
 63  0
             String recessiveAutoUpdate = recessive.getAutoUpdate();
 64  
 
 65  0
             if ( recessiveAutoUpdate != null )
 66  
             {
 67  0
                 dominant.setAutoUpdate( recessiveAutoUpdate );
 68  0
                 dominantRtInfo.setAutoUpdateSourceLevel( recessiveSourceLevel );
 69  
             }
 70  
         }
 71  
 
 72  0
         List recessivePlugins = null;
 73  
 
 74  0
         if ( recessive != null )
 75  
         {
 76  0
             recessivePlugins = recessive.getPlugins();
 77  
         }
 78  
         else
 79  
         {
 80  0
             recessivePlugins = Collections.EMPTY_LIST;
 81  
         }
 82  
 
 83  0
         shallowMergePlugins( dominant, recessivePlugins, recessiveSourceLevel );
 84  0
     }
 85  
 
 86  
     public static void recursivelySetSourceLevel( PluginRegistry pluginRegistry, String sourceLevel )
 87  
     {
 88  0
         if ( pluginRegistry == null )
 89  
         {
 90  0
             return;
 91  
         }
 92  
 
 93  0
         pluginRegistry.setSourceLevel( sourceLevel );
 94  
 
 95  0
         for ( Iterator it = pluginRegistry.getPlugins().iterator(); it.hasNext(); )
 96  
         {
 97  0
             Plugin plugin = (Plugin) it.next();
 98  
 
 99  0
             plugin.setSourceLevel( sourceLevel );
 100  0
         }
 101  0
     }
 102  
 
 103  
     private static void shallowMergePlugins( PluginRegistry dominant, List recessive, String recessiveSourceLevel )
 104  
     {
 105  0
         Map dominantByKey = dominant.getPluginsByKey();
 106  
 
 107  0
         List dominantPlugins = dominant.getPlugins();
 108  
 
 109  0
         for ( Iterator it = recessive.iterator(); it.hasNext(); )
 110  
         {
 111  0
             Plugin recessivePlugin = (Plugin) it.next();
 112  
 
 113  0
             if ( !dominantByKey.containsKey( recessivePlugin.getKey() ) )
 114  
             {
 115  0
                 recessivePlugin.setSourceLevel( recessiveSourceLevel );
 116  
 
 117  0
                 dominantPlugins.add( recessivePlugin );
 118  
             }
 119  0
         }
 120  
 
 121  0
         dominant.flushPluginsByKey();
 122  0
     }
 123  
 
 124  
     public static PluginRegistry extractUserPluginRegistry( PluginRegistry pluginRegistry )
 125  
     {
 126  0
         PluginRegistry userRegistry = null;
 127  
 
 128  
         // check if this registry is entirely made up of global settings
 129  0
         if ( pluginRegistry != null && !PluginRegistry.GLOBAL_LEVEL.equals( pluginRegistry.getSourceLevel() ) )
 130  
         {
 131  0
             userRegistry = new PluginRegistry();
 132  
 
 133  0
             RuntimeInfo rtInfo = new RuntimeInfo( userRegistry );
 134  
 
 135  0
             userRegistry.setRuntimeInfo( rtInfo );
 136  
 
 137  0
             RuntimeInfo oldRtInfo = pluginRegistry.getRuntimeInfo();
 138  
 
 139  0
             if ( TrackableBase.USER_LEVEL.equals( oldRtInfo.getAutoUpdateSourceLevel() ) )
 140  
             {
 141  0
                 userRegistry.setAutoUpdate( pluginRegistry.getAutoUpdate() );
 142  
             }
 143  
 
 144  0
             if ( TrackableBase.USER_LEVEL.equals( oldRtInfo.getUpdateIntervalSourceLevel() ) )
 145  
             {
 146  0
                 userRegistry.setUpdateInterval( pluginRegistry.getUpdateInterval() );
 147  
             }
 148  
 
 149  0
             List plugins = new ArrayList();
 150  
 
 151  0
             for ( Iterator it = pluginRegistry.getPlugins().iterator(); it.hasNext(); )
 152  
             {
 153  0
                 Plugin plugin = (Plugin) it.next();
 154  
 
 155  0
                 if ( TrackableBase.USER_LEVEL.equals( plugin.getSourceLevel() ) )
 156  
                 {
 157  0
                     plugins.add( plugin );
 158  
                 }
 159  0
             }
 160  
 
 161  0
             userRegistry.setPlugins( plugins );
 162  
 
 163  0
             rtInfo.setFile( pluginRegistry.getRuntimeInfo().getFile() );
 164  
         }
 165  
 
 166  0
         return userRegistry;
 167  
     }
 168  
 
 169  
 }