You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Allison, Bob" <ro...@qwest.com> on 2005/11/14 21:13:16 UTC

RE: [m2] How to inject values into a bean within a collection definedas a plugin parameter?

The configuration should look like (assuming that your definition of
parameter directory is actually specified as "private String
directory"):

<options>
  <option>
    <directory>/a/b/c</directory>
  </option>
  <option>
    <directory>/d/e/f</directory>
  </option>
</options>

I don't think that the expressions and default values available in the
Mojo are available in the classes used in this manner.  A workaround
might be to place variables which require an expression as a parameter
in the Mojo itself and have a way to propagate it to the sub-objects.

-----Original Message-----
From: Richard Allen [mailto:richard.allen@gtri.gatech.edu] 
Sent: Monday, November 14, 2005 14:59
To: users@maven.apache.org
Subject: [m2] How to inject values into a bean within a collection
definedas a plugin parameter?


I have an array (same question applies to Java Collections) that is 
defined as a parameter of a Mojo:

public class MyMojo extends AbstractMojo {
...
  /**
   * @parameter
   * @required
   */
  private Options[] optionsArray;
...
}

and within the Options bean, I would like to inject properties from
Maven:

public class Options {
...
  /**
   * @parameter expression="${project.build.directory}"
   */
  private directory;
...
}

such that the plugin can be configured like:

      <plugin>
        ...
        <executions>
          <execution>
            ...
            <configuration>
              <optionsArray>
                <options>
                  ...
                </options>
                <options>
                  ...
                </options>
              </compilations>
            </configuration>
            ...
          </execution>
        </executions>
      </plugin>

Is there a way to make this happen? It seems like I should be able to do

this since Maven is creating and populating the bean classes (Options 
class).

Thanks,
Richard Allen

---------------------------------------------------------------------
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: [m2] How to inject values into a bean within a collection definedas a plugin parameter?

Posted by Richard Allen <ri...@gtri.gatech.edu>.
For now, I've added a set method on the Options class for setting a 
default directory, which I get from a parameter in the Mojo. This is 
essentially what you suggested I could do. I just don't think it is very 
clean, and I see how it could be useful (and in this case cleaner) if 
Maven could process annotations on beans in collections that are defined 
as Mojo parameters.

Thanks,
Richard Allen

Allison, Bob wrote:

>The configuration should look like (assuming that your definition of
>parameter directory is actually specified as "private String
>directory"):
>
><options>
>  <option>
>    <directory>/a/b/c</directory>
>  </option>
>  <option>
>    <directory>/d/e/f</directory>
>  </option>
></options>
>
>I don't think that the expressions and default values available in the
>Mojo are available in the classes used in this manner.  A workaround
>might be to place variables which require an expression as a parameter
>in the Mojo itself and have a way to propagate it to the sub-objects.
>
>-----Original Message-----
>From: Richard Allen [mailto:richard.allen@gtri.gatech.edu] 
>Sent: Monday, November 14, 2005 14:59
>To: users@maven.apache.org
>Subject: [m2] How to inject values into a bean within a collection
>definedas a plugin parameter?
>
>
>I have an array (same question applies to Java Collections) that is 
>defined as a parameter of a Mojo:
>
>public class MyMojo extends AbstractMojo {
>...
>  /**
>   * @parameter
>   * @required
>   */
>  private Options[] optionsArray;
>...
>}
>
>and within the Options bean, I would like to inject properties from
>Maven:
>
>public class Options {
>...
>  /**
>   * @parameter expression="${project.build.directory}"
>   */
>  private directory;
>...
>}
>
>such that the plugin can be configured like:
>
>      <plugin>
>        ...
>        <executions>
>          <execution>
>            ...
>            <configuration>
>              <optionsArray>
>                <options>
>                  ...
>                </options>
>                <options>
>                  ...
>                </options>
>              </compilations>
>            </configuration>
>            ...
>          </execution>
>        </executions>
>      </plugin>
>
>Is there a way to make this happen? It seems like I should be able to do
>
>this since Maven is creating and populating the bean classes (Options 
>class).
>
>Thanks,
>Richard Allen
>
>---------------------------------------------------------------------
>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