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 import java.io.File; 019 import java.io.IOException; 020 import java.io.OutputStream; 021 import java.util.Properties; 022 023 import org.apache.commons.io.FileUtils; 024 import org.apache.commons.io.IOUtils; 025 import org.apache.maven.plugin.AbstractMojo; 026 import org.apache.maven.plugin.MojoExecutionException; 027 import org.apache.maven.project.MavenProject; 028 029 /** 030 * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a> 031 * @version $Id: AbstractWritePropertiesMojo.java 8861 2009-01-21 15:35:38Z pgier $ 032 */ 033 public abstract class AbstractWritePropertiesMojo extends AbstractMojo { 034 035 /** 036 * @parameter default-value="${project}" 037 * @required 038 * @readonly 039 */ 040 protected MavenProject project; 041 042 /** 043 * The file that properties will be written to 044 * 045 * @parameter expression="${properties.outputFile}" 046 * default-value="${project.build.directory}/properties/project.properties"; 047 * @required 048 */ 049 protected File outputFile; 050 051 protected void writeProperties(Properties properties, File file) throws MojoExecutionException { 052 OutputStream out = null; 053 try { 054 out = FileUtils.openOutputStream(outputFile); 055 properties.store(out, "Properties"); 056 } catch (IOException e) { 057 throw new MojoExecutionException("Error creating properties file", e); 058 } finally { 059 IOUtils.closeQuietly(out); 060 } 061 } 062 }