Java Code Examples for org.apache.ivy.core.module.id.ModuleRevisionId#getRevision()

The following examples show how to use org.apache.ivy.core.module.id.ModuleRevisionId#getRevision() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private ModuleRevisionId getRevision(ResolvedResource ivyRef, ModuleRevisionId askedMrid,
        ModuleDescriptor md) {
    Map<String, String> allAttributes = new HashMap<>();
    allAttributes.putAll(md.getQualifiedExtraAttributes());
    allAttributes.putAll(askedMrid.getQualifiedExtraAttributes());

    String revision = ivyRef.getRevision();
    if (revision == null) {
        Message.debug("no revision found in reference for " + askedMrid);
        if (getSettings().getVersionMatcher().isDynamic(askedMrid)) {
            if (md.getModuleRevisionId().getRevision() == null) {
                revision = "working@" + getName();
            } else {
                Message.debug("using " + askedMrid);
                revision = askedMrid.getRevision();
            }
        } else {
            Message.debug("using " + askedMrid);
            revision = askedMrid.getRevision();
        }
    }

    return ModuleRevisionId.newInstance(askedMrid.getOrganisation(), askedMrid.getName(),
        askedMrid.getBranch(), revision, allAttributes);
}
 
Example 2
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void resolveAndCheckRevision(ModuleDescriptor systemMd,
        ModuleRevisionId dependencyConstraint, ResolvedResource ivyRef, boolean isDynamic) {
    // we get the resolved module revision id from the descriptor: it may contain extra
    // attributes that were not included in the dependency constraint
    ModuleRevisionId resolvedMrid = systemMd.getResolvedModuleRevisionId();
    if (resolvedMrid.getRevision() == null || resolvedMrid.getRevision().length() == 0
            || resolvedMrid.getRevision().startsWith("working@")) {
        if (!isDynamic) {
            resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid,
                dependencyConstraint.getRevision());
        } else if (ivyRef == null) {
            resolvedMrid = systemMd.getMetadataArtifact().getModuleRevisionId();
        } else if (ivyRef.getRevision() == null || ivyRef.getRevision().length() == 0) {
            resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, "working@" + getName());
        } else {
            resolvedMrid = ModuleRevisionId.newInstance(resolvedMrid, ivyRef.getRevision());
        }
    }
    if (isDynamic) {
        Message.verbose("\t\t[" + toSystem(resolvedMrid).getRevision() + "] "
                + dependencyConstraint.getModuleId());
    }
    systemMd.setResolvedModuleRevisionId(resolvedMrid);
    checkModuleDescriptorRevision(systemMd, dependencyConstraint);
}
 
Example 3
Source File: Match.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public Matcher getPatternMatcher(ModuleRevisionId askedMrid) {
    String revision = askedMrid.getRevision();

    List<String> args = split(getArgs());
    List<String> argValues = getRevisionArgs(revision);

    if (args.size() != argValues.size()) {
        return new NoMatchMatcher();
    }

    Map<String, String> variables = new HashMap<>();
    for (String arg : args) {
        variables.put(arg, argValues.get(args.indexOf(arg)));
    }

    String pattern = getPattern();
    pattern = IvyPatternHelper.substituteVariables(pattern, variables);

    PatternMatcher pMatcher = IvyContext.getContext().getSettings().getMatcher(matcher);
    return pMatcher.getMatcher(pattern);
}
 
