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.apache.maven:maven-artifact" );
062 artifacts.add( "org.apache.maven:maven-aether-provider" );
063 artifacts.add( "org.apache.maven:maven-artifact-manager" );
064 artifacts.add( "org.apache.maven:maven-compat" );
065 artifacts.add( "org.apache.maven:maven-core" );
066 artifacts.add( "org.apache.maven:maven-error-diagnostics" );
067 artifacts.add( "org.apache.maven:maven-lifecycle" );
068 artifacts.add( "org.apache.maven:maven-model" );
069 artifacts.add( "org.apache.maven:maven-model-builder" );
070 artifacts.add( "org.apache.maven:maven-monitor" );
071 artifacts.add( "org.apache.maven:maven-plugin-api" );
072 artifacts.add( "org.apache.maven:maven-plugin-descriptor" );
073 artifacts.add( "org.apache.maven:maven-plugin-parameter-documenter" );
074 artifacts.add( "org.apache.maven:maven-plugin-registry" );
075 artifacts.add( "org.apache.maven:maven-profile" );
076 artifacts.add( "org.apache.maven:maven-project" );
077 artifacts.add( "org.apache.maven:maven-repository-metadata" );
078 artifacts.add( "org.apache.maven:maven-settings" );
079 artifacts.add( "org.apache.maven:maven-settings-builder" );
080 artifacts.add( "org.apache.maven:maven-toolchain" );
081 artifacts.add( "org.apache.maven.wagon:wagon-provider-api" );
082 artifacts.add( "org.sonatype.aether:aether-api" );
083 artifacts.add( "org.sonatype.aether:aether-spi" );
084 artifacts.add( "org.sonatype.aether:aether-impl" );
085
086 /*
087 * NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise
088 * provoke linkage errors for wagons contributed by build extensions. We also don't need to exclude the wagons
089 * from plugins. Plugins that use wagons directly and declare the corresponding dependency will simply use a
090 * wagon from their plugin realm.
091 */
092
093 DEFAULT_EXCLUSIONS = Collections.unmodifiableSet( artifacts);
094 }
095
096 protected Set<String> excludedArtifacts = new HashSet<String>( DEFAULT_EXCLUSIONS );
097
098 /**
099 * @deprecated Use this class as a component instead, and then use getArtifactFilter().
100 */
101 public static ArtifactFilter createStandardFilter()
102 {
103 // TODO: configure this from bootstrap or scan lib
104 return new ExclusionSetFilter( DEFAULT_EXCLUSIONS );
105 }
106
107 /**
108 * Returns the artifact filter for the core + extension artifacts.
109 *
110 * @see org.apache.maven.ArtifactFilterManager#getArtifactFilter()
111 */
112 public ArtifactFilter getArtifactFilter()
113 {
114 Set<String> excludes = new LinkedHashSet<String>( excludedArtifacts );
115
116 for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
117 {
118 delegate.addExcludes( excludes );
119 }
120
121 return new ExclusionSetFilter( excludes );
122 }
123
124 /**
125 * Returns the artifact filter for the standard core artifacts.
126 *
127 * @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
128 */
129 public ArtifactFilter getCoreArtifactFilter()
130 {
131 return new ExclusionSetFilter( getCoreArtifactExcludes() );
132 }
133
134 private List<ArtifactFilterManagerDelegate> getDelegates()
135 {
136 try
137 {
138 return plexus.lookupList( ArtifactFilterManagerDelegate.class );
139 }
140 catch ( ComponentLookupException e )
141 {
142 return new ArrayList<ArtifactFilterManagerDelegate>();
143 }
144 }
145
146 /* (non-Javadoc)
147 * @see org.apache.maven.ArtifactFilterManager#excludeArtifact(java.lang.String)
148 */
149 public void excludeArtifact( String artifactId )
150 {
151 excludedArtifacts.add( artifactId );
152 }
153
154 public Set<String> getCoreArtifactExcludes()
155 {
156 Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
157
158 for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
159 {
160 delegate.addCoreExcludes( excludes );
161 }
162
163 return excludes;
164 }
165
166 }