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    /*
019     * Licensed to the Apache Software Foundation (ASF) under one
020     * or more contributor license agreements.  See the NOTICE file 
021     * distributed with this work for additional information
022     * regarding copyright ownership.  The ASF licenses this file
023     * to you under the Apache License, Version 2.0 (the
024     * "License"); you may not use this file except in compliance
025     * with the License.  You may obtain a copy of the License at
026     * 
027     *   http://www.apache.org/licenses/LICENSE-2.0
028     * 
029     * Unless required by applicable law or agreed to in writing, 
030     * software distributed under the License is distributed on an
031     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
032     * KIND, either express or implied.  See the License for the 
033     * specific language governing permissions and limitations 
034     * under the License.
035     */
036    
037    import org.apache.maven.model.Profile;
038    import org.apache.maven.plugin.MojoExecutionException;
039    
040    import java.util.Iterator;
041    import java.util.List;
042    import java.util.Properties;
043    
044    /**
045     * Writes properties of all active profiles to a file.
046     *
047     * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
048     * @version $Id: WriteActiveProfileProperties.java 8861 2009-01-21 15:35:38Z pgier $
049     * @goal write-active-profile-properties
050     */
051    public class WriteActiveProfileProperties extends AbstractWritePropertiesMojo
052    {
053        public void execute()
054            throws MojoExecutionException
055        {
056            validateOutputFile();
057            List list = project.getActiveProfiles();
058            if ( getLog().isInfoEnabled() )
059            {
060                getLog().debug( list.size() + " profile(s) active" );
061            }
062            Properties properties = new Properties();
063            for ( Iterator iter = list.iterator(); iter.hasNext(); )
064            {
065                Profile profile = (Profile) iter.next();
066                if ( profile.getProperties() != null )
067                {
068                    properties.putAll( profile.getProperties() );
069                }
070            }
071    
072            writeProperties( properties, outputFile );
073        }
074    }