Example 4
Source File: PomModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static void setModuleVariables(ModuleDescriptor md, IvyVariableContainer variables,
        PomWriterOptions options) {
    ModuleRevisionId mrid = md.getModuleRevisionId();
    variables.setVariable("ivy.pom.groupId", mrid.getOrganisation(), true);

    String artifactId = options.getArtifactName();
    if (artifactId == null) {
        artifactId = mrid.getName();
    }

    String packaging = options.getArtifactPackaging();
    if (packaging == null) {
        // find artifact to determine the packaging
        Artifact artifact = findArtifact(md, artifactId);
        if (artifact == null) {
            // no suitable artifact found, default to 'pom'
            packaging = "pom";
        } else {
            packaging = artifact.getType();
        }
    }

    variables.setVariable("ivy.pom.artifactId", artifactId, true);
    variables.setVariable("ivy.pom.packaging", packaging, true);
    if (mrid.getRevision() != null) {
        variables.setVariable("ivy.pom.version", mrid.getRevision(), true);
    }
    if (options.getDescription() != null) {
        variables.setVariable("ivy.pom.description", options.getDescription(), true);
    } else if (!isNullOrEmpty(md.getDescription())) {
        variables.setVariable("ivy.pom.description", md.getDescription(), true);
    }
    if (md.getHomePage() != null) {
        variables.setVariable("ivy.pom.url", md.getHomePage(), true);
    }
}
 
Example 5
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void checkRevision(ModuleRevisionId systemMrid) {
    // check revision
    int index = systemMrid.getRevision().indexOf('@');
    if (index != -1 && !systemMrid.getRevision().substring(index + 1).equals(workspaceName)) {
        throw new UnresolvedDependencyException("\t" + getName() + ": unhandled revision => "
                + systemMrid.getRevision());
    }
}
 
Example 6
Source File: PatternVersionMatcher.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isDynamic(ModuleRevisionId askedMrid) {
    init();
    String revision = askedMrid.getRevision();
    int bracketIndex = revision.indexOf('(');
    if (bracketIndex > 0) {
        revision = revision.substring(0, bracketIndex);
    }
    return revisionMatches.containsKey(revision);
}
 
Example 7
Source File: OsgiLatestStrategy.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public int compare(ModuleRevisionId o1, ModuleRevisionId o2) {
    Version v1 = new Version(o1.getRevision());
    Version v2 = new Version(o2.getRevision());
    try {
        return v1.compareTo(v2);
    } catch (RuntimeException e) {
        if (e.getCause() instanceof ParseException) {
            throw new RuntimeException("Uncomparable versions:" + o1.getRevision()
                    + " and " + o2.getRevision() + " (" + e.getMessage() + ")");
        }
        throw e;
    }
}
 
Example 8
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    writer.attribute("publication", ivyDateFormat.format(md.getResolvedPublicationDate()));
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        writer.startElement(extraDescr.getKey().toString());
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 9
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void startExtends(Attributes attributes) {
    // in merge mode, comment out extends element
    if (options.isMerge()) {
        write("<!-- ");
    }
    write("<extends");

    String org = substitute(settings, attributes.getValue("organisation"));
    String module = substitute(settings, attributes.getValue("module"));
    ModuleId parentId = new ModuleId(org, module);

    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getQName(i);
        String value = null;

        switch (name) {
            case "organisation":
                value = org;
                break;
            case "module":
                value = module;
                break;
            case "revision":
                // replace inline revision with resolved parent revision
                ModuleDescriptor merged = options.getMergedDescriptor();
                if (merged != null) {
                    for (ExtendsDescriptor parent : merged.getInheritedDescriptors()) {
                        ModuleRevisionId resolvedId = parent.getResolvedParentRevisionId();
                        if (parentId.equals(resolvedId.getModuleId())) {
                            value = resolvedId.getRevision();
                            if (value != null) {
                                break;
                            }
                        }
                    }
                }
                if (value == null) {
                    value = substitute(settings, attributes.getValue(i));
                }
                break;
            default:
                value = substitute(settings, attributes.getValue(i));
                break;
        }
        write(" " + name + "=\"" + value + "\"");
    }
}
 
