| 1 | |
package org.apache.maven.artifact.resolver; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.artifact.Artifact; |
| 23 | |
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; |
| 24 | |
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; |
| 25 | |
import org.apache.maven.artifact.metadata.ResolutionGroup; |
| 26 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
| 27 | |
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; |
| 28 | |
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; |
| 29 | |
import org.apache.maven.artifact.versioning.ArtifactVersion; |
| 30 | |
import org.apache.maven.artifact.versioning.OverConstrainedVersionException; |
| 31 | |
import org.apache.maven.artifact.versioning.VersionRange; |
| 32 | |
import org.apache.maven.artifact.versioning.ManagedVersionMap; |
| 33 | |
|
| 34 | |
import java.util.ArrayList; |
| 35 | |
import java.util.Collections; |
| 36 | |
import java.util.Iterator; |
| 37 | |
import java.util.LinkedHashMap; |
| 38 | |
import java.util.LinkedHashSet; |
| 39 | |
import java.util.List; |
| 40 | |
import java.util.Map; |
| 41 | |
import java.util.Set; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public class DefaultArtifactCollector |
| 50 | |
implements ArtifactCollector |
| 51 | |
{ |
| 52 | |
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, |
| 53 | |
ArtifactRepository localRepository, List remoteRepositories, |
| 54 | |
ArtifactMetadataSource source, ArtifactFilter filter, List listeners ) |
| 55 | |
throws ArtifactResolutionException |
| 56 | |
{ |
| 57 | 0 | return collect( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, |
| 58 | |
source, filter, listeners ); |
| 59 | |
} |
| 60 | |
|
| 61 | |
public ArtifactResolutionResult collect( Set artifacts, Artifact originatingArtifact, Map managedVersions, |
| 62 | |
ArtifactRepository localRepository, List remoteRepositories, |
| 63 | |
ArtifactMetadataSource source, ArtifactFilter filter, List listeners ) |
| 64 | |
throws ArtifactResolutionException |
| 65 | |
{ |
| 66 | 0 | Map resolvedArtifacts = new LinkedHashMap(); |
| 67 | |
|
| 68 | 0 | ResolutionNode root = new ResolutionNode( originatingArtifact, remoteRepositories ); |
| 69 | |
|
| 70 | 0 | root.addDependencies( artifacts, remoteRepositories, filter ); |
| 71 | |
|
| 72 | 0 | ManagedVersionMap versionMap = getManagedVersionsMap( originatingArtifact, managedVersions ); |
| 73 | |
|
| 74 | 0 | recurse( originatingArtifact, root, resolvedArtifacts, versionMap, localRepository, remoteRepositories, source, filter, |
| 75 | |
listeners ); |
| 76 | |
|
| 77 | 0 | Set set = new LinkedHashSet(); |
| 78 | |
|
| 79 | 0 | for ( Iterator i = resolvedArtifacts.values().iterator(); i.hasNext(); ) |
| 80 | |
{ |
| 81 | 0 | List nodes = (List) i.next(); |
| 82 | 0 | for ( Iterator j = nodes.iterator(); j.hasNext(); ) |
| 83 | |
{ |
| 84 | 0 | ResolutionNode node = (ResolutionNode) j.next(); |
| 85 | 0 | if ( !node.equals( root ) && node.isActive() ) |
| 86 | |
{ |
| 87 | 0 | Artifact artifact = node.getArtifact(); |
| 88 | |
|
| 89 | 0 | if ( node.filterTrail( filter ) ) |
| 90 | |
{ |
| 91 | |
|
| 92 | |
|
| 93 | 0 | if ( node.isChildOfRootNode() || !artifact.isOptional() ) |
| 94 | |
{ |
| 95 | 0 | artifact.setDependencyTrail( node.getDependencyTrail() ); |
| 96 | |
|
| 97 | 0 | set.add( node ); |
| 98 | |
} |
| 99 | |
} |
| 100 | |
} |
| 101 | 0 | } |
| 102 | 0 | } |
| 103 | |
|
| 104 | 0 | ArtifactResolutionResult result = new ArtifactResolutionResult(); |
| 105 | 0 | result.setArtifactResolutionNodes( set ); |
| 106 | 0 | return result; |
| 107 | |
} |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
private ManagedVersionMap getManagedVersionsMap( Artifact originatingArtifact, Map managedVersions ) |
| 115 | |
{ |
| 116 | |
ManagedVersionMap versionMap; |
| 117 | 0 | if ( managedVersions != null && managedVersions instanceof ManagedVersionMap ) |
| 118 | |
{ |
| 119 | 0 | versionMap = (ManagedVersionMap) managedVersions; |
| 120 | |
} |
| 121 | |
else |
| 122 | |
{ |
| 123 | 0 | versionMap = new ManagedVersionMap( managedVersions ); |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | 0 | Artifact managedOriginatingArtifact = (Artifact) versionMap.get( originatingArtifact.getDependencyConflictId() ); |
| 128 | 0 | if ( managedOriginatingArtifact != null ) |
| 129 | |
{ |
| 130 | |
|
| 131 | |
|
| 132 | 0 | if ( managedVersions instanceof ManagedVersionMap ) |
| 133 | |
{ |
| 134 | |
|
| 135 | 0 | versionMap = new ManagedVersionMap( managedVersions ); |
| 136 | |
} |
| 137 | 0 | versionMap.remove( originatingArtifact.getDependencyConflictId() ); |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | return versionMap; |
| 141 | |
} |
| 142 | |
|
| 143 | |
private void recurse( Artifact originatingArtifact, ResolutionNode node, Map resolvedArtifacts, ManagedVersionMap managedVersions, |
| 144 | |
ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source, |
| 145 | |
ArtifactFilter filter, List listeners ) |
| 146 | |
throws CyclicDependencyException, ArtifactResolutionException, OverConstrainedVersionException |
| 147 | |
{ |
| 148 | 0 | fireEvent( ResolutionListener.TEST_ARTIFACT, listeners, node ); |
| 149 | |
|
| 150 | 0 | Object key = node.getKey(); |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | 0 | if ( managedVersions.containsKey( key )) |
| 155 | |
{ |
| 156 | 0 | manageArtifact( node, managedVersions, listeners ); |
| 157 | |
} |
| 158 | |
|
| 159 | 0 | List previousNodes = (List) resolvedArtifacts.get( key ); |
| 160 | 0 | if ( previousNodes != null ) |
| 161 | |
{ |
| 162 | 0 | for ( Iterator i = previousNodes.iterator(); i.hasNext(); ) |
| 163 | |
{ |
| 164 | 0 | ResolutionNode previous = (ResolutionNode) i.next(); |
| 165 | |
|
| 166 | 0 | if ( previous.isActive() ) |
| 167 | |
{ |
| 168 | |
|
| 169 | 0 | VersionRange previousRange = previous.getArtifact().getVersionRange(); |
| 170 | 0 | VersionRange currentRange = node.getArtifact().getVersionRange(); |
| 171 | |
|
| 172 | 0 | if ( previousRange != null && currentRange != null ) |
| 173 | |
{ |
| 174 | |
|
| 175 | |
|
| 176 | 0 | VersionRange newRange = previousRange.restrict( currentRange ); |
| 177 | |
|
| 178 | 0 | if ( newRange.isSelectedVersionKnown( previous.getArtifact() ) ) |
| 179 | |
{ |
| 180 | 0 | fireEvent( ResolutionListener.RESTRICT_RANGE, listeners, node, previous.getArtifact(), |
| 181 | |
newRange ); |
| 182 | |
} |
| 183 | 0 | previous.getArtifact().setVersionRange( newRange ); |
| 184 | 0 | node.getArtifact().setVersionRange( currentRange.restrict( previousRange ) ); |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | 0 | ResolutionNode[] resetNodes = {previous, node}; |
| 190 | 0 | for ( int j = 0; j < 2; j++ ) |
| 191 | |
{ |
| 192 | 0 | Artifact resetArtifact = resetNodes[j].getArtifact(); |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | 0 | if ( resetArtifact.getVersion() == null && resetArtifact.getVersionRange() != null ) |
| 198 | |
{ |
| 199 | |
|
| 200 | |
|
| 201 | 0 | List versions = resetArtifact.getAvailableVersions(); |
| 202 | 0 | if ( versions == null ) |
| 203 | |
{ |
| 204 | |
try |
| 205 | |
{ |
| 206 | 0 | versions = |
| 207 | |
source.retrieveAvailableVersions( resetArtifact, localRepository, |
| 208 | |
remoteRepositories ); |
| 209 | 0 | resetArtifact.setAvailableVersions( versions ); |
| 210 | |
} |
| 211 | 0 | catch ( ArtifactMetadataRetrievalException e ) |
| 212 | |
{ |
| 213 | 0 | resetArtifact.setDependencyTrail( node.getDependencyTrail() ); |
| 214 | 0 | throw new ArtifactResolutionException( |
| 215 | |
"Unable to get dependency information: " + |
| 216 | |
e.getMessage(), resetArtifact, |
| 217 | |
remoteRepositories, e ); |
| 218 | 0 | } |
| 219 | |
} |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | 0 | ArtifactVersion selectedVersion = resetArtifact.getVersionRange().matchVersion( resetArtifact.getAvailableVersions() ); |
| 224 | 0 | if (selectedVersion != null) |
| 225 | |
{ |
| 226 | 0 | resetArtifact.selectVersion( selectedVersion.toString() ); |
| 227 | |
} |
| 228 | |
else |
| 229 | |
{ |
| 230 | 0 | throw new OverConstrainedVersionException(" Unable to find a version in "+ resetArtifact.getAvailableVersions()+" to match the range "+ resetArtifact.getVersionRange(), resetArtifact); |
| 231 | |
} |
| 232 | |
|
| 233 | 0 | fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, resetNodes[j] ); |
| 234 | |
} |
| 235 | |
} |
| 236 | |
} |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
ResolutionNode nearest; |
| 244 | |
ResolutionNode farthest; |
| 245 | 0 | if ( previous.getDepth() <= node.getDepth() ) |
| 246 | |
{ |
| 247 | 0 | nearest = previous; |
| 248 | 0 | farthest = node; |
| 249 | |
} |
| 250 | |
else |
| 251 | |
{ |
| 252 | 0 | nearest = node; |
| 253 | 0 | farthest = previous; |
| 254 | |
} |
| 255 | |
|
| 256 | 0 | if ( checkScopeUpdate( farthest, nearest, listeners ) ) |
| 257 | |
{ |
| 258 | |
|
| 259 | 0 | nearest.disable(); |
| 260 | 0 | farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() ); |
| 261 | 0 | fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, nearest, farthest.getArtifact() ); |
| 262 | |
} |
| 263 | |
else |
| 264 | |
{ |
| 265 | 0 | farthest.disable(); |
| 266 | 0 | fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, farthest, nearest.getArtifact() ); |
| 267 | |
} |
| 268 | |
} |
| 269 | 0 | } |
| 270 | |
} |
| 271 | |
else |
| 272 | |
{ |
| 273 | 0 | previousNodes = new ArrayList(); |
| 274 | 0 | resolvedArtifacts.put( key, previousNodes ); |
| 275 | |
} |
| 276 | 0 | previousNodes.add( node ); |
| 277 | |
|
| 278 | 0 | if ( node.isActive() ) |
| 279 | |
{ |
| 280 | 0 | fireEvent( ResolutionListener.INCLUDE_ARTIFACT, listeners, node ); |
| 281 | |
} |
| 282 | |
|
| 283 | |
|
| 284 | 0 | if ( node.isActive() && !Artifact.SCOPE_SYSTEM.equals( node.getArtifact().getScope() ) ) |
| 285 | |
{ |
| 286 | 0 | fireEvent( ResolutionListener.PROCESS_CHILDREN, listeners, node ); |
| 287 | |
|
| 288 | 0 | Artifact parentArtifact = node.getArtifact(); |
| 289 | |
|
| 290 | 0 | for ( Iterator i = node.getChildrenIterator(); i.hasNext(); ) |
| 291 | |
{ |
| 292 | 0 | ResolutionNode child = (ResolutionNode) i.next(); |
| 293 | |
|
| 294 | 0 | if ( !child.isResolved() && ( !child.getArtifact().isOptional() || child.isChildOfRootNode() ) ) |
| 295 | |
{ |
| 296 | 0 | List childRemoteRepositories = child.getRemoteRepositories(); |
| 297 | 0 | Artifact artifact = child.getArtifact(); |
| 298 | |
|
| 299 | |
try |
| 300 | |
{ |
| 301 | |
Object childKey; |
| 302 | |
do |
| 303 | |
{ |
| 304 | 0 | childKey = child.getKey(); |
| 305 | |
|
| 306 | 0 | if ( managedVersions.containsKey( childKey ) ) |
| 307 | |
{ |
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | 0 | manageArtifact( child, managedVersions, listeners ); |
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | 0 | Artifact ma = (Artifact) managedVersions.get( childKey ); |
| 320 | 0 | ArtifactFilter managedExclusionFilter = ma.getDependencyFilter(); |
| 321 | 0 | if ( null != managedExclusionFilter ) |
| 322 | |
{ |
| 323 | 0 | if ( null != artifact.getDependencyFilter() ) |
| 324 | |
{ |
| 325 | 0 | AndArtifactFilter aaf = new AndArtifactFilter(); |
| 326 | 0 | aaf.add( artifact.getDependencyFilter() ); |
| 327 | 0 | aaf.add( managedExclusionFilter ); |
| 328 | 0 | artifact.setDependencyFilter( aaf ); |
| 329 | 0 | } |
| 330 | |
else |
| 331 | |
{ |
| 332 | 0 | artifact.setDependencyFilter( managedExclusionFilter ); |
| 333 | |
} |
| 334 | |
} |
| 335 | |
} |
| 336 | |
|
| 337 | 0 | if ( artifact.getVersion() == null ) |
| 338 | |
{ |
| 339 | |
|
| 340 | |
|
| 341 | |
ArtifactVersion version; |
| 342 | 0 | if ( artifact.isSelectedVersionKnown() ) |
| 343 | |
{ |
| 344 | 0 | version = artifact.getSelectedVersion(); |
| 345 | |
} |
| 346 | |
else |
| 347 | |
{ |
| 348 | |
|
| 349 | 0 | List versions = artifact.getAvailableVersions(); |
| 350 | 0 | if ( versions == null ) |
| 351 | |
{ |
| 352 | 0 | versions = source.retrieveAvailableVersions( artifact, localRepository, |
| 353 | |
childRemoteRepositories ); |
| 354 | 0 | artifact.setAvailableVersions( versions ); |
| 355 | |
} |
| 356 | |
|
| 357 | 0 | Collections.sort( versions ); |
| 358 | |
|
| 359 | 0 | VersionRange versionRange = artifact.getVersionRange(); |
| 360 | |
|
| 361 | 0 | version = versionRange.matchVersion( versions ); |
| 362 | |
|
| 363 | 0 | if ( version == null ) |
| 364 | |
{ |
| 365 | |
|
| 366 | 0 | artifact.setDependencyTrail( node.getDependencyTrail() ); |
| 367 | |
|
| 368 | 0 | if ( versions.isEmpty() ) |
| 369 | |
{ |
| 370 | 0 | throw new OverConstrainedVersionException( |
| 371 | |
"No versions are present in the repository for the artifact with a range " + |
| 372 | |
versionRange, artifact, childRemoteRepositories ); |
| 373 | |
} |
| 374 | |
|
| 375 | 0 | throw new OverConstrainedVersionException( "Couldn't find a version in " + |
| 376 | |
versions + " to match range " + versionRange, artifact, |
| 377 | |
childRemoteRepositories ); |
| 378 | |
} |
| 379 | |
} |
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | 0 | artifact.selectVersion( version.toString() ); |
| 385 | 0 | fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); |
| 386 | |
} |
| 387 | |
|
| 388 | 0 | Artifact relocated = source.retrieveRelocatedArtifact( artifact, localRepository, childRemoteRepositories ); |
| 389 | 0 | if ( !artifact.equals( relocated ) ) |
| 390 | |
{ |
| 391 | 0 | relocated.setDependencyFilter( artifact.getDependencyFilter() ); |
| 392 | 0 | artifact = relocated; |
| 393 | 0 | child.setArtifact( artifact ); |
| 394 | |
} |
| 395 | |
} |
| 396 | 0 | while( !childKey.equals( child.getKey() ) ); |
| 397 | |
|
| 398 | 0 | if ( parentArtifact != null && parentArtifact.getDependencyFilter() != null && !parentArtifact.getDependencyFilter().include( artifact ) ) |
| 399 | |
{ |
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | 0 | continue; |
| 406 | |
} |
| 407 | |
|
| 408 | 0 | artifact.setDependencyTrail( node.getDependencyTrail() ); |
| 409 | 0 | ResolutionGroup rGroup = source.retrieve( artifact, localRepository, remoteRepositories ); |
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | 0 | if ( rGroup == null ) |
| 414 | |
{ |
| 415 | |
|
| 416 | 0 | continue; |
| 417 | |
} |
| 418 | |
|
| 419 | 0 | child.addDependencies( rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter ); |
| 420 | |
|
| 421 | |
} |
| 422 | 0 | catch ( CyclicDependencyException e ) |
| 423 | |
{ |
| 424 | |
|
| 425 | |
|
| 426 | 0 | fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners, |
| 427 | |
new ResolutionNode( e.getArtifact(), remoteRepositories, child ) ); |
| 428 | |
} |
| 429 | 0 | catch ( ArtifactMetadataRetrievalException e ) |
| 430 | |
{ |
| 431 | 0 | artifact.setDependencyTrail( node.getDependencyTrail() ); |
| 432 | 0 | throw new ArtifactResolutionException( |
| 433 | |
"Unable to get dependency information: " + e.getMessage(), artifact, remoteRepositories, |
| 434 | |
e ); |
| 435 | 0 | } |
| 436 | |
|
| 437 | 0 | recurse( originatingArtifact, child, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, |
| 438 | |
filter, listeners ); |
| 439 | |
} |
| 440 | 0 | } |
| 441 | |
|
| 442 | 0 | fireEvent( ResolutionListener.FINISH_PROCESSING_CHILDREN, listeners, node ); |
| 443 | |
} |
| 444 | 0 | } |
| 445 | |
|
| 446 | |
private void manageArtifact( ResolutionNode node, ManagedVersionMap managedVersions, List listeners ) |
| 447 | |
{ |
| 448 | 0 | Artifact artifact = (Artifact) managedVersions.get( node.getKey() ); |
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | 0 | if ( artifact.getVersion() != null |
| 458 | |
&& ( node.isChildOfRootNode() ? node.getArtifact().getVersion() == null : true ) ) |
| 459 | |
{ |
| 460 | 0 | fireEvent( ResolutionListener.MANAGE_ARTIFACT_VERSION, listeners, node, artifact ); |
| 461 | 0 | node.getArtifact().setVersion( artifact.getVersion() ); |
| 462 | |
} |
| 463 | |
|
| 464 | 0 | if ( artifact.getScope() != null |
| 465 | |
&& ( node.isChildOfRootNode() ? node.getArtifact().getScope() == null : true ) ) |
| 466 | |
{ |
| 467 | 0 | fireEvent( ResolutionListener.MANAGE_ARTIFACT_SCOPE, listeners, node, artifact ); |
| 468 | 0 | node.getArtifact().setScope( artifact.getScope() ); |
| 469 | |
} |
| 470 | 0 | } |
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners ) |
| 481 | |
{ |
| 482 | 0 | boolean updateScope = false; |
| 483 | 0 | Artifact farthestArtifact = farthest.getArtifact(); |
| 484 | 0 | Artifact nearestArtifact = nearest.getArtifact(); |
| 485 | |
|
| 486 | |
|
| 487 | 0 | if ( Artifact.SCOPE_RUNTIME.equals( farthestArtifact.getScope() ) && ( |
| 488 | |
Artifact.SCOPE_TEST.equals( nearestArtifact.getScope() ) || |
| 489 | |
Artifact.SCOPE_PROVIDED.equals( nearestArtifact.getScope() ) ) ) |
| 490 | |
{ |
| 491 | 0 | updateScope = true; |
| 492 | |
} |
| 493 | |
|
| 494 | |
|
| 495 | 0 | if ( Artifact.SCOPE_COMPILE.equals( farthestArtifact.getScope() ) && |
| 496 | |
!Artifact.SCOPE_COMPILE.equals( nearestArtifact.getScope() ) ) |
| 497 | |
{ |
| 498 | 0 | updateScope = true; |
| 499 | |
} |
| 500 | |
|
| 501 | |
|
| 502 | 0 | if ( nearest.getDepth() < 2 && updateScope ) |
| 503 | |
{ |
| 504 | 0 | updateScope = false; |
| 505 | |
|
| 506 | 0 | fireEvent( ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact ); |
| 507 | |
} |
| 508 | |
|
| 509 | 0 | if ( updateScope ) |
| 510 | |
{ |
| 511 | 0 | fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthestArtifact ); |
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | 0 | nearestArtifact.setScope( farthestArtifact.getScope() ); |
| 517 | |
} |
| 518 | |
|
| 519 | 0 | return updateScope; |
| 520 | |
} |
| 521 | |
|
| 522 | |
private void fireEvent( int event, List listeners, ResolutionNode node ) |
| 523 | |
{ |
| 524 | 0 | fireEvent( event, listeners, node, null ); |
| 525 | 0 | } |
| 526 | |
|
| 527 | |
private void fireEvent( int event, List listeners, ResolutionNode node, Artifact replacement ) |
| 528 | |
{ |
| 529 | 0 | fireEvent( event, listeners, node, replacement, null ); |
| 530 | 0 | } |
| 531 | |
|
| 532 | |
private void fireEvent( int event, List listeners, ResolutionNode node, Artifact replacement, |
| 533 | |
VersionRange newRange ) |
| 534 | |
{ |
| 535 | 0 | for ( Iterator i = listeners.iterator(); i.hasNext(); ) |
| 536 | |
{ |
| 537 | 0 | ResolutionListener listener = (ResolutionListener) i.next(); |
| 538 | |
|
| 539 | 0 | switch ( event ) |
| 540 | |
{ |
| 541 | |
case ResolutionListener.TEST_ARTIFACT: |
| 542 | 0 | listener.testArtifact( node.getArtifact() ); |
| 543 | 0 | break; |
| 544 | |
case ResolutionListener.PROCESS_CHILDREN: |
| 545 | 0 | listener.startProcessChildren( node.getArtifact() ); |
| 546 | 0 | break; |
| 547 | |
case ResolutionListener.FINISH_PROCESSING_CHILDREN: |
| 548 | 0 | listener.endProcessChildren( node.getArtifact() ); |
| 549 | 0 | break; |
| 550 | |
case ResolutionListener.INCLUDE_ARTIFACT: |
| 551 | 0 | listener.includeArtifact( node.getArtifact() ); |
| 552 | 0 | break; |
| 553 | |
case ResolutionListener.OMIT_FOR_NEARER: |
| 554 | 0 | listener.omitForNearer( node.getArtifact(), replacement ); |
| 555 | 0 | break; |
| 556 | |
case ResolutionListener.OMIT_FOR_CYCLE: |
| 557 | 0 | listener.omitForCycle( node.getArtifact() ); |
| 558 | 0 | break; |
| 559 | |
case ResolutionListener.UPDATE_SCOPE: |
| 560 | 0 | listener.updateScope( node.getArtifact(), replacement.getScope() ); |
| 561 | 0 | break; |
| 562 | |
case ResolutionListener.UPDATE_SCOPE_CURRENT_POM: |
| 563 | 0 | listener.updateScopeCurrentPom( node.getArtifact(), replacement.getScope() ); |
| 564 | 0 | break; |
| 565 | |
case ResolutionListener.MANAGE_ARTIFACT_VERSION: |
| 566 | 0 | if (listener instanceof ResolutionListenerForDepMgmt) { |
| 567 | 0 | ResolutionListenerForDepMgmt asImpl = (ResolutionListenerForDepMgmt) listener; |
| 568 | 0 | asImpl.manageArtifactVersion( node.getArtifact(), replacement ); |
| 569 | 0 | } else { |
| 570 | 0 | listener.manageArtifact( node.getArtifact(), replacement ); |
| 571 | |
} |
| 572 | 0 | break; |
| 573 | |
case ResolutionListener.MANAGE_ARTIFACT_SCOPE: |
| 574 | 0 | if (listener instanceof ResolutionListenerForDepMgmt) { |
| 575 | 0 | ResolutionListenerForDepMgmt asImpl = (ResolutionListenerForDepMgmt) listener; |
| 576 | 0 | asImpl.manageArtifactScope( node.getArtifact(), replacement ); |
| 577 | 0 | } else { |
| 578 | 0 | listener.manageArtifact( node.getArtifact(), replacement ); |
| 579 | |
} |
| 580 | 0 | break; |
| 581 | |
case ResolutionListener.SELECT_VERSION_FROM_RANGE: |
| 582 | 0 | listener.selectVersionFromRange( node.getArtifact() ); |
| 583 | 0 | break; |
| 584 | |
case ResolutionListener.RESTRICT_RANGE: |
| 585 | 0 | if ( node.getArtifact().getVersionRange().hasRestrictions() || |
| 586 | |
replacement.getVersionRange().hasRestrictions() ) |
| 587 | |
{ |
| 588 | 0 | listener.restrictRange( node.getArtifact(), replacement, newRange ); |
| 589 | |
} |
| 590 | |
break; |
| 591 | |
default: |
| 592 | 0 | throw new IllegalStateException( "Unknown event: " + event ); |
| 593 | |
} |
| 594 | 0 | } |
| 595 | 0 | } |
| 596 | |
|
| 597 | |
} |