You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-dev@incubator.apache.org by Xavier Hanin <xa...@gmail.com> on 2007/11/13 23:49:49 UTC

Re: svn commit: r594481 - in /incubator/ivy/core/trunk: ./ src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/util/ test/java/org/apache/ivy/ test/java/org/apache/ivy/ant/ test/java/org/apache/

On Nov 13, 2007 10:00 PM, Maarten Coene <ma...@yahoo.com> wrote:

> Xavier,
>
> this change broke some tests. Could you take a look at it?

Sure, sorry about that.

I've just checked in a fix, things should be ok now. For one of the two
failing tests, I had to modify the test. Indeed the test makes use of
several methods in Ivy and CacheManager, but now the IvyContext is clearer
after the call to ivy methods, so during the later call to CacheManager
method, the context is not set anymore, which is causing a problem in this
particular case, because the retaining artifact mechanism relies on the
context used during the resolve.

Ideally due to the change in the Ivy "API" (requirement to push a context
manually whenever you call several related methods consecutively) we should
change almost all our unit tests, which most of the time call methods on ivy
engines directly, and not on the Ivy instance itself. In practice this is
only necessary when consecutive methods actually use the context, which was
only the case in one unit test. But if we later make more extensive use of
IvyContext, we may have to generalize context pushing/poping in all our unit
tests. This could be done in the setup/teardown, but we need to push a
context which ensure Ivy itself won't push another in its methods, which is
not possible ATM (except if you know the Ivy instance when you push the
context, but it's not possible in all unit tests). This means that we would
have to create some kind of special IvyContext which Ivy would recognize in
its pushContext() method to attach to it rather than creating a new sub
context. Or maybe this could simply be done by checking in the pushContext()
method not only if the current Ivy instance is the same as the current but
also if it is null. Something like this:

    public void pushContext() {
        if (IvyContext.getContext().peekIvy() == null) {
            IvyContext.getContext().setIvy(this);
            IvyContext.pushContext(IvyContext.getContext());
        } else if (IvyContext.getContext().peekIvy() != this) {
            IvyContext.pushNewContext();
            IvyContext.getContext().setIvy(this);
        } else {
            IvyContext.pushContext(IvyContext.getContext());
        }
    }

WDYT?

Xavier

-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/

Re: svn commit: r594481 - in /incubator/ivy/core/trunk: ./ src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/util/ test/java/org/apache/ivy/ test/java/org/apache/ivy/ant/ test/java/org/apache/

Posted by Xavier Hanin <xa...@gmail.com>.
On Nov 14, 2007 12:49 AM, Xavier Hanin <xa...@gmail.com> wrote:

> On Nov 13, 2007 10:00 PM, Maarten Coene <ma...@yahoo.com> wrote:
>
> > Xavier,
> >
> > this change broke some tests. Could you take a look at it?
>
> Sure, sorry about that.
>
> I've just checked in a fix, things should be ok now. For one of the two
> failing tests, I had to modify the test. Indeed the test makes use of
> several methods in Ivy and CacheManager, but now the IvyContext is clearer
> after the call to ivy methods, so during the later call to CacheManager
> method, the context is not set anymore, which is causing a problem in this
> particular case, because the retaining artifact mechanism relies on the
> context used during the resolve.
>
> Ideally due to the change in the Ivy "API" (requirement to push a context
> manually whenever you call several related methods consecutively) we should
> change almost all our unit tests, which most of the time call methods on ivy
> engines directly, and not on the Ivy instance itself. In practice this is
> only necessary when consecutive methods actually use the context, which was
> only the case in one unit test. But if we later make more extensive use of
> IvyContext, we may have to generalize context pushing/poping in all our unit
> tests. This could be done in the setup/teardown, but we need to push a
> context which ensure Ivy itself won't push another in its methods, which is
> not possible ATM (except if you know the Ivy instance when you push the
> context, but it's not possible in all unit tests). This means that we would
> have to create some kind of special IvyContext which Ivy would recognize in
> its pushContext() method to attach to it rather than creating a new sub
> context. Or maybe this could simply be done by checking in the pushContext()
> method not only if the current Ivy instance is the same as the current but
> also if it is null. Something like this:
>
>     public void pushContext() {
>         if (IvyContext.getContext().peekIvy() == null) {
>             IvyContext.getContext().setIvy(this);
>             IvyContext.pushContext(IvyContext.getContext());
>         } else if (IvyContext.getContext().peekIvy() != this) {
>             IvyContext.pushNewContext();
>             IvyContext.getContext().setIvy(this);
>         } else {
>             IvyContext.pushContext(IvyContext.getContext());
>         }
>     }
>
The problem with that is that it defeats the whole purpose of context
pushing and popping: the context associated before calling an Ivy method
will then have this Ivy instance attached, so this is not a good answer to
the problem. A better solution would be to use something specific, for which
we could be sure the user has purposefully pushed a context and will thus
pop it.

Xavier

>
>
> WDYT?
>
> Xavier
>
> --
> Xavier Hanin - Independent Java Consultant
> http://xhab.blogspot.com/
> http://ant.apache.org/ivy/
> http://www.xoocode.org/




-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/