Example 10
Source File: IvyDeliver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public String resolve(ModuleDescriptor published, String publishedStatus,
        ModuleRevisionId depMrid, String depStatus) {
    if (StatusManager.getCurrent().isIntegration(publishedStatus)) {
        // published status is integration one, nothing to ask
        return super.resolve(published, publishedStatus, depMrid, depStatus);
    }

    // we are publishing a delivery (a non integration module)

    if (!StatusManager.getCurrent().isIntegration(depStatus)) {
        // dependency is already a delivery, nothing to ask
        return super.resolve(published, publishedStatus, depMrid, depStatus);
    }

    // the dependency is not a delivery

    String statusProperty = depMrid.getName() + "." + depMrid.getRevision() + ".status";
    String versionProperty = depMrid.getName() + "." + depMrid.getRevision() + ".version";
    String deliveredProperty = depMrid.getName() + "." + depMrid.getRevision()
            + ".delivered";

    String version = getProject().getProperty(versionProperty);
    String status = getProject().getProperty(statusProperty);
    String delivered = getProject().getProperty(deliveredProperty);
    Message.debug("found version = " + version + " status=" + status + " delivered="
            + delivered);
    if (version != null && status != null) {
        if ("true".equals(delivered)) {
            // delivery has already been done : just return the value
            return version;
        } else {
            deliverDependency(depMrid, version, status, depStatus);
            loadDeliveryList();
            return version;
        }
    }

    /**
     * By setting these properties: recursive.delivery.status and
     * recursive.delivery.version, then if the specific status/version is not found, then we
     * will use the status/version set in these global properties. This will apply to all
     * artifacts in the system. This patch is meant to be used for recursive deliveries so
     * that all deliveries will use the global status/version unless a more specific one is
     * set.
     */
    String globalStatusProperty = "recursive.delivery.status";
    String globalVersionProperty = "recursive.delivery.version";
    version = getProject().getProperty(globalVersionProperty);
    status = getProject().getProperty(globalStatusProperty);
    if (version != null && status != null) {
        // found global delivery properties
        delivered = getProject().getProperty(
            "recursive." + depMrid.getName() + ".delivered");
        Message.debug("found global version = " + version + " and global status=" + status
                + " - delivered = " + delivered);
        if ("true".equals(delivered)) {
            // delivery has already been done : just return the value
            return version;
        } else {
            getProject().setProperty(statusProperty, status);
            deliverDependency(depMrid, version, status, depStatus);
            loadDeliveryList();
            return version;
        }
    }

    // we must ask the user what version and status he want to have
    // for the dependency
    Input input = (Input) getProject().createTask("input");
    input.setOwningTarget(getOwningTarget());
    input.init();

    // ask status
    input.setMessage(depMrid.getName() + " " + depMrid.getRevision()
            + ": please enter a status: ");
    input.setValidargs(StatusManager.getCurrent().getDeliveryStatusListString());
    input.setAddproperty(statusProperty);
    input.perform();
    status = getProject().getProperty(statusProperty);
    appendDeliveryList(statusProperty + " = " + status);

    // ask version
    input.setMessage(depMrid.getName() + " " + depMrid.getRevision()
            + ": please enter a version: ");
    input.setValidargs(null);
    input.setAddproperty(versionProperty);
    input.perform();

    version = getProject().getProperty(versionProperty);
    appendDeliveryList(versionProperty + " = " + version);
    deliverDependency(depMrid, version, status, depStatus);

    loadDeliveryList();

    return version;
}
 
Example 11
Source File: DefaultDependencyMetaData.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultDependencyMetaData(DependencyDescriptor dependencyDescriptor) {
    this.dependencyDescriptor = dependencyDescriptor;
    ModuleRevisionId dependencyRevisionId = dependencyDescriptor.getDependencyRevisionId();
    requested = new DefaultModuleVersionSelector(dependencyRevisionId.getOrganisation(), dependencyRevisionId.getName(), dependencyRevisionId.getRevision());
}
 
