/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012, Red Hat Middleware LLC, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed 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.
 */
package org.jboss.shrinkwrap.resolver.impl.maven.filter;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.jboss.shrinkwrap.resolver.api.CoordinateParseException;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolutionFilter;
import org.jboss.shrinkwrap.resolver.api.maven.ScopeType;
import org.jboss.shrinkwrap.resolver.api.maven.dependency.DependencyDeclaration;
import org.jboss.shrinkwrap.resolver.api.maven.dependency.exclusion.DependencyExclusion;
import org.jboss.shrinkwrap.resolver.impl.maven.coordinate.MavenCoordinateParser;
import org.jboss.shrinkwrap.resolver.impl.maven.dependency.DependencyDeclarationImpl;

/**
 * A {@link MavenResolutionFilter} which will selectively ban specified dependencies
 *
 * @author <a href="mailto:kpiwko@redhat.com">Karel Piwko</a>
 *
 */
public class RejectDependenciesFilter implements MavenResolutionFilterInternalView {

    private Set<DependencyDeclaration> bannedDependencies;

    public RejectDependenciesFilter(final String... coordinates) throws IllegalArgumentException,
        CoordinateParseException {
        if (coordinates.length == 0) {
            throw new IllegalArgumentException("There must be at least one coordinate specified to be rejected.");
        }

        for (final String coords : coordinates) {
            bannedDependencies.add(build(coords));
        }

    }

    @Override
    public MavenResolutionFilterInternalView setDefinedDependencies(final List<DependencyDeclaration> dependencies) {
        return this;
    }

    @Override
    public MavenResolutionFilterInternalView setDefinedDependencyManagement(
        final List<DependencyDeclaration> dependencyManagement) {
        return this;
    }

    @Override
    public boolean accepts(DependencyDeclaration coordinate) throws IllegalArgumentException {

        if (bannedDependencies.contains(coordinate)) {
            return false;
        }

        return true;
    }

    private DependencyDeclaration build(final String coordinates) throws CoordinateParseException {
        final MavenCoordinateParser parser = MavenCoordinateParser.parse(coordinates);

        return new DependencyDeclarationImpl(parser.getGroupId(), parser.getArtifactId(), parser.getPackaging(),
            parser.getClassifier(), parser.getVersion(), ScopeType.COMPILE, false,
            Collections.<DependencyExclusion> emptySet());

    }

}

@@ -866,16 +866,42 @@
 ctions;%0A
+import java.util.HashSet;%0A
 import j
@@ -1731,16 +1731,22 @@
 private 
+final 
 Set%3CDepe
@@ -1784,16 +1784,16 @@
 encies;%0A
-
 %0A    pub
@@ -1941,16 +1941,39 @@
 rdinates
+ == null %7C%7C coordinates
 .length 
@@ -2098,32 +2098,117 @@
 .%22);%0A        %7D%0A%0A
+        bannedDependencies = new HashSet%3CDependencyDeclaration%3E(coordinates.length);%0A
         for (fin

Fix NPE in RejectDependenciesFilter