You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by David Jackman <Da...@fastsearch.com> on 2007/02/16 22:43:13 UTC

Mojo accessing project properties

I'm trying to write a mojo that accesses the properties section of the
project pom.  I declared a member variable like this
    /**
     * Project properties.
     *
     * @parameter default-value="${project.properties}"
     * @required
     * @readonly
     */
    private Properties properties;
When my mojo runs, it gets a Properties object okay, but it's always
empty, even if I have declared properties in the project POM.
 
Am I doing something wrong?  How do I access the project properties (not
plugin configuration properties)?
 
..David..

 
 

RE: Mojo accessing project properties

Posted by David Jackman <Da...@fastsearch.com>.
Well, since this is a jar included in the core directory of Maven 2.0.5,
I can't just reference a snapshot build from the plugin.  I would have
to tell all the developers in the company to patch the jar in their
Maven installation.  Having the plugin just use project will be easier
than trying to scale an unreleased fix, especially since the plugin
won't be able to detect an unpatched installation since having no
properties is a valid state.

..David..


-----Original Message-----
From: Jason van Zyl [mailto:jason@maven.org] 
Sent: Thursday, February 22, 2007 1:15 PM
To: Maven Users List
Subject: Re: Mojo accessing project properties


On 22 Feb 07, at 3:11 PM 22 Feb 07, David Jackman wrote:

> That works great--the perfect solution for right now as I wait until 
> this fix is available with Maven 2.0.6.
>

Once in JIRA you can watch it and use a snapshot build once it's fixed.

Jason.

> Thanks!
>
> ..David..
>
>
> -----Original Message-----
> From: Marcos Silva Pereira [mailto:marcos.silva@gmail.com]
> Sent: Thursday, February 22, 2007 11:38 AM
> To: Maven Users List
> Subject: Re: Mojo accessing project properties
>
> Hello, David
>
> Adding @requiresProject does nothing.
>
>
> What about try inject the project object instead project.properties?
>
> /**
>  * @parameter default-value="${project}"
>  * @required
>  * @readonly
>  */
> private MavenProject project;
>
> I know that it is not a neat solution, but probably will works fine 
> for you.
>
> Interestingly, I'm getting the dependencies just fine without having
>> @requiresDependencyResolution
>> there (although in my case I don't want transitive dependencies--I 
>> expected leaving this attribute out would only give me the direct 
>> dependencies including inherited dependencies).
>
>
> Not sure about it, but maybe it is working because dependencies were 
> already processed when your mojo is activated.
>
> Kind Regards,
>
> --
> Marcos Silva Pereira
> recife - pe
> marcos.silva@gmail.com
> skype: marcos.silva.pereira
> http://blastemica.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Mojo accessing project properties

Posted by Jason van Zyl <ja...@maven.org>.
On 22 Feb 07, at 3:11 PM 22 Feb 07, David Jackman wrote:

> That works great--the perfect solution for right now as I wait until
> this fix is available with Maven 2.0.6.
>

Once in JIRA you can watch it and use a snapshot build once it's fixed.

Jason.

> Thanks!
>
> ..David..
>
>
> -----Original Message-----
> From: Marcos Silva Pereira [mailto:marcos.silva@gmail.com]
> Sent: Thursday, February 22, 2007 11:38 AM
> To: Maven Users List
> Subject: Re: Mojo accessing project properties
>
> Hello, David
>
> Adding @requiresProject does nothing.
>
>
> What about try inject the project object instead project.properties?
>
> /**
>  * @parameter default-value="${project}"
>  * @required
>  * @readonly
>  */
> private MavenProject project;
>
> I know that it is not a neat solution, but probably will works fine  
> for
> you.
>
> Interestingly, I'm getting the dependencies just fine without having
>> @requiresDependencyResolution
>> there (although in my case I don't want transitive dependencies--I
>> expected leaving this attribute out would only give me the direct
>> dependencies including inherited dependencies).
>
>
> Not sure about it, but maybe it is working because dependencies were
> already processed when your mojo is activated.
>
> Kind Regards,
>
> --
> Marcos Silva Pereira
> recife - pe
> marcos.silva@gmail.com
> skype: marcos.silva.pereira
> http://blastemica.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Mojo accessing project properties

