On Nov 13, 2007 10:00 PM, Maarten Coene <[EMAIL PROTECTED]> 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/

Reply via email to