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

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.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:
32
32
import java.util.Set;
33
33
import java.util.Map.Entry;
34
34
 
35
 
import org.apache.ivy.core.IvyContext;
36
35
import org.apache.ivy.core.IvyPatternHelper;
37
36
import org.apache.ivy.core.module.descriptor.Artifact;
38
37
import org.apache.ivy.core.module.descriptor.DefaultArtifact;
39
38
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
40
 
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
41
39
import org.apache.ivy.core.module.id.ModuleRevisionId;
42
 
import org.apache.ivy.core.resolve.IvyNode;
43
40
import org.apache.ivy.core.resolve.ResolveData;
44
41
import org.apache.ivy.core.settings.IvyPattern;
45
 
import org.apache.ivy.plugins.conflict.ConflictManager;
46
42
import org.apache.ivy.plugins.matcher.Matcher;
47
 
import org.apache.ivy.plugins.resolver.util.MDResolvedResource;
48
43
import org.apache.ivy.plugins.resolver.util.ResolvedResource;
49
44
import org.apache.ivy.plugins.resolver.util.ResourceMDParser;
50
 
import org.apache.ivy.plugins.version.VersionMatcher;
51
45
import org.apache.ivy.util.Message;
52
46
 
53
47
/**
73
67
            data.getDate()), getRMDParser(dd, data), data.getDate());
74
68
    }
75
69
 
76
 
    protected ResolvedResource findArtifactRef(Artifact artifact, Date date) {
 
70
    public ResolvedResource findArtifactRef(Artifact artifact, Date date) {
77
71
        ModuleRevisionId mrid = artifact.getModuleRevisionId();
78
72
        if (isM2compatible()) {
79
73
            mrid = convertM2IdForResourceSearch(mrid);
81
75
        return findResourceUsingPatterns(mrid, artifactPatterns, artifact,
82
76
            getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date);
83
77
    }
 
78
    
 
79
    public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser,
 
80
            ModuleRevisionId mrid, Date date) {
 
81
        if (isM2compatible()) {
 
82
            // convert 'M2'-organisation back to 'Ivy'-organisation
 
83
            mrid = convertM2ResourceSearchIdToNormal(mrid);
 
84
        }
 
85
        return super.findResource(rress, rmdparser, mrid, date);
 
86
    }    
84
87
 
85
88
    protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevision,
86
89
            List patternList, Artifact artifact, ResourceMDParser rmdparser, Date date) {
114
117
    protected abstract ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid,
115
118
            String pattern, Artifact artifact, ResourceMDParser rmdparser, Date date);
116
119
 
117
 
    public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser,
118
 
            ModuleRevisionId mrid, Date date) {
119
 
        String name = getName();
120
 
        VersionMatcher versionMatcher = getSettings().getVersionMatcher();
121
 
        
122
 
        ResolvedResource found = null;
123
 
        List sorted = getLatestStrategy().sort(rress);
124
 
        List rejected = new ArrayList();
125
 
        List foundBlacklisted = new ArrayList();
126
 
        IvyContext context = IvyContext.getContext();
127
 
        
128
 
        for (ListIterator iter = sorted.listIterator(sorted.size()); iter.hasPrevious();) {
129
 
            ResolvedResource rres = (ResolvedResource) iter.previous();
130
 
            // we start by filtering based on information already available,
131
 
            // even though we don't even know if the resource actually exist.
132
 
            // But checking for existence is most of the time more costly than checking 
133
 
            // name, blacklisting and first level version matching
134
 
            if (filterNames(new ArrayList(Collections.singleton(rres.getRevision()))).isEmpty()) {
135
 
                Message.debug("\t" + name + ": filtered by name: " + rres);
136
 
                continue;
137
 
            }
138
 
            ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());
139
 
            
140
 
            ResolveData data = context.getResolveData();
141
 
            if (data != null
142
 
                    && data.getReport() != null 
143
 
                    && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
144
 
                Message.debug("\t" + name + ": blacklisted: " + rres);
145
 
                rejected.add(rres.getRevision() + " (blacklisted)");
146
 
                foundBlacklisted.add(foundMrid);
147
 
                continue;
148
 
            }
149
 
            
150
 
            if (!versionMatcher.accept(mrid, foundMrid)) {
151
 
                Message.debug("\t" + name + ": rejected by version matcher: " + rres);
152
 
                rejected.add(rres.getRevision());
153
 
                continue;
154
 
            }
155
 
            if (!rres.getResource().exists()) {
156
 
                Message.debug("\t" + name + ": unreachable: " + rres 
157
 
                    + "; res=" + rres.getResource());
158
 
                rejected.add(rres.getRevision() + " (unreachable)");
159
 
                continue;
160
 
            }
161
 
            if ((date != null && rres.getLastModified() > date.getTime())) {
162
 
                Message.verbose("\t" + name + ": too young: " + rres);
163
 
                rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
164
 
                continue;
165
 
            }
166
 
            if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
167
 
                ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
168
 
                if (r == null) {
169
 
                    Message.debug("\t" + name 
170
 
                        + ": impossible to get module descriptor resource: " + rres);
171
 
                    rejected.add(rres.getRevision() + " (no or bad MD)");
172
 
                    continue;
173
 
                }
174
 
                ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision()
175
 
                        .getDescriptor();
176
 
                if (md.isDefault()) {
177
 
                    Message.debug("\t" + name + ": default md rejected by version matcher" 
178
 
                            + "requiring module descriptor: " + rres);
179
 
                    rejected.add(rres.getRevision() + " (MD)");
180
 
                    continue;
181
 
                } else if (!versionMatcher.accept(mrid, md)) {
182
 
                    Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
183
 
                    rejected.add(rres.getRevision() + " (MD)");
184
 
                    continue;
185
 
                } else {
186
 
                    found = r;
187
 
                }
188
 
            } else {
189
 
                found = rres;
190
 
            }
191
 
 
192
 
            if (found != null) {
193
 
                break;
194
 
            }
195
 
        }
196
 
        if (found == null && !rejected.isEmpty()) {
197
 
            logAttempt(rejected.toString());
198
 
        }
199
 
        if (found == null && !foundBlacklisted.isEmpty()) {
200
 
            // all acceptable versions have been blacklisted, this means that an unsolvable conflict
201
 
            // has been found
202
 
            DependencyDescriptor dd = context.getDependencyDescriptor();
203
 
            IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
204
 
            ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
205
 
            cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
206
 
        }
207
 
 
208
 
        return found;
209
 
    }
210
 
 
211
120
    protected Collection findNames(Map tokenValues, String token) {
212
121
        Collection names = new HashSet();
213
122
        names.addAll(findIvyNames(tokenValues, token));
356
265
    
357
266
    protected abstract boolean exist(String path);
358
267
 
359
 
    /**
360
 
     * Filters names before returning them in the findXXXNames or findTokenValues method.
361
 
     * <p>
362
 
     * Remember to call the super implementation when overriding this method.
363
 
     * </p>
364
 
     * 
365
 
     * @param names
366
 
     *            the list to filter.
367
 
     * @return the filtered list
368
 
     */
369
 
    protected Collection filterNames(Collection names) {
370
 
        getSettings().filterIgnore(names);
371
 
        return names;
372
 
    }
373
 
 
374
268
    protected void findTokenValues(Collection names, List patterns, Map tokenValues, String token) {
375
269
        //to be overridden by subclasses wanting to have listing features
376
270
    }
437
331
    public void setM2compatible(boolean compatible) {
438
332
        m2compatible = compatible;
439
333
    }
 
334
    
 
335
    protected ModuleRevisionId convertM2ResourceSearchIdToNormal(ModuleRevisionId mrid) {
 
336
        if (mrid.getOrganisation() == null || mrid.getOrganisation().indexOf('/') == -1) {
 
337
            return mrid;
 
338
        }
 
339
        return ModuleRevisionId.newInstance(mrid.getOrganisation().replace('/', '.'),
 
340
            mrid.getName(), mrid.getBranch(), mrid.getRevision(),
 
341
            mrid.getQualifiedExtraAttributes());
 
342
    }
440
343
 
441
344
    protected ModuleRevisionId convertM2IdForResourceSearch(ModuleRevisionId mrid) {
442
345
        if (mrid.getOrganisation() == null || mrid.getOrganisation().indexOf('.') == -1) {