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 import java.io.File;
19 import java.io.IOException;
20 import java.io.OutputStream;
21 import java.util.Properties;
22
23 import org.apache.commons.io.FileUtils;
24 import org.apache.commons.io.IOUtils;
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.project.MavenProject;
28
29 /**
30 * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
31 * @version $Id: AbstractWritePropertiesMojo.java 8861 2009-01-21 15:35:38Z pgier $
32 */
33 public abstract class AbstractWritePropertiesMojo extends AbstractMojo {
34
35 /**
36 * @parameter default-value="${project}"
37 * @required
38 * @readonly
39 */
40 protected MavenProject project;
41
42 /**
43 * The file that properties will be written to
44 *
45 * @parameter expression="${properties.outputFile}"
46 * default-value="${project.build.directory}/properties/project.properties";
47 * @required
48 */
49 protected File outputFile;
50
51 protected void writeProperties(Properties properties, File file) throws MojoExecutionException {
52 OutputStream out = null;
53 try {
54 out = FileUtils.openOutputStream(outputFile);
55 properties.store(out, "Properties");
56 } catch (IOException e) {
57 throw new MojoExecutionException("Error creating properties file", e);
58 } finally {
59 IOUtils.closeQuietly(out);
60 }
61 }
62 }