~ubuntu-branches/ubuntu/trusty/ivy/trusty-proposed

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/core/resolve/ResolveData.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-15 17:44:57 UTC
  • mfrom: (3.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130515174457-ogntd0vxluwalq11
Tags: 2.3.0-2
* Team upload.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
    }
95
95
 
96
96
    public VisitData getVisitData(ModuleRevisionId mrid) {
97
 
        return (VisitData) visitData.get(mrid);
 
97
        VisitData result = (VisitData) visitData.get(mrid);
 
98
 
 
99
        if (result == null) {
 
100
            // search again, now ignore the missing extra attributes
 
101
            for (Iterator it = visitData.entrySet().iterator(); it.hasNext();) {
 
102
                Map.Entry entry = (Entry) it.next();
 
103
                ModuleRevisionId current = (ModuleRevisionId) entry.getKey();
 
104
                
 
105
                if (isSubMap(mrid.getAttributes(), current.getAttributes())) {
 
106
                    result = (VisitData) entry.getValue();
 
107
                    break;
 
108
                }
 
109
            }
 
110
        }
 
111
 
 
112
        return result;
 
113
    }
 
114
    
 
115
    /**
 
116
     * Checks whether one map is a sub-map of the other.
 
117
     */
 
118
    private static boolean isSubMap(Map map1, Map map2) {
 
119
        int map1Size = map1.size();
 
120
        int map2Size = map2.size();
 
121
        
 
122
        if (map1Size == map2Size) {
 
123
            return map1.equals(map2);
 
124
        }
 
125
        
 
126
        Map smallest = map1Size < map2Size ? map1 : map2;
 
127
        Map largest = map1Size < map2Size ? map2 : map1;
 
128
        
 
129
        for (Iterator it = smallest.entrySet().iterator(); it.hasNext(); ) {
 
130
            Map.Entry entry = (Entry) it.next();
 
131
            
 
132
            if (!largest.containsKey(entry.getKey())) {
 
133
                return false;
 
134
            }
 
135
            
 
136
            Object map1Value = smallest.get(entry.getKey());
 
137
            Object map2Value = largest.get(entry.getKey());
 
138
            if (!isEqual(map1Value, map2Value)) {
 
139
                return false;
 
140
            }
 
141
        }
 
142
        
 
143
        return true;
 
144
    }
 
145
    
 
146
    private static boolean isEqual(Object obj1, Object obj2) {
 
147
        if (obj1 == obj2) {
 
148
            return true;
 
149
        }
 
150
        
 
151
        if (obj1 == null) {
 
152
            return obj2 == null;
 
153
        }
 
154
        
 
155
        if (obj2 == null) {
 
156
            return obj1 == null;
 
157
        }
 
158
        
 
159
        return obj1.equals(obj2);
98
160
    }
99
161
    
100
162
    /**
210
272
    public boolean isBlacklisted(String rootModuleConf, ModuleRevisionId mrid) {
211
273
        IvyNode node = getNode(mrid);
212
274
        
213
 
        if (node == null) {
214
 
            // search again, now ignore the extra attributes
215
 
            // TODO: maybe we should search the node that has at least the 
216
 
            // same attributes as mrid
217
 
            for (Iterator it = visitData.entrySet().iterator(); it.hasNext();) {
218
 
                Map.Entry entry = (Entry) it.next();
219
 
                ModuleRevisionId current = (ModuleRevisionId) entry.getKey();
220
 
                if (current.getModuleId().equals(mrid.getModuleId())
221
 
                        && current.getRevision().equals(mrid.getRevision())) {
222
 
                    VisitData data = (VisitData) entry.getValue();
223
 
                    node = data.getNode();
224
 
                    break;
225
 
                }
226
 
            }
227
 
        }
228
 
        
 
275
//        if (node == null) {
 
276
//            // search again, now ignore the extra attributes
 
277
//            // TODO: maybe we should search the node that has at least the 
 
278
//            // same attributes as mrid
 
279
//            for (Iterator it = visitData.entrySet().iterator(); it.hasNext();) {
 
280
//                Map.Entry entry = (Entry) it.next();
 
281
//                ModuleRevisionId current = (ModuleRevisionId) entry.getKey();
 
282
//                if (current.getModuleId().equals(mrid.getModuleId())
 
283
//                        && current.getRevision().equals(mrid.getRevision())) {
 
284
//                    VisitData data = (VisitData) entry.getValue();
 
285
//                    node = data.getNode();
 
286
//                    break;
 
287
//                }
 
288
//            }
 
289
//        }
 
290
//        
229
291
        return node != null && node.isBlacklisted(rootModuleConf);
230
292
    }
231
293