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  /*
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.Enumeration;
38  import java.util.Properties;
39  
40  import org.apache.maven.plugin.AbstractMojo;
41  import org.apache.maven.plugin.MojoExecutionException;
42  import org.apache.maven.plugin.MojoFailureException;
43  
44  /**
45   * Sets system properties.
46   *
47   * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
48   * @version $Id: SetSystemPropertiesMojo.java 9751 2009-05-20 14:53:00Z mark $
49   * @goal set-system-properties
50   * @phase initialize
51   */
52  public class SetSystemPropertiesMojo extends AbstractMojo {
53      // fields -----------------------------------------------------------------
54  
55      /**
56       * The system properties to set.
57       *
58       * @parameter
59       * @required
60       */
61      private Properties properties;
62  
63      // Mojo methods -----------------------------------------------------------
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public void execute() throws MojoExecutionException, MojoFailureException {
70          if (properties.isEmpty()) {
71              getLog().debug("No system properties found");
72  
73              return;
74          }
75  
76          getLog().debug("Setting system properties:");
77  
78          for (Enumeration<?> propertyNames = properties.propertyNames(); propertyNames.hasMoreElements();) {
79              String propertyName = propertyNames.nextElement().toString();
80              String propertyValue = properties.getProperty(propertyName);
81  
82              getLog().debug("- " + propertyName + " = " + propertyValue);
83  
84              System.setProperty(propertyName, propertyValue);
85          }
86  
87          int count = properties.size();
88  
89          getLog().info("Set " + count + " system " + (count > 1 ? "properties" : "property"));
90      }
91  }