Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.felix.bundleplugin; |
| 20 | |
| 21 | |
| 22 | import java.util.Collection; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 23 | import java.util.Iterator; |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 24 | import java.util.LinkedHashSet; |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 25 | import java.util.List; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 26 | import java.util.Map; |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 27 | import java.util.Set; |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 28 | import java.util.regex.Pattern; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 29 | |
| 30 | import org.apache.maven.artifact.Artifact; |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 31 | import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; |
| 32 | import org.apache.maven.artifact.resolver.filter.ArtifactFilter; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 33 | import org.apache.maven.plugin.MojoExecutionException; |
| 34 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 35 | import aQute.bnd.header.Attrs; |
Stuart McCulloch | 42151ee | 2012-07-16 13:43:38 +0000 | [diff] [blame] | 36 | import aQute.bnd.header.OSGiHeader; |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 37 | import aQute.bnd.osgi.Instruction; |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 38 | import org.apache.maven.shared.dependency.graph.DependencyNode; |
| 39 | import org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter; |
| 40 | import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter; |
| 41 | import org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor; |
| 42 | import org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor; |
| 43 | import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; |
| 44 | import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | /** |
| 48 | * Apply clause-based filter over given dependencies |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 49 | * |
Richard S. Hall | 3bc8afd | 2009-08-12 19:03:19 +0000 | [diff] [blame] | 50 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 51 | */ |
| 52 | public abstract class AbstractDependencyFilter |
| 53 | { |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 54 | private static final Pattern MISSING_KEY_PATTERN = Pattern.compile( "(^|,)\\p{Blank}*(!)?\\p{Blank}*([a-zA-Z]+=)" ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 55 | |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 56 | /** |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 57 | * Dependency Graph. |
| 58 | */ |
| 59 | private final DependencyNode m_dependencyGraph; |
| 60 | /** |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 61 | * Dependency artifacts. |
| 62 | */ |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 63 | private final Collection<Artifact> m_dependencyArtifacts; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 64 | |
| 65 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 66 | public AbstractDependencyFilter( DependencyNode dependencyGraph, Collection<Artifact> dependencyArtifacts ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 67 | { |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 68 | m_dependencyGraph = dependencyGraph; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 69 | m_dependencyArtifacts = dependencyArtifacts; |
| 70 | } |
| 71 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 72 | private static abstract class DependencyFilter implements ArtifactFilter |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 73 | { |
| 74 | private final Instruction m_instruction; |
| 75 | private final String m_defaultValue; |
| 76 | |
| 77 | |
| 78 | public DependencyFilter( String expression ) |
| 79 | { |
| 80 | this( expression, "" ); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | public DependencyFilter( String expression, String defaultValue ) |
| 85 | { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 86 | m_instruction = new Instruction( expression ); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 87 | m_defaultValue = defaultValue; |
| 88 | } |
| 89 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 90 | public abstract boolean include( Artifact dependency ); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 91 | |
| 92 | boolean matches( String text ) |
| 93 | { |
| 94 | boolean result; |
| 95 | |
| 96 | if ( null == text ) |
| 97 | { |
| 98 | result = m_instruction.matches( m_defaultValue ); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | result = m_instruction.matches( text ); |
| 103 | } |
| 104 | |
| 105 | return m_instruction.isNegated() ? !result : result; |
| 106 | } |
| 107 | } |
| 108 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 109 | private static class TrimmingDependencyNodeFilter implements DependencyNodeFilter |
| 110 | { |
| 111 | private DependencyNodeFilter dependencyNodeFilter; |
| 112 | |
| 113 | public TrimmingDependencyNodeFilter( DependencyNodeFilter dependencyNodeFilter ) |
| 114 | { |
| 115 | this.dependencyNodeFilter = dependencyNodeFilter; |
| 116 | } |
| 117 | |
| 118 | public boolean accept( DependencyNode node ) |
| 119 | { |
| 120 | boolean accepted = dependencyNodeFilter.accept( node ); |
| 121 | if( !accepted ) |
| 122 | { |
| 123 | List<DependencyNode> children = node.getChildren(); |
| 124 | children.clear(); |
| 125 | } |
| 126 | return accepted; |
| 127 | } |
| 128 | } |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 129 | |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 130 | protected final void processInstructions( String header ) throws MojoExecutionException |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 131 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 132 | Map<String,Attrs> instructions = OSGiHeader.parseHeader( MISSING_KEY_PATTERN.matcher( header ).replaceAll( "$1$2*;$3" ) ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 133 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 134 | Collection<Artifact> availableDependencies = new LinkedHashSet<Artifact>( m_dependencyArtifacts ); |
Stuart McCulloch | e78eff9 | 2011-10-26 21:54:03 +0000 | [diff] [blame] | 135 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 136 | for ( Iterator<Map.Entry<String,Attrs>> clauseIterator = instructions.entrySet().iterator(); clauseIterator.hasNext(); ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 137 | { |
| 138 | String inline = "false"; |
| 139 | |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 140 | // always start with a fresh *modifiable* collection for each unique clause |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 141 | Collection<Artifact> filteredDependencies = new LinkedHashSet<Artifact>( availableDependencies ); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 142 | |
| 143 | // CLAUSE: REGEXP --> { ATTRIBUTE MAP } |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 144 | Map.Entry<String,Attrs> clause = clauseIterator.next(); |
| 145 | String primaryKey = clause.getKey().replaceFirst( "~+$", "" ); |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 146 | boolean isNegative = primaryKey.startsWith( "!" ); |
| 147 | if ( isNegative ) |
| 148 | { |
| 149 | primaryKey = primaryKey.substring( 1 ); |
| 150 | } |
| 151 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 152 | final AndArtifactFilter andArtifactFilter = new AndArtifactFilter(); |
Stuart McCulloch | e8851a5 | 2011-10-26 21:14:28 +0000 | [diff] [blame] | 153 | if ( !"*".equals( primaryKey ) ) |
Stuart McCulloch | d98b02e | 2011-06-28 23:20:37 +0000 | [diff] [blame] | 154 | { |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 155 | ArtifactFilter filter = new DependencyFilter( primaryKey ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 156 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 157 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 158 | public boolean include( Artifact dependency ) |
Hiram R. Chirino | 20a916a | 2011-01-29 01:39:54 +0000 | [diff] [blame] | 159 | { |
| 160 | return super.matches( dependency.getArtifactId() ); |
| 161 | } |
| 162 | }; |
| 163 | // FILTER ON MAIN CLAUSE |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 164 | andArtifactFilter.add(filter); |
Hiram R. Chirino | 20a916a | 2011-01-29 01:39:54 +0000 | [diff] [blame] | 165 | } |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 166 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 167 | for ( Iterator<Map.Entry<String,String>> attrIterator = clause.getValue().entrySet().iterator(); attrIterator.hasNext(); ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 168 | { |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 169 | final ArtifactFilter filter; |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 170 | // ATTRIBUTE: KEY --> REGEXP |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 171 | Map.Entry<String,String> attr = attrIterator.next(); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 172 | if ( "groupId".equals( attr.getKey() ) ) |
| 173 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 174 | filter = new DependencyFilter( attr.getValue() ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 175 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 176 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 177 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 178 | { |
| 179 | return super.matches( dependency.getGroupId() ); |
| 180 | } |
| 181 | }; |
| 182 | } |
| 183 | else if ( "artifactId".equals( attr.getKey() ) ) |
| 184 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 185 | filter = new DependencyFilter( attr.getValue() ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 186 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 187 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 188 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 189 | { |
| 190 | return super.matches( dependency.getArtifactId() ); |
| 191 | } |
| 192 | }; |
| 193 | } |
| 194 | else if ( "version".equals( attr.getKey() ) ) |
| 195 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 196 | filter = new DependencyFilter( attr.getValue() ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 197 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 198 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 199 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 200 | { |
| 201 | try |
| 202 | { |
| 203 | // use the symbolic version if available (ie. 1.0.0-SNAPSHOT) |
| 204 | return super.matches( dependency.getSelectedVersion().toString() ); |
| 205 | } |
| 206 | catch ( Exception e ) |
| 207 | { |
| 208 | return super.matches( dependency.getVersion() ); |
| 209 | } |
| 210 | } |
| 211 | }; |
| 212 | } |
| 213 | else if ( "scope".equals( attr.getKey() ) ) |
| 214 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 215 | filter = new DependencyFilter( attr.getValue(), "compile" ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 216 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 217 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 218 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 219 | { |
| 220 | return super.matches( dependency.getScope() ); |
| 221 | } |
| 222 | }; |
| 223 | } |
| 224 | else if ( "type".equals( attr.getKey() ) ) |
| 225 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 226 | filter = new DependencyFilter( attr.getValue(), "jar" ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 227 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 228 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 229 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 230 | { |
| 231 | return super.matches( dependency.getType() ); |
| 232 | } |
| 233 | }; |
| 234 | } |
| 235 | else if ( "classifier".equals( attr.getKey() ) ) |
| 236 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 237 | filter = new DependencyFilter( attr.getValue() ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 238 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 239 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 240 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 241 | { |
| 242 | return super.matches( dependency.getClassifier() ); |
| 243 | } |
| 244 | }; |
| 245 | } |
| 246 | else if ( "optional".equals( attr.getKey() ) ) |
| 247 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 248 | filter = new DependencyFilter( attr.getValue(), "false" ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 249 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 250 | @Override |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 251 | public boolean include( Artifact dependency ) |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 252 | { |
| 253 | return super.matches( "" + dependency.isOptional() ); |
| 254 | } |
| 255 | }; |
| 256 | } |
| 257 | else if ( "inline".equals( attr.getKey() ) ) |
| 258 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 259 | inline = attr.getValue(); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 260 | continue; |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | throw new MojoExecutionException( "Unexpected attribute " + attr.getKey() ); |
| 265 | } |
| 266 | |
| 267 | // FILTER ON EACH ATTRIBUTE |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 268 | andArtifactFilter.add( filter ); |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 271 | filteredDependencies( andArtifactFilter, filteredDependencies ); |
| 272 | |
Stuart McCulloch | 271f173 | 2011-10-26 23:12:36 +0000 | [diff] [blame] | 273 | if ( isNegative ) |
| 274 | { |
| 275 | // negative clauses reduce the set of available artifacts |
| 276 | availableDependencies.removeAll( filteredDependencies ); |
| 277 | if ( !clauseIterator.hasNext() ) |
| 278 | { |
| 279 | // assume there's an implicit * missing at the end |
| 280 | processDependencies( availableDependencies, inline ); |
| 281 | } |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | // positive clause; doesn't alter the available artifacts |
| 286 | processDependencies( filteredDependencies, inline ); |
| 287 | } |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 292 | protected abstract void processDependencies( Collection<Artifact> dependencies, String inline ); |
Guillaume Nodet | ed7b110 | 2015-07-09 19:45:09 +0000 | [diff] [blame] | 293 | |
| 294 | private void filteredDependencies( final ArtifactFilter artifactFilter, Collection<Artifact> filteredDependencies ) |
| 295 | { |
| 296 | CollectingDependencyNodeVisitor collectingDependencyNodeVisitor = new CollectingDependencyNodeVisitor(); |
| 297 | final Artifact rootArtifact = m_dependencyGraph.getArtifact(); |
| 298 | ArtifactFilter filter = new ArtifactFilter() |
| 299 | { |
| 300 | |
| 301 | |
| 302 | public boolean include( Artifact artifact ) |
| 303 | { |
| 304 | return artifact.equals( rootArtifact ) || artifactFilter.include( artifact ); |
| 305 | } |
| 306 | |
| 307 | |
| 308 | }; |
| 309 | DependencyNodeFilter dependencyNodeFilter = new ArtifactDependencyNodeFilter( filter ); |
| 310 | dependencyNodeFilter = new TrimmingDependencyNodeFilter( dependencyNodeFilter ); |
| 311 | DependencyNodeVisitor dependencyNodeVisitor = |
| 312 | new FilteringDependencyNodeVisitor( collectingDependencyNodeVisitor, dependencyNodeFilter ); |
| 313 | dependencyNodeVisitor = new BuildingDependencyNodeVisitor( dependencyNodeVisitor ); |
| 314 | m_dependencyGraph.accept( dependencyNodeVisitor ); |
| 315 | List<DependencyNode> dependencyNodes = collectingDependencyNodeVisitor.getNodes(); |
| 316 | Set<String> ids = new LinkedHashSet<String>( dependencyNodes.size() ); |
| 317 | for( DependencyNode dependencyNode : dependencyNodes ) { |
| 318 | Artifact artifact = dependencyNode.getArtifact(); |
| 319 | String id = artifact.getId(); |
| 320 | ids.add(id); |
| 321 | } |
| 322 | for (Iterator<Artifact> iterator = filteredDependencies.iterator(); iterator.hasNext();) |
| 323 | { |
| 324 | Artifact artifact = iterator.next(); |
| 325 | String id = artifact.getId(); |
| 326 | if (!ids.contains(id)) |
| 327 | { |
| 328 | iterator.remove(); |
| 329 | } |
| 330 | } |
| 331 | } |
Stuart McCulloch | 233a574 | 2009-02-16 07:36:22 +0000 | [diff] [blame] | 332 | } |