You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Chris Patti <cp...@gmail.com> on 2008/03/13 20:40:00 UTC
Is there a programmatic way to get a list of currently active profiles from within a plugin in Maven 2.0.6?
Folks;
What I want to do is fairly simple. We have a number of destructive unit
tests in our environment that should NEVER be run against production, and I
want to enforce that by attaching a plugin to the validate or initialize
phase that will fail the build if "PROD" is in the current list of active
profiles AND if maven.test.skip is either false or undefined.
<plugin>
<groupId>org.codehaus.mojo.groovy</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<executions>
<execution>
<id>prevent-tests-against-prod</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
if ((${project.activeprofile} == "PROD")
&& (${maven.test.skip} != "true"))
{
fail("Running unit tests against
production is NEVER OK!");
}
</source>
</configuration>
</execution>
... (additional executions follow>
So, is there a way to make this happen? I realize I can use mvn
help:active-profiles but having to parse the output of that command is messy
and I'm guessing there's a better way.
Thanks,
-Chris
--
Chris Patti --- Y!: feoh -- AIM: chrisfeohpatti --- E-Mail: cpatti@gmail.com
"Technological progress is like an ax in the hands of a pathological
criminal." -Albert Einstein
Re: Is there a programmatic way to get a list of currently active profiles from within a plugin in Maven 2.0.6?
Posted by Chris Patti <cp...@gmail.com>.
On Thu, Mar 13, 2008 at 6:15 PM, Samuel Le Berrigaud <sa...@gmail.com>
wrote:
> Well if I had to do it I would actually have a look in the code of the
> maven-help-plugin. Seems like it wouldn't be difficult from there to
> implement the plugin you want…
>
> SaM
>
Thanks, the Groovy code I ended up with looks like this:
---
// Run through the currently active
// profiles, checking to see if this one
// is in use.
def scanActiveProfiles(String profileId)
{
List profiles =
project.getActiveProfiles();
profiles.each {
p = it;
print "Profile IDs: " + p.getId() +
"\n";
}
}
---
I'm switching gears slightly and writing a full plugin instead of using the
groovy-maven-plugin and inline code execution because that way I can just
pass properties not attached to the project (like maven.test.skip) into the
plugin.
-Chris
--
Chris Patti --- Y!: feoh -- AIM: chrisfeohpatti --- E-Mail: cpatti@gmail.com
"Technological progress is like an ax in the hands of a pathological
criminal." -Albert Einstein
Re: Is there a programmatic way to get a list of currently active profiles from within a plugin in Maven 2.0.6?
Posted by Samuel Le Berrigaud <sa...@gmail.com>.
Well if I had to do it I would actually have a look in the code of the
maven-help-plugin. Seems like it wouldn't be difficult from there to
implement the plugin you want…
SaM
On Fri, Mar 14, 2008 at 6:40 AM, Chris Patti <cp...@gmail.com> wrote:
> Folks;
>
> What I want to do is fairly simple. We have a number of destructive unit
> tests in our environment that should NEVER be run against production, and
> I
> want to enforce that by attaching a plugin to the validate or initialize
> phase that will fail the build if "PROD" is in the current list of active
> profiles AND if maven.test.skip is either false or undefined.
>
> <plugin>
> <groupId>org.codehaus.mojo.groovy</groupId>
> <artifactId>groovy-maven-plugin</artifactId>
> <executions>
> <execution>
> <id>prevent-tests-against-prod</id>
> <phase>initialize</phase>
> <goals>
> <goal>execute</goal>
> </goals>
> <configuration>
> <source>
> if ((${project.activeprofile} == "PROD")
> && (${maven.test.skip} != "true"))
> {
> fail("Running unit tests against
> production is NEVER OK!");
> }
> </source>
> </configuration>
> </execution>
> ... (additional executions follow>
>
> So, is there a way to make this happen? I realize I can use mvn
> help:active-profiles but having to parse the output of that command is
> messy
> and I'm guessing there's a better way.
>
> Thanks,
> -Chris
>
> --
> Chris Patti --- Y!: feoh -- AIM: chrisfeohpatti --- E-Mail:
> cpatti@gmail.com
> "Technological progress is like an ax in the hands of a pathological
> criminal." -Albert Einstein
>
--
Samuel Le Berrigaud