View Javadoc

1   /**
2    * Copyright 2009-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.properties;
17  
18  /*
19   * Licensed to the Apache Software Foundation (ASF) under one
20   * or more contributor license agreements.  See the NOTICE file 
21   * distributed with this work for additional information
22   * regarding copyright ownership.  The ASF licenses this file
23   * to you under the Apache License, Version 2.0 (the
24   * "License"); you may not use this file except in compliance
25   * with the License.  You may obtain a copy of the License at
26   * 
27   *   http://www.apache.org/licenses/LICENSE-2.0
28   * 
29   * Unless required by applicable law or agreed to in writing, 
30   * software distributed under the License is distributed on an
31   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
32   * KIND, either express or implied.  See the License for the 
33   * specific language governing permissions and limitations 
34   * under the License.
35   */
36  
37  import java.util.Properties;
38  import java.util.Enumeration;
39  
40  import org.apache.maven.plugin.MojoExecutionException;
41  import org.apache.maven.plugin.MojoFailureException;
42  
43  /**
44   * Writes project properties to a file.
45   *
46   * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
47   * @version $Id: WriteProjectProperties.java 9747 2009-05-20 13:27:44Z mark $
48   * @goal write-project-properties
49   */
50  public class WriteProjectProperties extends AbstractWritePropertiesMojo
51  {
52      public void execute()
53          throws MojoExecutionException, MojoFailureException
54      {
55          validateOutputFile();
56          Properties projProperties = new Properties();
57          projProperties.putAll( project.getProperties() );
58          
59          Properties systemProperties = System.getProperties();
60          
61          //allow system properties to over write key/value found in maven properties
62          Enumeration enumeration = systemProperties.keys();
63          while ( enumeration.hasMoreElements() )
64          {
65              String key = (String) enumeration.nextElement();
66              String value = systemProperties.getProperty( key );
67              if ( projProperties.get( key ) != null )
68              {
69                  projProperties.put( key, value );
70              }
71              
72          }
73          
74          writeProperties( projProperties, outputFile );
75      }
76  }