001package org.apache.maven; 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 022import java.util.LinkedHashSet; 023import java.util.List; 024import java.util.Set; 025 026import javax.inject.Inject; 027import javax.inject.Named; 028import javax.inject.Singleton; 029 030import org.apache.maven.artifact.resolver.filter.ArtifactFilter; 031import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; 032import org.apache.maven.extension.internal.CoreExportsProvider; 033 034/** 035 * @author Jason van Zyl 036 */ 037@Named 038@Singleton 039@SuppressWarnings( "deprecation" ) 040public class DefaultArtifactFilterManager 041 implements ArtifactFilterManager 042{ 043 044 // this is a live injected collection 045 protected final List<ArtifactFilterManagerDelegate> delegates; 046 047 protected Set<String> excludedArtifacts; 048 049 private final Set<String> coreArtifacts; 050 051 @Inject 052 public DefaultArtifactFilterManager( List<ArtifactFilterManagerDelegate> delegates, 053 CoreExportsProvider coreExports ) 054 { 055 this.delegates = delegates; 056 this.coreArtifacts = coreExports.get().getExportedArtifacts(); 057 } 058 059 private synchronized Set<String> getExcludedArtifacts() 060 { 061 if ( excludedArtifacts == null ) 062 { 063 excludedArtifacts = new LinkedHashSet<String>( coreArtifacts ); 064 } 065 return excludedArtifacts; 066 } 067 068 /** 069 * Returns the artifact filter for the core + extension artifacts. 070 * 071 * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter() 072 */ 073 public ArtifactFilter getArtifactFilter() 074 { 075 Set<String> excludes = new LinkedHashSet<String>( getExcludedArtifacts() ); 076 077 for ( ArtifactFilterManagerDelegate delegate : delegates ) 078 { 079 delegate.addExcludes( excludes ); 080 } 081 082 return new ExclusionSetFilter( excludes ); 083 } 084 085 /** 086 * Returns the artifact filter for the standard core artifacts. 087 * 088 * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter() 089 */ 090 public ArtifactFilter getCoreArtifactFilter() 091 { 092 return new ExclusionSetFilter( getCoreArtifactExcludes() ); 093 } 094 095 public void excludeArtifact( String artifactId ) 096 { 097 getExcludedArtifacts().add( artifactId ); 098 } 099 100 public Set<String> getCoreArtifactExcludes() 101 { 102 Set<String> excludes = new LinkedHashSet<String>( coreArtifacts ); 103 104 for ( ArtifactFilterManagerDelegate delegate : delegates ) 105 { 106 delegate.addCoreExcludes( excludes ); 107 } 108 109 return excludes; 110 } 111 112}