001 package org.apache.maven.artifact.resolver.filter; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.util.Arrays; 023 import java.util.LinkedHashSet; 024 import java.util.Set; 025 026 import org.apache.maven.artifact.Artifact; 027 028 /** 029 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 030 */ 031 public class ExclusionSetFilter 032 implements ArtifactFilter 033 { 034 private Set<String> excludes; 035 036 public ExclusionSetFilter( String[] excludes ) 037 { 038 this.excludes = new LinkedHashSet<String>( Arrays.asList( excludes ) ); 039 } 040 041 public ExclusionSetFilter( Set<String> excludes ) 042 { 043 this.excludes = excludes; 044 } 045 046 public boolean include( Artifact artifact ) 047 { 048 String id = artifact.getArtifactId(); 049 050 if ( excludes.contains( id ) ) 051 { 052 return false; 053 } 054 055 id = artifact.getGroupId() + ':' + id; 056 057 if ( excludes.contains( id ) ) 058 { 059 return false; 060 } 061 062 return true; 063 } 064 065 @Override 066 public int hashCode() 067 { 068 int hash = 17; 069 hash = hash * 31 + excludes.hashCode(); 070 return hash; 071 } 072 073 @Override 074 public boolean equals( Object obj ) 075 { 076 if ( this == obj ) 077 { 078 return true; 079 } 080 081 if ( !( obj instanceof ExclusionSetFilter ) ) 082 { 083 return false; 084 } 085 086 ExclusionSetFilter other = (ExclusionSetFilter) obj; 087 088 return excludes.equals( other.excludes ); 089 } 090 }