Posted by David Jackman <Da...@fastsearch.com>.
That works great--the perfect solution for right now as I wait until
this fix is available with Maven 2.0.6. 

Thanks!

..David..


-----Original Message-----
From: Marcos Silva Pereira [mailto:marcos.silva@gmail.com] 
Sent: Thursday, February 22, 2007 11:38 AM
To: Maven Users List
Subject: Re: Mojo accessing project properties

Hello, David

Adding @requiresProject does nothing.


What about try inject the project object instead project.properties?

/**
 * @parameter default-value="${project}"
 * @required
 * @readonly
 */
private MavenProject project;

I know that it is not a neat solution, but probably will works fine for
you.

Interestingly, I'm getting the dependencies just fine without having
> @requiresDependencyResolution
> there (although in my case I don't want transitive dependencies--I 
> expected leaving this attribute out would only give me the direct 
> dependencies including inherited dependencies).


Not sure about it, but maybe it is working because dependencies were
already processed when your mojo is activated.

Kind Regards,

--
Marcos Silva Pereira
recife - pe
marcos.silva@gmail.com
skype: marcos.silva.pereira
http://blastemica.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Mojo accessing project properties

Posted by Marcos Silva Pereira <ma...@gmail.com>.
Hello, David

Adding @requiresProject does nothing.


What about try inject the project object instead project.properties?

/**
 * @parameter default-value="${project}"
 * @required
 * @readonly
 */
private MavenProject project;

I know that it is not a neat solution, but probably will works fine for you.

Interestingly, I'm getting the dependencies just fine without having
> @requiresDependencyResolution
> there (although in my case I don't want transitive dependencies--I
> expected leaving this attribute out would only give me the direct
> dependencies including inherited dependencies).


Not sure about it, but maybe it is working because dependencies were already
processed when your mojo is activated.

Kind Regards,

-- 
Marcos Silva Pereira
recife - pe
marcos.silva@gmail.com
skype: marcos.silva.pereira
http://blastemica.blogspot.com

RE: Mojo accessing project properties

Posted by David Jackman <Da...@fastsearch.com>.
Adding @requiresProject does nothing.  Interestingly, I'm getting the
dependencies just fine without having @requiresDependencyResolution
there (although in my case I don't want transitive dependencies--I
expected leaving this attribute out would only give me the direct
dependencies including inherited dependencies).

Anyway, I think I've found the problem with project.properties showing
up empty in the plugin.  The problem is in the Plexus code.  I will post
my findings in a separate email.

..David..


-----Original Message-----
From: Marcos Silva Pereira [mailto:marcos.silva@gmail.com] 
Sent: Wednesday, February 21, 2007 11:02 PM
To: Maven Users List
Subject: Re: Mojo accessing project properties

Hi, you need annotate you mojo with @requiresProject tag:

/**
 * Verifies that the dependencies of the project are official.
 *
 * @goal verify
 *
 * @phase validate
 * @requiresProject
 * @requiresDependencyResolution
 */
public class VerifyDependenciesMojo extends AbstractMojo { ... }

So, maven will do all stuff that is necessary to parse pom and create
MavenProject object before start your mojo. Because you need to access
dependencies project, you also need to use the
@requiresDependencyResolution.

Hope this helps.


