Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the last inconsistencies in generics #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

twogee
Copy link
Contributor

@twogee twogee commented Jul 27, 2017

... use collections, not arrays

@jaikiran
Copy link
Member

Overall, this looks fine to me. I just need some inputs from the rest of the team on one specific change, for which I have raised a dev list thread https://www.mail-archive.com/[email protected]/msg46002.html

@twogee
Copy link
Contributor Author

twogee commented Jul 28, 2017

The new method is taken from AbstractOSGiResolver where a corresponding method is made public. All resolvers implement only the new method and the fallback for the deprecated method is moved to AbstractResolver. The new method is crucial for the SearchEngine to work properly; leave it out and you may as well leave out everything.

@twogee
Copy link
Contributor Author

twogee commented Jul 28, 2017

The methods in AbstractResolver must be defined the other way around: the default implementation of the method with new signature should call the method with the old signature. May I amend the commit?

@twogee
Copy link
Contributor Author

twogee commented Jul 28, 2017

The same applies to ChainResolver (which should check resolver type as suggested by @jaikiran); actually, all custom resolvers that do not extend AbstractResolver could be wrapped in the chain resolver as a workaround.

@twogee
Copy link
Contributor Author

twogee commented Jul 29, 2017

Is this sufficient, or should I add an extra check in ChainResolver

            if (resolver instanceof AbstractResolver || hasGenericMethod(resolver)) {
...
            }
...

    private boolean hasGenericMethod(DependencyResolver resolver) {
        try {
            return resolver.getClass().getDeclaredMethod("listTokenValues",
                    Set.class, Map.class).getReturnType().getSimpleName().equals("Set");
        } catch (NoSuchMethodException e) {
            return false;
        }
    }

@jaikiran
Copy link
Member

jaikiran commented Aug 2, 2017

Hi Gintas,

To be clear - what I meant/proposed in the dev list was:

  • It's fine to have all the changes related to introducing that new method with Java generics on the implementation classes, including the AbstractResolver. No objections to it.

  • However, I think we shouldn't yet introduce it on the DependencyResolver interface in this release.

  • Finally, as you note in the latest comment, we would need to do a type check in our (internal) classes where we use the DependencyResolver interface's listTokenValues method to see if it's of type AbstractResolver and if it is, then invoke the new generic method. Else invoke the older method. We don't need to do a reflection check to see whether the resolver has the generic listTokenValues method, since the other existing method should just function as normal. So ultimately something like:

    if (resolver instanceof AbstractResolver) {
       Set<Map<String, String>> tokenVals = resolver.listTokenValues(...) // the new generic method
    } else {
       // call the method that's exposed via the DependencyResolver interface - the one which doesn't use generics
      Map<String, String>[] tokenVals = resolver.listTokenValues(...);
    }

In short, in this release, don't expose this as a new API on the interface but expose it on the AbstractResolver with an internal implementation that will trickle down to all external resolvers that extend the AbstractResolver.

Again, I'm being a bit extra cautious on this specific interface unlike some other interface/class changes that we have been doing since this one acts as the central well known contract to the developers who have extended Ivy. Plus the fact that we do have a way to do all the changes being proposed in this PR without having to force the implementations of the DependencyResolver to implement that new method in this specific release.

@twogee
Copy link
Contributor Author

twogee commented Aug 2, 2017

Thanks for clarifying.

My point was that the use of the method is limited to two classes: SearchEngine and ChainResolver (because it is essentially a proxy).

A quick search seems to indicate that most (if not all) custom resolver implementations out there extend AbstractResolver, and thus providing a default implementation of the method with the new signature as a wrapper in the abstract class will mitigate the problems due to the lack of it.

Therefore I would like to insist on adding the method to the interface as well as changing the signature in all resolvers that ship with Ivy. Any public method in the abstract class should be declared in the interface, and going halfway does not make much sense.

@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from a30ac81 to bf4db7c Compare August 6, 2017 21:12
@hibnico
Copy link
Contributor

hibnico commented Aug 6, 2017

@twogee, you have looked into the open sources softwares that use Ivy, but Ivy is under the ASL, not the GPL, it might be used in some closed, commercial products :)
So we cannot know for sure that we won't break softwares by changing that part of the API.

The hierarchy of the classes of the DependencyResolver is not of the best design, it would have been great to have more composition than inheritance. But that's we have. So unless we want to break things, rewrite things and make an Ivy3, I think we should stick with it.

To move forward, I suggest that this PR doesn't break the API at all. And if you still think DependencyResolver deserve a probably-safe API break, you're welcomed to discuss it on ant-dev so we can get a consensus.

@twogee
Copy link
Contributor Author

twogee commented Aug 7, 2017

@nlalevee, we already broke a few things by going Java 7 (and gained native symlinks 😉). For more examples, look at commons-lang3 breaking off commons-text and introducing escapeHtml3 and escapeHtml4 instead of escapeHtml -- all without changing a major version. Pointing to some hypothetical closed code is a poor excuse -- as if commercial vendors (or their customers) have no QA and expect the dependencies to be drop-ins every time. I will present the argument on ant-dev in a more coherent form later.

@twogee twogee force-pushed the consistent-generics branch 8 times, most recently from 74d1de7 to f877d82 Compare August 24, 2017 11:21
@twogee twogee force-pushed the consistent-generics branch 3 times, most recently from 036ac6d to a49d4ac Compare September 3, 2017 10:46
@twogee twogee changed the title fix last inconsistencies in generics fix the last inconsistencies in generics Sep 3, 2017
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from 2efe5de to 5badc7a Compare September 8, 2017 17:44
@twogee twogee force-pushed the consistent-generics branch 3 times, most recently from 8344060 to 59fc3a4 Compare September 17, 2017 19:47
@twogee twogee force-pushed the consistent-generics branch 4 times, most recently from 3c02117 to 81f6e9d Compare November 14, 2017 06:21
@twogee twogee force-pushed the consistent-generics branch 3 times, most recently from b2d4a68 to 83e4c0e Compare December 8, 2017 06:55
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from c20fcee to 973aa5f Compare February 3, 2018 06:55
@twogee twogee mentioned this pull request Feb 9, 2018
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from 89a8cac to e8d0f84 Compare March 3, 2018 11:22
@twogee twogee force-pushed the consistent-generics branch 3 times, most recently from 145d812 to 5668f0c Compare March 15, 2018 18:44
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from 836f253 to de9e402 Compare March 21, 2018 15:57
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from bd439f3 to 7bac30c Compare August 29, 2018 06:52
@twogee twogee force-pushed the consistent-generics branch 2 times, most recently from 4cc056d to 109afaf Compare October 30, 2019 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants