blob: e1414cd3ccdde534d0daf548779b41e36322a879 [file] [log] [blame]
package org.apache.maven.plugin.coreit;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import java.util.Properties;
import java.io.FileOutputStream;
import java.io.File;
/**
* Take some configuration values that use interpolated POM values and write them to a properties file
* to make sure they are passing through the system properly. We are using this mojo in it0088, and the
* configuration looks like the following:
*
* <plugin>
* <groupId>org.apache.maven.its.plugins</groupId>
* <artifactId>maven-it-plugin-generate-properties</artifactId>
* <version>1.0-SNAPSHOT</version>
* <executions>
* <execution>
* <phase>process-resources</phase>
* <configuration>
* <projectBuildDirectory>${project.build.directory}</projectBuildDirectory>
* <targetDirectoryString>target</targetDirectoryString>
* <targetDirectoryFile>target</targetDirectoryFile>
* </configuration>
* <goals>
* <goal>generate-properties</goal>
* </goals>
* </execution>
* </executions>
* </plugin>
*
* @goal generate-properties
*
*/
public class InterpolatedPomConfigurationMojo
extends AbstractMojo
{
/**
* @parameter expression="${basedir}"
*/
private String basedir;
/**
* This is using the plugin configuration above and so ${project.build.directory} is the value
* of the expression ${projectBuildDirectory} and should be the full path to the scratch directory
* which often looks something like /path/to/project/target. For the 2.0.x family this always results
* in a full path, and bugs have resulted when it resolves to something that is not a full path like "target".
*
* @parameter expression="${projectBuildDirectory}"
*/
private String projectBuildDirectory;
/**
* @parameter expression="${targetDirectoryString}"
*/
private String targetDirectoryString;
/**
* @parameter expression="${targetDirectoryFile}"
*/
private File targetDirectoryFile;
public void execute()
throws MojoExecutionException
{
try
{
Properties mojoGeneratedPropeties = new Properties();
mojoGeneratedPropeties.put( "project.build.directory", projectBuildDirectory );
if ( targetDirectoryString != null )
{
mojoGeneratedPropeties.put( "targetDirectoryString", targetDirectoryString );
}
if ( targetDirectoryFile != null )
{
mojoGeneratedPropeties.put( "targetDirectoryFile", targetDirectoryFile.getAbsolutePath() );
}
FileOutputStream fos = new FileOutputStream( new File( basedir, "target/mojo-generated.properties" ) );
mojoGeneratedPropeties.store( fos, "# Properties generated by the execution of a mojo that uses interpolated POM values for configuration." );
}
catch( Exception e )
{
getLog().error( "Error creating mojo generated properties.", e );
}
}
}