On 2/17/07, David Jackman <Da...@fastsearch.com> wrote:
>
> At this point, it's a simple mojo that I'm executing via the command 
> line (trying to figure out how I can get at this information and what 
> form it comes in since no docs explain this).  This mojo will 
> eventually be attached to the verify phase, and that's what's in the 
> mojo now.  Are the properties not available at that stage?  The entire
mojo code is below.
>
> ..David..
>
>
> /**
> * Verifies that the dependencies of the project are official.
> *
> * @goal verify
> *
> * @phase validate
> */
> public class VerifyDependenciesMojo extends AbstractMojo {
>     /**
>      * Dependencies to verify.
>      * Items in the list will be of type 
> org.apache.maven.model.Dependency .
>      *
>      * @parameter default-value="${project.dependencies}"
>      * @required
>      * @readonly
>      */
>     private List dependencies;
>
>     /**
>      * Project properties.
>      *
>      * @parameter default-value="${project.properties}"
>      * @required
>      * @readonly
>      */
>     private Properties properties;
>
>     /**
>      * @see AbstractMojo#execute()
>      */
>     public void execute() throws MojoExecutionException, 
> MojoFailureException
>     {
>         getLog().debug("Properties: " + properties);
>     }
> }
>
>
> ________________________________
>
> From: Jason van Zyl [mailto:jason@maven.org]
> Sent: Fri 2/16/2007 8:38 PM
> To: Maven Users List
> Subject: Re: Mojo accessing project properties
>
>
>
> What's the rest of your mojo look like?
>
> Are you using @execute phase="something"?
>
> Jason.
>
> On 16 Feb 07, at 4:43 PM 16 Feb 07, David Jackman wrote:
>
> > I'm trying to write a mojo that accesses the properties section of 
> > the project pom.  I declared a member variable like this
> >     /**
> >      * Project properties.
> >      *
> >      * @parameter default-value="${project.properties}"
> >      * @required
> >      * @readonly
> >      */
> >     private Properties properties;
> > When my mojo runs, it gets a Properties object okay, but it's always

> > empty, even if I have declared properties in the project POM.
> >
> > Am I doing something wrong?  How do I access the project properties 
> > (not plugin configuration properties)?
> >
> > ..David..
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



--
Marcos Silva Pereira
recife - pe
marcos.silva@gmail.com
skype: marcos.silva.pereira
http://blastemica.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Mojo accessing project properties

Posted by Marcos Silva Pereira <ma...@gmail.com>.
Hi, you need annotate you mojo with @requiresProject tag:

/**
 * Verifies that the dependencies of the project are official.
 *
 * @goal verify
 *
 * @phase validate
 * @requiresProject
 * @requiresDependencyResolution
 */
public class VerifyDependenciesMojo extends AbstractMojo { ... }

So, maven will do all stuff that is necessary to parse pom and create
MavenProject object before start your mojo. Because you need to access
dependencies project, you also need to use the
@requiresDependencyResolution.

Hope this helps.


On 2/17/07, David Jackman <Da...@fastsearch.com> wrote:
>
> At this point, it's a simple mojo that I'm executing via the command line
> (trying to figure out how I can get at this information and what form it
> comes in since no docs explain this).  This mojo will eventually be attached
> to the verify phase, and that's what's in the mojo now.  Are the properties
> not available at that stage?  The entire mojo code is below.
>
> ..David..
>
>
> /**
> * Verifies that the dependencies of the project are official.
> *
> * @goal verify
> *
> * @phase validate
> */
> public class VerifyDependenciesMojo extends AbstractMojo
> {
>     /**
>      * Dependencies to verify.
>      * Items in the list will be of type org.apache.maven.model.Dependency
> .
>      *
>      * @parameter default-value="${project.dependencies}"
>      * @required
>      * @readonly
>      */
>     private List dependencies;
>
>     /**
>      * Project properties.
>      *
>      * @parameter default-value="${project.properties}"
>      * @required
>      * @readonly
>      */
>     private Properties properties;
>
>     /**
>      * @see AbstractMojo#execute()
>      */
>     public void execute() throws MojoExecutionException,
> MojoFailureException
>     {
>         getLog().debug("Properties: " + properties);
>     }
> }
>
>
> ________________________________
>
> From: Jason van Zyl [mailto:jason@maven.org]
> Sent: Fri 2/16/2007 8:38 PM
> To: Maven Users List
> Subject: Re: Mojo accessing project properties
>
>
>
> What's the rest of your mojo look like?
>
> Are you using @execute phase="something"?
>
> Jason.
>
> On 16 Feb 07, at 4:43 PM 16 Feb 07, David Jackman wrote:
>
> > I'm trying to write a mojo that accesses the properties section of the
> > project pom.  I declared a member variable like this
> >     /**
> >      * Project properties.
> >      *
> >      * @parameter default-value="${project.properties}"
> >      * @required
> >      * @readonly
> >      */
> >     private Properties properties;
> > When my mojo runs, it gets a Properties object okay, but it's always
> > empty, even if I have declared properties in the project POM.
> >
> > Am I doing something wrong?  How do I access the project properties
> > (not
> > plugin configuration properties)?
> >
> > ..David..
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



