001    /**
002     * Copyright 2009-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.codehaus.mojo.properties;
017    
018    import java.util.Iterator;
019    import java.util.List;
020    import java.util.Properties;
021    
022    import org.apache.maven.model.Profile;
023    import org.apache.maven.plugin.MojoExecutionException;
024    
025    /**
026     * Writes properties of all active profiles to a file.
027     *
028     * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
029     * @version $Id: WriteActiveProfileProperties.java 8861 2009-01-21 15:35:38Z pgier $
030     * @goal write-active-profile-properties
031     */
032    public class WriteActiveProfileProperties extends AbstractWritePropertiesMojo {
033            @Override
034            public void execute() throws MojoExecutionException {
035                    List<?> list = project.getActiveProfiles();
036                    if (getLog().isInfoEnabled()) {
037                            getLog().debug(list.size() + " profile(s) active");
038                    }
039                    Properties properties = new Properties();
040                    for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
041                            Profile profile = (Profile) iter.next();
042                            if (profile.getProperties() != null) {
043                                    properties.putAll(profile.getProperties());
044                            }
045                    }
046    
047                    getLog().info("Creating " + outputFile);
048                    writeProperties(outputFile, properties, outputStyle, prefix, encoding, comment);
049            }
050    }