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 java.util.Iterator;
038    import java.util.List;
039    import java.util.Properties;
040    
041    import org.apache.maven.model.Profile;
042    import org.apache.maven.plugin.MojoExecutionException;
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        @Override
053        public void execute() throws MojoExecutionException {
054            validateOutputFile();
055            List<?> list = project.getActiveProfiles();
056            if (getLog().isInfoEnabled()) {
057                getLog().debug(list.size() + " profile(s) active");
058            }
059            Properties properties = new Properties();
060            for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
061                Profile profile = (Profile) iter.next();
062                if (profile.getProperties() != null) {
063                    properties.putAll(profile.getProperties());
064                }
065            }
066    
067            getLog().info("Creating " + outputFile);
068            writeProperties(properties, outputFile);
069        }
070    }