1 17 package org.apache.servicemix.maven.plugin.jbi; 18 19 import org.apache.maven.artifact.Artifact; 20 import org.apache.maven.artifact.resolver.ResolutionListener; 21 import org.apache.maven.artifact.versioning.VersionRange; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Stack ; 29 30 33 public class JbiResolutionListener 34 implements ResolutionListener 35 { 36 private Stack parents = new Stack (); 37 38 private Map artifacts = new HashMap (); 39 40 private Node rootNode; 41 42 public void testArtifact( Artifact artifact ) 43 { 44 } 46 47 public void startProcessChildren( Artifact artifact ) 48 { 49 Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); 50 if ( parents.isEmpty() ) 51 { 52 rootNode = node; 53 } 54 55 parents.push( node ); 56 } 57 58 public void endProcessChildren( Artifact artifact ) 59 { 60 Node check = (Node) parents.pop(); 61 assert artifact.equals( check.artifact ); 62 } 63 64 public void omitForNearer( Artifact omitted, Artifact kept ) 65 { 66 assert omitted.getDependencyConflictId().equals( kept.getDependencyConflictId() ); 67 68 Node prev = (Node) artifacts.get( omitted.getDependencyConflictId() ); 69 if ( prev != null ) 70 { 71 if ( prev.parent != null ) 72 { 73 prev.parent.children.remove( prev ); 74 } 75 artifacts.remove( omitted.getDependencyConflictId() ); 76 } 77 78 includeArtifact( kept ); 79 } 80 81 public void omitForCycle( Artifact artifact ) 82 { 83 } 85 86 public void includeArtifact( Artifact artifact ) 87 { 88 if ( artifacts.containsKey( artifact.getDependencyConflictId() ) ) 89 { 90 Node prev = (Node) artifacts.get( artifact.getDependencyConflictId() ); 91 if ( prev.parent != null ) 92 { 93 prev.parent.children.remove( prev ); 94 } 95 artifacts.remove( artifact.getDependencyConflictId() ); 96 } 97 98 Node node = new Node(); 99 node.artifact = artifact; 100 if ( !parents.isEmpty() ) 101 { 102 node.parent = (Node) parents.peek(); 103 node.parent.children.add( node ); 104 } 105 artifacts.put( artifact.getDependencyConflictId(), node ); 106 } 107 108 public void updateScope( Artifact artifact, String scope ) 109 { 110 Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); 111 112 node.artifact.setScope( scope ); 113 } 114 115 public void manageArtifact( Artifact artifact, Artifact replacement ) 116 { 117 Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); 118 119 if ( node != null ) 120 { 121 if ( replacement.getVersion() != null ) 122 { 123 node.artifact.setVersion( replacement.getVersion() ); 124 } 125 if ( replacement.getScope() != null ) 126 { 127 node.artifact.setScope( replacement.getScope() ); 128 } 129 } 130 } 131 132 public void updateScopeCurrentPom( Artifact artifact, String key ) 133 { 134 } 136 137 public void selectVersionFromRange( Artifact artifact ) 138 { 139 } 141 142 public void restrictRange( Artifact artifact, Artifact artifact1, VersionRange versionRange ) 143 { 144 } 146 147 public Node getNode(Artifact artifact) { 148 return (Node) artifacts.get(artifact.getDependencyConflictId()); 149 } 150 151 public Collection getArtifacts() 152 { 153 return artifacts.values(); 154 } 155 156 static class Node 157 { 158 private Node parent; 159 160 private List children = new ArrayList (); 161 162 private Artifact artifact; 163 164 public List getChildren() 165 { 166 return children; 167 } 168 169 public Artifact getArtifact() 170 { 171 return artifact; 172 } 173 174 public Node getParent() { 175 return parent; 176 } 177 } 178 179 public Node getRootNode() 180 { 181 return rootNode; 182 } 183 } 184 | Popular Tags |