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-568] go offline filter #135

Closed
wants to merge 3 commits into from
Closed

Conversation

bmarwell
Copy link

@bmarwell bmarwell commented Jun 1, 2021

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.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

All the filters should have unit tests.

@@ -0,0 +1,59 @@
package org.apache.maven.plugins.dependency.filters;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this introducing a new package? Probably not needed.

Copy link
Author

Choose a reason for hiding this comment

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

Yup, because code is similar to artifact-filter's ArtifactFilter which is also in its own package. Also, more filters could be introduced later. Is there a downside of creating a package I do not know?

Copy link
Contributor

Choose a reason for hiding this comment

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

It tends to force methods to be public for use by other subpackages that otherwise wouldn't have to be public.

Choose a reason for hiding this comment

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

@elharo is this change a requirement for this PR to be accepted? I agree with @bmarwell approach (to be future proof), but if it is mandatory, I think it is possible to change packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, packaghes are overused with bad consequences

@bmarwell bmarwell force-pushed the MDEP-568_go-offline_filter branch from 68600d6 to ab8d8d3 Compare June 1, 2021 17:26
@bmarwell bmarwell requested a review from elharo June 1, 2021 17:27
@bmarwell bmarwell requested a review from elharo June 2, 2021 07:03
import java.util.Set;


abstract class AbstractDependencyFilter implements DependencyFilter
Copy link

Choose a reason for hiding this comment

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

Hello @bmarwell ,
Since you created this abstract class, maybe it could contain more than just splitValues method. The inherited classes are very similar IMO; This way, this abstract class could have almost all logic here, with the filter, include and exclude methods; It is just a suggestion to avoid code duplication.

Below an example of the abstract class and one of its child. Even the filterexcludeIds and filterincludeIds could be simplified because they share similar logic.

As ScopeFilter has specific treatment to split include and exclue ids, I created two functions splitIncludeIds and splitExcludeIds

	abstract class AbstractDependencyFilter implements DependencyFilter
	{
	protected final String includeIds;

	protected final String excludeIds;

	public AbstractDependencyFilter(String includeIds, String excludeIds)
	{
		this.includeIds = includeIds == null ? "" : includeIds;
		this.excludeIds = excludeIds == null ? "" : excludeIds;
	}


	@Override
	public Set<Dependency> filter(Set<Dependency> dependencies)
	{
		Set<Dependency> filtered = new HashSet<>(dependencies);

		filtered = filterincludeIds(filtered);
		filtered = filterexcludeIds(filtered);

		return filtered;
	}

	private Set<Dependency> filterexcludeIds(Set<Dependency> dependencies)
	{
		if (excludeIds.trim().isEmpty()) {
			return dependencies;
		}

		final Set<String> excludedIds = splitExcludeIds(excludeIds);

		Set<Dependency> filtered = new HashSet<>(dependencies.size());
		for (Dependency dependency : dependencies) {
			if (excludedIds.contains(getContainsProperty(dependency))) {
				continue;
			}

			filtered.add(dependency);
		}

		return filtered;
	}


	private Set<Dependency> filterincludeIds(Set<Dependency> dependencies)
	{
		if (includeIds.trim().isEmpty()) {
			return dependencies;
		}

		Set<String> includedIds = splitIncludeIds(includeIds);

		Set<Dependency> filtered = new HashSet<>(dependencies.size());
		for (Dependency dependency : dependencies) {
			if (includedIds.contains(getContainsProperty(dependency))) {
				filtered.add(dependency);
			}
		}

		return filtered;
	}

	protected Set<String> splitExcludeIds(String excludeIds) {
		return splitValues(excludeIds);
	}

	protected Set<String> splitIncludeIds(String includeIds) {
		return splitValues(includeIds);
	}

	protected Set<String> splitValues(String csvValueList) {
		// ommited here
	}

	abstract protected String getContainsProperty(Dependency dependency);

}
	public class GroupIdFilter extends AbstractDependencyFilter
	{

		public GroupIdFilter(String includeGroupIds, String excludeGroupIds)
		{
			super(includeGroupIds, excludeGroupIds);
		}

	    protected String getContainsProperty(Dependency dependency) {
			return dependency.getGroupId();
		}

	}

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking of closing this PR. We would need the same logic for other goals as well, and this goal could be replaced with the combination of two other goals.

I think you could just create a PR to my branch of you're interested to keep it up.

Choose a reason for hiding this comment

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

Created the PR to your branch: #145

Should I change anything else? There is a apparently unfinished thread about package names in June 1st.

