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.Properties;
038 import java.util.Enumeration;
039
040 import org.apache.maven.plugin.MojoExecutionException;
041 import org.apache.maven.plugin.MojoFailureException;
042
043 /**
044 * Writes project properties to a file.
045 *
046 * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
047 * @version $Id: WriteProjectProperties.java 9747 2009-05-20 13:27:44Z mark $
048 * @goal write-project-properties
049 */
050 public class WriteProjectProperties extends AbstractWritePropertiesMojo
051 {
052 public void execute()
053 throws MojoExecutionException, MojoFailureException
054 {
055 validateOutputFile();
056 Properties projProperties = new Properties();
057 projProperties.putAll( project.getProperties() );
058
059 Properties systemProperties = System.getProperties();
060
061 //allow system properties to over write key/value found in maven properties
062 Enumeration enumeration = systemProperties.keys();
063 while ( enumeration.hasMoreElements() )
064 {
065 String key = (String) enumeration.nextElement();
066 String value = systemProperties.getProperty( key );
067 if ( projProperties.get( key ) != null )
068 {
069 projProperties.put( key, value );
070 }
071
072 }
073
074 writeProperties( projProperties, outputFile );
075 }
076 }