Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added write-custom-properties goal #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ target
.settings
.project
.classpath
.idea/
*.iml
23 changes: 23 additions & 0 deletions acceptance/acceptance-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@
<goal>read-project-properties</goal>
</goals>
</execution>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>write-custom-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/META-INF/build.properties</outputFile>
<properties>
<property>
<name>Application-Name</name>
<value>${project.build.finalName}</value>
</property>
<property>
<name>Application.version</name>
<value>${project.version}</value>
</property>
<property>
<name>Application-Build-Timestamp</name>
<value>${maven.build.timestamp}</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
<name>Tim Gordon</name>
<email>timothygordon32@gmail.com</email>
</developer>
<developer>
<id>okohub</id>
<name>Onur Kağan Özcan</name>
<email>onurkaganozcan@gmail.com</email>
</developer>
</developers>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.codehaus.mojo.properties;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import java.util.Properties;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
* Writes custom properties to a file.
*
* @author <a href="mailto:onurkaganozcan@gmail.com">Onur Kağan Özcan</a>
* @version $Id$
*/
@Mojo( name = "write-custom-properties", defaultPhase = LifecyclePhase.NONE, threadSafe = true )
public class WriteCustomProperties
extends AbstractWritePropertiesMojo
{

/**
* The custom properties to set.
*/
@Parameter(name = "properties", required = true)
private Properties properties;

public void execute()
throws MojoExecutionException, MojoFailureException
{
validateOutputFile();
writeProperties(properties, getOutputFile());
}
}
13 changes: 13 additions & 0 deletions src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,18 @@
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<goals>
<goal>write-custom-properties</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
2 changes: 2 additions & 0 deletions src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Properties Maven Plugin

* {{{./set-system-properties-mojo.html}properties:set-system-properties}} Sets system properties.

* {{{./write-custom-properties-mojo.html}properties:write-custom-properties}} Writes custom properties.


* Usage

Expand Down
36 changes: 36 additions & 0 deletions src/site/apt/usage.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,39 @@ Usage
</build>
</project>
----------------

* write-custom-properties

The {{{./write-custom-properties-mojo.html}properties:write-custom-properties}}
goal writes custom properties to a file.

----------------
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>write-custom-properties</goal>
</goals>
<configuration>
<outputFile>\${project.build.outputDirectory}/META-INF/build.properties</outputFile>
<properties>
<property>
<name>my.property.name</name>
<value>my.property.value</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
----------------