View Javadoc

1   /**
2    * Copyright 2009-2012 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  import java.util.Enumeration;
19  import java.util.Properties;
20  
21  import org.apache.maven.plugin.AbstractMojo;
22  import org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  
25  /**
26   * Sets system properties.
27   *
28   * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
29   * @version $Id: SetSystemPropertiesMojo.java 9751 2009-05-20 14:53:00Z mark $
30   * @goal set-system-properties
31   * @phase initialize
32   */
33  public class SetSystemPropertiesMojo extends AbstractMojo {
34      // fields -----------------------------------------------------------------
35  
36      /**
37       * The system properties to set.
38       *
39       * @parameter
40       * @required
41       */
42      private Properties properties;
43  
44      // Mojo methods -----------------------------------------------------------
45  
46      /**
47       * {@inheritDoc}
48       */
49      @Override
50      public void execute() throws MojoExecutionException, MojoFailureException {
51          if (properties.isEmpty()) {
52              getLog().debug("No system properties found");
53  
54              return;
55          }
56  
57          getLog().debug("Setting system properties:");
58  
59          for (Enumeration<?> propertyNames = properties.propertyNames(); propertyNames.hasMoreElements();) {
60              String propertyName = propertyNames.nextElement().toString();
61              String propertyValue = properties.getProperty(propertyName);
62  
63              getLog().debug("- " + propertyName + " = " + propertyValue);
64  
65              System.setProperty(propertyName, propertyValue);
66          }
67  
68          int count = properties.size();
69  
70          getLog().info("Set " + count + " system " + (count > 1 ? "properties" : "property"));
71      }
72  }