001 package org.apache.maven.model.plugin;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.List;
023
024 import org.apache.maven.model.Build;
025 import org.apache.maven.model.Model;
026 import org.apache.maven.model.Plugin;
027 import org.apache.maven.model.PluginExecution;
028 import org.apache.maven.model.PluginManagement;
029 import org.apache.maven.model.building.ModelBuildingRequest;
030 import org.apache.maven.model.building.ModelProblemCollector;
031 import org.codehaus.plexus.component.annotations.Component;
032 import org.codehaus.plexus.util.xml.Xpp3Dom;
033
034 /**
035 * Handles expansion of general build plugin configuration into individual executions.
036 *
037 * @author Benjamin Bentmann
038 */
039 @Component( role = PluginConfigurationExpander.class )
040 public class DefaultPluginConfigurationExpander
041 implements PluginConfigurationExpander
042 {
043
044 public void expandPluginConfiguration( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
045 {
046 Build build = model.getBuild();
047
048 if ( build != null )
049 {
050 expand( build.getPlugins() );
051
052 PluginManagement pluginManagement = build.getPluginManagement();
053
054 if ( pluginManagement != null )
055 {
056 expand( pluginManagement.getPlugins() );
057 }
058 }
059 }
060
061 private void expand( List<Plugin> plugins )
062 {
063 for ( Plugin plugin : plugins )
064 {
065 Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
066
067 if ( pluginConfiguration != null )
068 {
069 for ( PluginExecution execution : plugin.getExecutions() )
070 {
071 Xpp3Dom executionConfiguration = (Xpp3Dom) execution.getConfiguration();
072
073 executionConfiguration =
074 Xpp3Dom.mergeXpp3Dom( executionConfiguration, new Xpp3Dom( pluginConfiguration ) );
075
076 execution.setConfiguration( executionConfiguration );
077 }
078 }
079 }
080 }
081
082 }