Example 12
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void infoStarted(Attributes attributes) {

            String module = substitute(settings, attributes.getValue("module"));
            String rev = null;
            String branch = null;
            String status = null;
            String namespace = null;
            Map<String, String> extraAttributes = null;

            if (options.isMerge()) {
                // get attributes from merged descriptor, ignoring raw XML
                ModuleDescriptor merged = options.getMergedDescriptor();
                ModuleRevisionId mergedMrid = merged.getModuleRevisionId();
                organisation = mergedMrid.getOrganisation();
                branch = mergedMrid.getBranch();
                rev = mergedMrid.getRevision();
                status = merged.getStatus();

                // TODO: should namespace be added to ModuleDescriptor interface, so we don't
                // have to do this kind of check?
                if (merged instanceof DefaultModuleDescriptor) {
                    Namespace ns = ((DefaultModuleDescriptor) merged).getNamespace();
                    if (ns != null) {
                        namespace = ns.getName();
                    }
                }
                if (namespace == null) {
                    namespace = attributes.getValue("namespace");
                }

                extraAttributes = merged.getQualifiedExtraAttributes();
            } else {
                // get attributes from raw XML, performing property substitution
                organisation = substitute(settings, attributes.getValue("organisation"));
                rev = substitute(settings, attributes.getValue("revision"));
                branch = substitute(settings, attributes.getValue("branch"));
                status = substitute(settings, attributes.getValue("status"));
                namespace = substitute(settings, attributes.getValue("namespace"));
                extraAttributes = new LinkedHashMap<>(attributes.getLength());
                for (int i = 0; i < attributes.getLength(); i++) {
                    String qname = attributes.getQName(i);
                    if (!STD_ATTS.contains(qname)) {
                        extraAttributes.put(qname, substitute(settings, attributes.getValue(i)));
                    }
                }
            }

            // apply override values provided in options
            if (revision != null) {
                rev = revision;
            }
            if (options.getBranch() != null) {
                branch = options.getBranch();
            }
            if (this.status != null) {
                status = this.status;
            }

            // if necessary translate mrid using optional namespace argument
            ModuleRevisionId localMid = ModuleRevisionId.newInstance(organisation, module, branch,
                rev, ExtendableItemHelper.getExtraAttributes(settings, attributes,
                            Arrays.asList("organisation", "module", "revision", "status",
                                    "publication", "namespace")));
            ModuleRevisionId systemMid = (ns == null) ? localMid : ns.getToSystemTransformer()
                    .transform(localMid);

            write("<info");
            if (organisation != null) {
                write(" organisation=\"" + XMLHelper.escape(systemMid.getOrganisation()) + "\"");
            }
            write(" module=\"" + XMLHelper.escape(systemMid.getName()) + "\"");
            if (branch != null) {
                write(" branch=\"" + XMLHelper.escape(systemMid.getBranch()) + "\"");
            }
            if (systemMid.getRevision() != null) {
                write(" revision=\"" + XMLHelper.escape(systemMid.getRevision()) + "\"");
            }
            write(" status=\"" + XMLHelper.escape(status) + "\"");
            if (pubdate != null) {
                write(" publication=\"" + DateUtil.format(pubdate) + "\"");
            } else if (attributes.getValue("publication") != null) {
                write(" publication=\"" + substitute(settings, attributes.getValue("publication"))
                        + "\"");
            }
            if (namespace != null) {
                write(" namespace=\"" + namespace + "\"");
            }

            for (Map.Entry<String, String> extra : extraAttributes.entrySet()) {
                write(" " + extra.getKey() + "=\"" + extra.getValue() + "\"");
            }
        }
 
Example 13
Source File: VersionRangeMatcher.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public boolean isDynamic(ModuleRevisionId askedMrid) {
    String revision = askedMrid.getRevision();
    return ALL_RANGE.matcher(revision).matches();
}
 
Example 14
Source File: DefaultDependencyMetaData.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultDependencyMetaData(DependencyDescriptor dependencyDescriptor) {
    this.dependencyDescriptor = dependencyDescriptor;
    ModuleRevisionId dependencyRevisionId = dependencyDescriptor.getDependencyRevisionId();
    requested = new DefaultModuleVersionSelector(dependencyRevisionId.getOrganisation(), dependencyRevisionId.getName(), dependencyRevisionId.getRevision());
}
 