Do I have to sign any documents? Please let me know.

PS.: I am sorry, butI did not understand why you are thinking in close this PR. Which goals are you talking about? Should they be a part in this PR? I think this PR solves the go-offline problem, which is the subject of MDEP-568.

@bmarwell
Copy link
Author

@elharo can you please look over this PR again?

@TimKnight-DWP
Copy link

Would really appreciate this being re-looked at and merged, it causes us problems when caching dependencies in Gitlab if these filters don't actually work.

Happy to provide input/coding

@elharo @bmarwell

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

assorted comments; though there seems to be some question from others about the overall approach that you might want to address first

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

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

Why all the tildes in the license?

Choose a reason for hiding this comment

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

removed in #258. It is a pull request to this branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. I still see them. Do you need to merge to master?

<version>2.0.6</version>
</dependency>
<dependency>
<groupId>non.existant.group</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: existent with an e

Choose a reason for hiding this comment

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

fixed in #258

return filtered;
}

private Set<Dependency> filterexcludeIds( Set<Dependency> dependencies )
Copy link
Contributor

Choose a reason for hiding this comment

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

filterExcludeIds

Choose a reason for hiding this comment

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

fixed in #258

Set<Dependency> filtered = new HashSet<>( dependencies.size() );
for ( Dependency dependency : dependencies )
{
if ( excludedIds.contains( getContainsProperty( dependency ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit awkward. Might be worth adding a local variable, renaming, the method, and/or refactoring with a more complete method

Choose a reason for hiding this comment

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

fixed in #258

It is now like this:

            boolean shouldFilterDependency = ids.contains( getId( dependency ) ) == expectedCondition;
            if ( shouldFilterDependency )
            {
                filtered.add( dependency );
            }

expectedConditionis true for the includeIds case anda false for the exclude. I created one method to remove the code duplication.

{
if ( excludedIds.contains( getContainsProperty( dependency ) ) )
{
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use continue; just change the if to if not

Choose a reason for hiding this comment

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

fixed in #258

public void testArtifactFilterInclude()
{
// given
final Dependency comSunTools = COM_SUN_TOOLS_SYSTEM_JAR;
Copy link
Contributor

Choose a reason for hiding this comment

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

local variables seem redundant here

Choose a reason for hiding this comment

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

fixed in #258

public void testGroupFilterInclude()
{
// given
final Dependency comSunTools = COM_SUN_TOOLS_SYSTEM_JAR;
Copy link
Contributor

Choose a reason for hiding this comment

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

local variables seem redundant here

Choose a reason for hiding this comment

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

fixed in #258

public void testScopeFilterExclude()
{
// given
final Dependency comSunTools = COM_SUN_TOOLS_SYSTEM_JAR;
Copy link
Contributor

Choose a reason for hiding this comment

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

local variables seem redundant here

Choose a reason for hiding this comment

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

fixed in #258

@Test
public void testTypeFilterExclude()
{
// given
Copy link
Contributor

Choose a reason for hiding this comment

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

local variables seem redundant here

Choose a reason for hiding this comment

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

fixed in #258

public class TestGoOfflineMojo extends AbstractDependencyMojoTestCase
{

protected void setUp() throws Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Override

Choose a reason for hiding this comment

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

fixed in #258

@antoniolucasnobar
Copy link

@elharo I fixed in #258 most of your questions.
Also, I resolved the conflicts with master.

About the overall aproach, I was never able to fully understand what is the problem with this one. @bmarwell could you please help with this?

Theoderich and others added 3 commits November 6, 2022 12:39
…wnload artifacts, download the artifacts

in the plugin code after filtering them with the provided parameters.
* [MDEP-568] Move common methods to parent class.

* [MDEP-568] Fix spacing

* [MDEP-568] Fix spacing

* [MDEP-568] Fix formatting

Co-authored-by: Antonio <antonio.lucas@trt4.jus.br>
@jshbrntt
Copy link

jshbrntt commented Aug 9, 2023

Is this going to be merged anytime soon?

It would be really helpful to install and cache dependencies prior to mvn package.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

I don't understand what's going on with this commit. Please make sure it's up to date against master, and comments are addressed here, not in other PRs.

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand. I still see them. Do you need to merge to master?

@@ -0,0 +1,59 @@
package org.apache.maven.plugins.dependency.filters;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, packaghes are overused with bad consequences

@bmarwell
Copy link
Author

bmarwell commented Nov 4, 2023

This is old. If interested, please do a new PR. I'll leave the branch for a while.

@bmarwell bmarwell closed this Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants