-
Notifications
You must be signed in to change notification settings - Fork 172
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
src/main/java/org/apache/maven/plugins/dependency/filters/AbstractDependencyFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/AbstractDependencyFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/AbstractDependencyFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/ClassifierFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/FilterDependencies.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/FilterDependencies.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/plugins/dependency/filters/GroupIdFilter.java
Outdated
Show resolved
Hide resolved
68600d6
to
ab8d8d3
Compare
src/main/java/org/apache/maven/plugins/dependency/filters/ArtifactIdFilter.java
Outdated
Show resolved
Hide resolved
import java.util.Set; | ||
|
||
|
||
abstract class AbstractDependencyFilter implements DependencyFilter |
There was a problem hiding this comment.
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();
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@elharo can you please look over this PR again? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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. I still see them. Do you need to merge to master?
<version>2.0.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>non.existant.group</groupId> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterExcludeIds
There was a problem hiding this comment.
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 ) ) ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 );
}
expectedCondition
is 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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #258
…wnload artifacts, download the artifacts in the plugin code after filtering them with the provided parameters.
5c59113
to
8746246
Compare
Is this going to be merged anytime soon? It would be really helpful to install and cache dependencies prior to |
There was a problem hiding this 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 |
There was a problem hiding this 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. I still see them. Do you need to merge to master?
@@ -0,0 +1,59 @@ | |||
package org.apache.maven.plugins.dependency.filters; |
There was a problem hiding this comment.
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
This is old. If interested, please do a new PR. I'll leave the branch for a while. |
Following this checklist to help us incorporate your
contribution quickly and easily:
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.
[MDEP-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MDEP-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
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.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.