Example 15
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    Date publicationDate = md.getResolvedPublicationDate();
    if (publicationDate != null) {
        writer.attribute("publication", ivyDateFormat.format(publicationDate));
    }
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        if (extraDescr.getKey() instanceof NamespaceId) {
            NamespaceId id = (NamespaceId) extraDescr.getKey();
            writer.startElement(String.format("ns:%s", id.getName()));
            writer.attribute("xmlns:ns", id.getNamespace());
        } else {
            writer.startElement(extraDescr.getKey().toString());
        }
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 16
Source File: DefaultDependencyMetaData.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultDependencyMetaData(DependencyDescriptor dependencyDescriptor) {
    this.dependencyDescriptor = dependencyDescriptor;
    ModuleRevisionId dependencyRevisionId = dependencyDescriptor.getDependencyRevisionId();
    requested = new DefaultModuleVersionSelector(dependencyRevisionId.getOrganisation(), dependencyRevisionId.getName(), dependencyRevisionId.getRevision());
}
 
Example 17
Source File: DefaultModuleVersionIdentifier.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ModuleVersionIdentifier newId(ModuleRevisionId moduleRevisionId) {
    return new DefaultModuleVersionIdentifier(moduleRevisionId.getOrganisation(), moduleRevisionId.getName(), moduleRevisionId.getRevision());
}
 
Example 18
Source File: PackagerCacheEntry.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private static File getSubdir(File rootDir, ModuleRevisionId mr) {
    return new File(rootDir, mr.getOrganisation() + File.separatorChar + mr.getName()
            + File.separatorChar + mr.getRevision());
}
 
Example 19
Source File: DefaultDependencyMetaData.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultDependencyMetaData(DependencyDescriptor dependencyDescriptor) {
    this.dependencyDescriptor = dependencyDescriptor;
    ModuleRevisionId dependencyRevisionId = dependencyDescriptor.getDependencyRevisionId();
    requested = new DefaultModuleVersionSelector(dependencyRevisionId.getOrganisation(), dependencyRevisionId.getName(), dependencyRevisionId.getRevision());
}
 
Example 20
Source File: RepositoryResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Override
protected ResolvedResource findResourceUsingPattern(ModuleRevisionId mrid, String pattern,
        Artifact artifact, ResourceMDParser rmdparser, Date date) {
    String name = getName();
    VersionMatcher versionMatcher = getSettings().getVersionMatcher();
    try {
        if (!versionMatcher.isDynamic(mrid) || isAlwaysCheckExactRevision()) {
            String resourceName = IvyPatternHelper.substitute(pattern, mrid, artifact);
            Message.debug("\t trying " + resourceName);
            logAttempt(resourceName);
            Resource res = repository.getResource(resourceName);
            boolean reachable = res.exists();
            if (reachable) {
                String revision;
                if (pattern.contains(IvyPatternHelper.REVISION_KEY)) {
                    revision = mrid.getRevision();
                } else {
                    if ("ivy".equals(artifact.getType()) || "pom".equals(artifact.getType())) {
                        // we can't determine the revision from the pattern, get it
                        // from the module descriptor itself
                        File temp = File.createTempFile("ivy", artifact.getExt());
                        temp.deleteOnExit();
                        repository.get(res.getName(), temp);
                        ModuleDescriptorParser parser = ModuleDescriptorParserRegistry
                                .getInstance().getParser(res);
                        ModuleDescriptor md = parser.parseDescriptor(getParserSettings(), temp
                                .toURI().toURL(), res, false);
                        revision = md.getRevision();
                        if (isNullOrEmpty(revision)) {
                            revision = "working@" + name;
                        }
                    } else {
                        revision = "working@" + name;
                    }
                }
                return new ResolvedResource(res, revision);
            } else if (versionMatcher.isDynamic(mrid)) {
                return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
            } else {
                Message.debug("\t" + name + ": resource not reachable for " + mrid + ": res="
                        + res);
                return null;
            }
        } else {
            return findDynamicResourceUsingPattern(rmdparser, mrid, pattern, artifact, date);
        }
    } catch (IOException | ParseException ex) {
        throw new RuntimeException(name + ": unable to get resource for " + mrid + ": res="
                + IvyPatternHelper.substitute(pattern, mrid, artifact) + ": " + ex, ex);
    }
}