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

[MDEP-832] - Remove commons-collections-4 #255

Merged
merged 1 commit into from
Aug 15, 2023
Merged

[MDEP-832] - Remove commons-collections-4 #255

merged 1 commit into from
Aug 15, 2023

Conversation

khmarbaise
Copy link
Member

@khmarbaise khmarbaise commented Oct 20, 2022

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MDEP-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MDEP-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

return new LinkedHashSet<>(
CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) );
// @formatter:on
Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) );
Copy link

@gnodet gnodet Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggled on that one a few weeks ago.
Given the two sets are the same, I think the result will always be an empty set.
So I would just simply remove that call and the two added classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they are not the same. The first list (modelDependencies2) contains two entries (junit) while the hashset contains only a single entry of that and the result must be the single junit-jar difference. Check the unit test: TestAnalyzeDuplicateMojo testcase testDuplicate and testDuplicate2 which references src/test/resources/unit/duplicate-dependencies/plugin-config.xml and the src/test/resources/unit/duplicate-dependencies/plugin-config2.xml which contains exactly those cases.

Copy link

@gnodet gnodet Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. But then, wouldn't it be simpler and more understandable :

    /**
     * Remove exactly one instance of each element from the given list. 
     */
    static <O> List<O> symmetricDifference( Collection<O> elements )
    {
        List<O> list = new ArrayList<>( elements );
        Set<O> set = new HashSet<>( elements );
        list.removeIf( set::remove );
        return list;
    }

It passes the slightly adapted tests in the UtilTest (the two last ones).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could even be inlined with a simple comment...

Copy link

@gnodet gnodet Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shortest form could be:

    private Set<String> findDuplicateDependencies( List<Dependency> modelDependencies )
    {
        List<String> modelDependencies2 = modelDependencies.stream()
                .map( Dependency::getManagementKey ).collect( Collectors.toList() );
        // remove one instance of each element from the list
        modelDependencies2.removeIf( new HashSet<>( modelDependencies2 )::remove );
        // keep a single instance of each duplicate
        return new LinkedHashSet<>( modelDependencies2 );
    }

Copy link

@bmarwell bmarwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Guillaume. Please simplify (or remove) the util class with the code he provided.
After that, consider my changes request obsolete. :)

pom.xml Outdated Show resolved Hide resolved
import static java.util.stream.Collectors.summingInt;
import static java.util.stream.Collectors.toList;

class Util
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a more specific name. Arguably this can be a private method in the class that uses it.

@asfgit asfgit merged commit c6973da into master Aug 15, 2023
15 checks passed
@asfgit asfgit deleted the MDEP-832 branch August 15, 2023 15:49
@@ -260,11 +260,6 @@ under the License.
<artifactId>commons-collections4</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't you mean to remove this one?

@elharo
Copy link
Contributor

elharo commented Oct 26, 2023

There were a number of pom changes in flight at the same time so it looks like some of the PRs got a little mixed up when resolving merge conflicts, but I think it is removed at HEAD.

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.

6 participants