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