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.Enumeration;
023 import java.util.Properties;
024
025 import org.apache.maven.plugin.AbstractMojo;
026 import org.apache.maven.plugin.MojoExecutionException;
027 import org.apache.maven.plugin.MojoFailureException;
028
029 /**
030 * Sets system properties.
031 *
032 * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
033 * @version $Id: SetSystemPropertiesMojo.java 9751 2009-05-20 14:53:00Z mark $
034 * @goal set-system-properties
035 * @phase initialize
036 */
037 public class SetSystemPropertiesMojo
038 extends AbstractMojo
039 {
040 // fields -----------------------------------------------------------------
041
042 /**
043 * The system properties to set.
044 *
045 * @parameter
046 * @required
047 */
048 private Properties properties;
049
050 // Mojo methods -----------------------------------------------------------
051
052 /**
053 * {@inheritDoc}
054 */
055 public void execute()
056 throws MojoExecutionException, MojoFailureException
057 {
058 if ( properties.isEmpty() )
059 {
060 getLog().debug( "No system properties found" );
061
062 return;
063 }
064
065 getLog().debug( "Setting system properties:" );
066
067 for ( Enumeration propertyNames = properties.propertyNames(); propertyNames.hasMoreElements(); )
068 {
069 String propertyName = propertyNames.nextElement().toString();
070 String propertyValue = properties.getProperty( propertyName );
071
072 getLog().debug( "- " + propertyName + " = " + propertyValue );
073
074 System.setProperty( propertyName, propertyValue );
075 }
076
077 int count = properties.size();
078
079 getLog().info( "Set " + count + " system " + ( count > 1 ? "properties" : "property" ) );
080 }
081 }