001 package 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 022 import java.util.ArrayList; 023 import java.util.Collections; 024 import java.util.HashSet; 025 import java.util.LinkedHashSet; 026 import java.util.List; 027 import java.util.Set; 028 029 import org.apache.maven.artifact.resolver.filter.ArtifactFilter; 030 import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; 031 import org.codehaus.plexus.PlexusContainer; 032 import org.codehaus.plexus.component.annotations.Component; 033 import org.codehaus.plexus.component.annotations.Requirement; 034 import org.codehaus.plexus.component.repository.exception.ComponentLookupException; 035 036 /** 037 * @author Jason van Zyl 038 * @todo this should probably be a component with some dynamic control of filtering 039 */ 040 @Component( role = ArtifactFilterManager.class ) 041 public class DefaultArtifactFilterManager 042 implements ArtifactFilterManager 043 { 044 045 private static final Set<String> DEFAULT_EXCLUSIONS; 046 047 @Requirement 048 private PlexusContainer plexus; 049 050 static 051 { 052 Set<String> artifacts = new HashSet<String>(); 053 054 artifacts.add( "classworlds:classworlds" ); 055 artifacts.add( "org.codehaus.plexus:plexus-classworlds" ); 056 artifacts.add( "org.codehaus.plexus:plexus-component-api" ); 057 artifacts.add( "org.codehaus.plexus:plexus-container-default" ); 058 artifacts.add( "plexus:plexus-container-default" ); 059 artifacts.add( "org.sonatype.spice:spice-inject-plexus" ); 060 artifacts.add( "org.sonatype.sisu:sisu-inject-plexus" ); 061 artifacts.add( "org.eclipse.sisu:org.eclipse.sisu.plexus" ); 062 artifacts.add( "org.apache.maven:maven-artifact" ); 063 artifacts.add( "org.apache.maven:maven-aether-provider" ); 064 artifacts.add( "org.apache.maven:maven-artifact-manager" ); 065 artifacts.add( "org.apache.maven:maven-compat" ); 066 artifacts.add( "org.apache.maven:maven-core" ); 067 artifacts.add( "org.apache.maven:maven-error-diagnostics" ); 068 artifacts.add( "org.apache.maven:maven-lifecycle" ); 069 artifacts.add( "org.apache.maven:maven-model" ); 070 artifacts.add( "org.apache.maven:maven-model-builder" ); 071 artifacts.add( "org.apache.maven:maven-monitor" ); 072 artifacts.add( "org.apache.maven:maven-plugin-api" ); 073 artifacts.add( "org.apache.maven:maven-plugin-descriptor" ); 074 artifacts.add( "org.apache.maven:maven-plugin-parameter-documenter" ); 075 artifacts.add( "org.apache.maven:maven-plugin-registry" ); 076 artifacts.add( "org.apache.maven:maven-profile" ); 077 artifacts.add( "org.apache.maven:maven-project" ); 078 artifacts.add( "org.apache.maven:maven-repository-metadata" ); 079 artifacts.add( "org.apache.maven:maven-settings" ); 080 artifacts.add( "org.apache.maven:maven-settings-builder" ); 081 artifacts.add( "org.apache.maven:maven-toolchain" ); 082 artifacts.add( "org.apache.maven.wagon:wagon-provider-api" ); 083 artifacts.add( "org.sonatype.aether:aether-api" ); 084 artifacts.add( "org.sonatype.aether:aether-spi" ); 085 artifacts.add( "org.sonatype.aether:aether-impl" ); 086 087 /* 088 * NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise 089 * provoke linkage errors for wagons contributed by build extensions. We also don't need to exclude the wagons 090 * from plugins. Plugins that use wagons directly and declare the corresponding dependency will simply use a 091 * wagon from their plugin realm. 092 */ 093 094 DEFAULT_EXCLUSIONS = Collections.unmodifiableSet( artifacts ); 095 } 096 097 protected Set<String> excludedArtifacts = new HashSet<String>( DEFAULT_EXCLUSIONS ); 098 099 /** 100 * @deprecated Use this class as a component instead, and then use getArtifactFilter(). 101 */ 102 public static ArtifactFilter createStandardFilter() 103 { 104 // TODO: configure this from bootstrap or scan lib 105 return new ExclusionSetFilter( DEFAULT_EXCLUSIONS ); 106 } 107 108 /** 109 * Returns the artifact filter for the core + extension artifacts. 110 * 111 * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter() 112 */ 113 public ArtifactFilter getArtifactFilter() 114 { 115 Set<String> excludes = new LinkedHashSet<String>( excludedArtifacts ); 116 117 for ( ArtifactFilterManagerDelegate delegate : getDelegates() ) 118 { 119 delegate.addExcludes( excludes ); 120 } 121 122 return new ExclusionSetFilter( excludes ); 123 } 124 125 /** 126 * Returns the artifact filter for the standard core artifacts. 127 * 128 * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter() 129 */ 130 public ArtifactFilter getCoreArtifactFilter() 131 { 132 return new ExclusionSetFilter( getCoreArtifactExcludes() ); 133 } 134 135 private List<ArtifactFilterManagerDelegate> getDelegates() 136 { 137 try 138 { 139 return plexus.lookupList( ArtifactFilterManagerDelegate.class ); 140 } 141 catch ( ComponentLookupException e ) 142 { 143 return new ArrayList<ArtifactFilterManagerDelegate>(); 144 } 145 } 146 147 /* (non-Javadoc) 148 * @see org.apache.maven.ArtifactFilterManager#excludeArtifact(java.lang.String) 149 */ 150 public void excludeArtifact( String artifactId ) 151 { 152 excludedArtifacts.add( artifactId ); 153 } 154 155 public Set<String> getCoreArtifactExcludes() 156 { 157 Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS ); 158 159 for ( ArtifactFilterManagerDelegate delegate : getDelegates() ) 160 { 161 delegate.addCoreExcludes( excludes ); 162 } 163 164 return excludes; 165 } 166 167 }