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 53 extends AbstractMojo 54 { 55 // fields ----------------------------------------------------------------- 56 57 /** 58 * The system properties to set. 59 * 60 * @parameter 61 * @required 62 */ 63 private Properties properties; 64 65 // Mojo methods ----------------------------------------------------------- 66 67 /** 68 * {@inheritDoc} 69 */ 70 public void execute() 71 throws MojoExecutionException, MojoFailureException 72 { 73 if ( properties.isEmpty() ) 74 { 75 getLog().debug( "No system properties found" ); 76 77 return; 78 } 79 80 getLog().debug( "Setting system properties:" ); 81 82 for ( Enumeration propertyNames = properties.propertyNames(); propertyNames.hasMoreElements(); ) 83 { 84 String propertyName = propertyNames.nextElement().toString(); 85 String propertyValue = properties.getProperty( propertyName ); 86 87 getLog().debug( "- " + propertyName + " = " + propertyValue ); 88 89 System.setProperty( propertyName, propertyValue ); 90 } 91 92 int count = properties.size(); 93 94 getLog().info( "Set " + count + " system " + ( count > 1 ? "properties" : "property" ) ); 95 } 96 }