/**
 * Generates the source files.
 *
 * @author connollys
 * @goal generate-sources
 * @phase generate-sources
 * @since Oct 20, 2009 9:04:44 AM
 */
public class GenerateSourcesMojo
    extends AbstractMojo
{
    /**
     * The current Maven project
     *
     * @parameter expression="${project}"
     * @readonly
     * @required
     */
    private MavenProject project;

    /**
     * The encoding to use when reading source files.
     *
     * @parameter default-value="${project.build.sourceEncoding}"
     */
    private String sourceEncoding;

    /**
     * The encoding to use when generating Java source files.
     *
     * @parameter default-value="${project.build.outputEncoding}"
     */
    private String outputEncoding;

    /**
     * The directory where the generated resource files will be
stored. The directory will be registered as a resource
     * root of the project such that the generated files will
participate in later build phases like packaing.
     *
     * @parameter
expression="${project.build.directory}/generated-resources/gen-bsapi"
     * @required
     */
    private File resourceOutputDirectory;

    /**
     * {...@inheritdoc}
     */
    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        if ( StringUtils.isEmpty( sourceEncoding ) )
        {
            getLog().warn( "Source file encoding has not been set,
using platform encoding "
                + System.getProperty( "file.encoding" ) + ", i.e.
build is platform dependent!" );
            sourceEncoding = System.getProperty( "file.encoding" );
        }
        if ( StringUtils.isEmpty( outputEncoding ) )
        {
            getLog().warn( "Output file encoding has not been set,
using platform encoding "
                + System.getProperty( "file.encoding" ) + ", i.e.
build is platform dependent!" );
            outputEncoding = System.getProperty( "file.encoding" );
        }

        Resource resource = new Resource();
        ...
        this.project.addResource( resource );
    }

}



On 3 December 2010 15:27, Stephen Connolly
<[email protected]>wrote:

> You will create a folder at
> ${basedir}/target/generated-resources/mypluginname/
> You will put your generated file in that directory
> You will add that directory to the project's list fo resource directories
> You will find the above solution is the maven way.
>
> Putting generated things in folders which are not sub-folders of target is
> not the maven way.
>
> -Stephen
>
>
> On 3 December 2010 14:35, fhomasp <[email protected]> wrote:
>
>>
>> Hey,
>>
>> I was working on a Mojo on which I thought would be a trivial problem.
>> Though it turns out it's not.
>>
>> I simply want to add a property file during the phase "generate-resources"
>> with the current version, on the classpath.  Ideally it's located at the
>> default resourcesdir.  The name of the props file needs to be the name of
>> the artifact (or the given name).
>>
>> For one, I was looking for a maven property like
>> ${build.rescourceDirectory}.  But I couldn't find it.  It's of course kind
>> of logical as It's not guaranteed to be only one directory.  But that's
>> not
>> the main reason of this thread.
>>
>> The other triviality seems to be setting a parameter to use a
>> default-value
>> for this but it doesn't work, or at least it returns null.
>>
>> the properties, which of course exist in maven and don't work in the mojo,
>> are:
>>
>>    /**
>>     * @parameter expression="${versionprop.appName}"
>> default-value="${build.artifactId}"
>>     */
>>    private String appName;
>>
>>
>>    /**
>>     * @parameter expression="${versionprop.name}" default-value="${name}"
>>     */
>>    private String name;
>>
>>  /**
>>     * @parameter expression="${versionprop.test}"
>> default-value="${artifactId}"
>>     */
>>    private String test;
>>
>> I do find this very odd to say the least.  I'd expect to be able to use
>> every expression value used in maven in a Mojo.
>>
>> I know it's really simple to just put these values in the configuration
>> section, however it would really be better if it would work without config
>> to minimize overhead and human errors.
>>
>>
>> Any idea's?
>>
>> Thanks!
>>
>> --
>> View this message in context:
>> http://maven.40175.n5.nabble.com/possible-expressions-on-MOJO-parameters-tp3290963p3290963.html
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to