You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/07/09 14:01:33 UTC

[GitHub] [maven-dependency-plugin] antoniolucasnobar commented on a change in pull request #135: [MDEP-568] go offline filter

antoniolucasnobar commented on a change in pull request #135:
URL: https://github.com/apache/maven-dependency-plugin/pull/135#discussion_r666972669



##########
File path: src/main/java/org/apache/maven/plugins/dependency/filters/AbstractDependencyFilter.java
##########
@@ -0,0 +1,50 @@
+package org.apache.maven.plugins.dependency.filters;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
+
+
+abstract class AbstractDependencyFilter implements DependencyFilter

Review comment:
       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`
   
   ```java
   	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 includeIds) {
   		return splitValues(includeIds);
   	}
   
   	protected Set<String> splitIncludeIds(String includeIds) {
   		return splitValues(includeIds);
   	}
   
   	protected Set<String> splitValues(String excludeIds) {
   		// ommited here
   	}
   
   	abstract protected String getContainsProperty(Dependency dependency);
   
   }
   ```
   
   ```java
   	public class GroupIdFilter extends AbstractDependencyFilter
   	{
   
   		public GroupIdFilter(String includeGroupIds, String excludeGroupIds)
   		{
   			super(includeGroupIds, excludeGroupIds);
   		}
   
   	    protected String getContainsProperty(Dependency dependency) {
   			return dependency.getGroupId();
   		}
   
   	}
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org