KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > maven > plugin > jbi > JbiResolutionListener


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Stack JavaDoc;
29
30 /**
31  * @author Edwin Punzalan
32  */

33 public class JbiResolutionListener
34     implements ResolutionListener
35 {
36     private Stack JavaDoc parents = new Stack JavaDoc();
37
38     private Map JavaDoc artifacts = new HashMap JavaDoc();
39
40     private Node rootNode;
41
42     public void testArtifact( Artifact artifact )
43     {
44         // intentionally blank
45
}
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         // intentionally blank
84
}
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 JavaDoc 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 JavaDoc key )
133     {
134         // intentionally blank
135
}
136
137     public void selectVersionFromRange( Artifact artifact )
138     {
139         // intentionally blank
140
}
141
142     public void restrictRange( Artifact artifact, Artifact artifact1, VersionRange versionRange )
143     {
144         // intentionally blank
145
}
146
147     public Node getNode(Artifact artifact) {
148         return (Node) artifacts.get(artifact.getDependencyConflictId());
149     }
150     
151     public Collection JavaDoc getArtifacts()
152     {
153         return artifacts.values();
154     }
155
156     static class Node
157     {
158         private Node parent;
159
160         private List JavaDoc children = new ArrayList JavaDoc();
161
162         private Artifact artifact;
163
164         public List JavaDoc 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