-- 
Marcos Silva Pereira
recife - pe
marcos.silva@gmail.com
skype: marcos.silva.pereira
http://blastemica.blogspot.com

RE: Mojo accessing project properties

Posted by David Jackman <Da...@fastsearch.com>.
At this point, it's a simple mojo that I'm executing via the command line (trying to figure out how I can get at this information and what form it comes in since no docs explain this).  This mojo will eventually be attached to the verify phase, and that's what's in the mojo now.  Are the properties not available at that stage?  The entire mojo code is below.
 
..David..
 
 
/**
 * Verifies that the dependencies of the project are official.
 *
 * @goal verify
 *
 * @phase validate
 */
public class VerifyDependenciesMojo extends AbstractMojo
{
    /**
     * Dependencies to verify.
     * Items in the list will be of type org.apache.maven.model.Dependency.
     *
     * @parameter default-value="${project.dependencies}"
     * @required
     * @readonly
     */
    private List dependencies;

    /**
     * Project properties.
     *
     * @parameter default-value="${project.properties}"
     * @required
     * @readonly
     */
    private Properties properties;
 
    /**
     * @see AbstractMojo#execute()
     */
    public void execute() throws MojoExecutionException, MojoFailureException
    {
        getLog().debug("Properties: " + properties);
    }
}


________________________________

From: Jason van Zyl [mailto:jason@maven.org]
Sent: Fri 2/16/2007 8:38 PM
To: Maven Users List
Subject: Re: Mojo accessing project properties



What's the rest of your mojo look like?

Are you using @execute phase="something"?

Jason.

On 16 Feb 07, at 4:43 PM 16 Feb 07, David Jackman wrote:

> I'm trying to write a mojo that accesses the properties section of the
> project pom.  I declared a member variable like this
>     /**
>      * Project properties.
>      *
>      * @parameter default-value="${project.properties}"
>      * @required
>      * @readonly
>      */
>     private Properties properties;
> When my mojo runs, it gets a Properties object okay, but it's always
> empty, even if I have declared properties in the project POM.
>
> Am I doing something wrong?  How do I access the project properties 
> (not
> plugin configuration properties)?
>
> ..David..
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org





Re: Mojo accessing project properties

Posted by Jason van Zyl <ja...@maven.org>.
What's the rest of your mojo look like?

Are you using @execute phase="something"?

Jason.

On 16 Feb 07, at 4:43 PM 16 Feb 07, David Jackman wrote:

> I'm trying to write a mojo that accesses the properties section of the
> project pom.  I declared a member variable like this
>     /**
>      * Project properties.
>      *
>      * @parameter default-value="${project.properties}"
>      * @required
>      * @readonly
>      */
>     private Properties properties;
> When my mojo runs, it gets a Properties object okay, but it's always
> empty, even if I have declared properties in the project POM.
>
> Am I doing something wrong?  How do I access the project properties  
> (not
> plugin configuration properties)?
>
> ..David..
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org