001    package org.codehaus.mojo.properties;
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.Properties;
023    import java.util.Enumeration;
024    
025    import org.apache.maven.plugin.MojoExecutionException;
026    import org.apache.maven.plugin.MojoFailureException;
027    
028    /**
029     * Writes project properties to a file.
030     *
031     * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
032     * @version $Id: WriteProjectProperties.java 9747 2009-05-20 13:27:44Z mark $
033     * @goal write-project-properties
034     */
035    public class WriteProjectProperties extends AbstractWritePropertiesMojo
036    {
037        public void execute()
038            throws MojoExecutionException, MojoFailureException
039        {
040            validateOutputFile();
041            Properties projProperties = new Properties();
042            projProperties.putAll( project.getProperties() );
043            
044            Properties systemProperties = System.getProperties();
045            
046            //allow system properties to over write key/value found in maven properties
047            Enumeration enumeration = systemProperties.keys();
048            while ( enumeration.hasMoreElements() )
049            {
050                String key = (String) enumeration.nextElement();
051                String value = systemProperties.getProperty( key );
052                if ( projProperties.get( key ) != null )
053                {
054                    projProperties.put( key, value );
055                }
056                
057            }
058            
059            writeProperties( projProperties, outputFile );
060        }
061    }