You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Steinar Bang <sb...@dod.no> on 2007/12/15 22:19:10 UTC

Not run maven-antrun-plugin task with file present?

Platform: Ubuntu 7.10, Intel Pentium M, maven 2.0.4

How does one avoid doing a maven-antrun-task when a file is present?

Here's what I do:
 - Unzip a zip file with dependency:unpack
 - Add a couple of jars into the unpacked zip file with dependency:copy
 - Modify the config in two XML files in the unpacked zip file, to tell
   it about the jars 
 - Rezip the zip file and install it in the local maven repo

This works, but I have to always do "mvn clean install" to avoid the
config being modified more than once, which messes it up, and "mvn clean
install" is a nuisance when I'm running this project as part of a
compound project.

What I have done is add an empty marker file with the touch task when I
do the config.

What I have tried to do, and been unsuccessful in, was to detect this
marker and not do the modification, inside the maven-antrun-plugin's
<tasks> element.

I've also tried (and not really expected to succeed), in using a
previous maven-antrun-plugin <task> to set a property if the marker file
is present, and use that property in an unless attribute on the <tasks>
element that does the config modification.

So... is there another plugin, or built-in maven stuff that can set a
maven property if a file is present?

(maven properties are visible inside maven-antrun-plugin tasks, but
properties set inside tasks are (probably... I haven't found any
documentation on this) not visible outside the task.  At least setting a
property in one task to determine if the next one should be run, doesn't
seem to work.)

Thanx!


- Steinar


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


Re: Not run maven-antrun-plugin task with file present?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

[snip! On using a profile to detect file presence]
> It now works when I do "mvn install" (config is modified), and
> repeated installs (config is left alone).

> But when I do "mvn clean install" then config is not modified
> (probably because the marker is still there at the time of profile
> activation).

> Of course, since the marker is deleted, but not recreated, the next
> "mvn install" will modify the config, and repeated "mvn install"
> invocations will leave it alone.

> So the behaviour is less destructive than before (ie. the config is
> never modified beyond corruption), but it may be wrong the first time,
> and that behaviour is confusing.

> Not sure how to fix this.

To complete the thread: I ended up having to bite the bullet, and put
the stuff done by ant into a separate ant build file, and invoke it from
an ant task in maven-antrun-plugin.

This works, ie. both "mvn clean install" and "mvn install" gives the
expected results (patching of config the first time after a clean, and
no more patching after that).

It also allows me to use a property for the marker file name (a property
that is a function of other properties, and eventually based on
${project.build.directory}).

The drawbacks are:
 1. there is an extra file to keep track of and put changes in
 2. running an ant task seems to be a lot more costly in time, than
    having the ant tasks inline in the POM
 3. it doesn't do property expansion in the replacevalue elements (that
    was probably done by maven with the inlined maven-antrun-plugin
    tasks) 


- Steinar


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


Re: Not run maven-antrun-plugin task with file present?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

>>>>> "Wendy Smoak" <ws...@gmail.com>:

[snip!]
>> But actually it sounds like you may want to just activate the profile
>> if one of the files that would be created is _missing_.

> Yes.  The marker file I create with <touch> in a maven-antrun-plugin
> task.

>> There's an example of that on this page:
>> http://maven.apache.org/guides/introduction/introduction-to-profiles.html

> Thanx!  I'll give it a look.

Now I've moved the entire maven-antrun-plugin config for the config
modification, into a profile that's activated with
 <file>
  <missing>full-path-to-the-marker-file</missing>
 </file>

and that works after a fashion (except that the full-path thingy is a
nuisance).

It now works when I do "mvn install" (config is modified), and repeated
installs (config is left alone).  

But when I do "mvn clean install" then config is not modified (probably
because the marker is still there at the time of profile activation).

Of course, since the marker is deleted, but not recreated, the next "mvn
install" will modify the config, and repeated "mvn install" invocations
will leave it alone.

So the behaviour is less destructive than before (ie. the config is
never modified beyond corruption), but it may be wrong the first time,
and that behaviour is confusing.

Not sure how to fix this.


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


Re: Not run maven-antrun-plugin task with file present?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> "Wendy Smoak" <ws...@gmail.com>:

> On Dec 15, 2007 2:19 PM, Steinar Bang <sb...@dod.no> wrote:
>> Platform: Ubuntu 7.10, Intel Pentium M, maven 2.0.4
>> 
>> How does one avoid doing a maven-antrun-task when a file is present?

> Try wrapping the execution in a profile, and activating that profile
> on the presence of the file.

The main problem with profiles is that <exists> doesn't take properties,
not even proprties like ${basedir} (at least not in maven 2.0.4 which
I'm stuck with for the duration).

So you can get the <exists> to run in a particular project, but not
neccessarily when run as a part of composite, unless... well I guess you
could activate on all different paths there could be to the file
(ie. from the parent, and from the project itself), but that could get
messy pretty quick.  Especially if you have to copy the
maven-antrun-plugin task to the different profiles.

The second problem with profiles is that they make the POMs hard to read
and understand.

One thing is if you can make do with setting properties in the profiles,
but that only works if you can do it in a parent (I think...?).  But if
you have to put <plugins> stuff in a profile, you get one part of a
plugins config living outside the profile and one inside.

It makes it easy to overlook stuff that's actually related.

> But actually it sounds like you may want to just activate the profile
> if one of the files that would be created is _missing_. 

Yes.  The marker file I create with <touch> in a maven-antrun-plugin
task. 

> There's an example of that on this page:
> http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Thanx!  I'll give it a look.


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


Re: Not run maven-antrun-plugin task with file present?

Posted by Wendy Smoak <ws...@gmail.com>.
On Dec 15, 2007 2:19 PM, Steinar Bang <sb...@dod.no> wrote:

> Platform: Ubuntu 7.10, Intel Pentium M, maven 2.0.4
>
> How does one avoid doing a maven-antrun-task when a file is present?

Try wrapping the execution in a profile, and activating that profile
on the presence of the file.

But actually it sounds like you may want to just activate the profile
if one of the files that would be created is _missing_.  There's an
example of that on this page:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

-- 
Wendy

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