Search in sources :

Example 21 with ResolvedResource

use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.

the class CacheResolver method getDependency.

@Override
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
    clearIvyAttempts();
    ModuleRevisionId mrid = dd.getDependencyRevisionId();
    // check revision
    ResolvedModuleRevision rmr = getRepositoryCacheManager().findModuleInCache(dd, mrid, getCacheOptions(data), null);
    if (rmr != null) {
        Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
        return rmr;
    } else if (!getSettings().getVersionMatcher().isDynamic(mrid)) {
        Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid);
        return null;
    } else {
        ensureConfigured();
        ResolvedResource ivyRef = findIvyFileRef(dd, data);
        if (ivyRef != null) {
            Message.verbose("\t" + getName() + ": found ivy file in cache for " + mrid);
            Message.verbose("\t\t=> " + ivyRef);
            ModuleRevisionId resolvedMrid = ModuleRevisionId.newInstance(mrid, ivyRef.getRevision());
            IvyNode node = data.getNode(resolvedMrid);
            if (node != null && node.getModuleRevision() != null) {
                // this revision has already be resolved : return it
                Message.verbose("\t" + getName() + ": revision already resolved: " + resolvedMrid);
                return node.getModuleRevision();
            }
            rmr = getRepositoryCacheManager().findModuleInCache(dd.clone(ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), ivyRef.getRevision())), dd.getDependencyRevisionId(), getCacheOptions(data), null);
            if (rmr != null) {
                Message.verbose("\t" + getName() + ": revision in cache: " + resolvedMrid);
                return rmr;
            } else {
                Message.error("\t" + getName() + ": inconsistent cache: clean it and resolve again");
                return null;
            }
        } else {
            Message.verbose("\t" + getName() + ": no ivy file in cache found for " + mrid);
            return null;
        }
    }
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 22 with ResolvedResource

use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.

the class IBiblioResolver method findArtifactRef.

@Override
public ResolvedResource findArtifactRef(Artifact artifact, Date date) {
    ensureConfigured(getSettings());
    ModuleRevisionId mrid = artifact.getModuleRevisionId();
    if (isM2compatible()) {
        mrid = convertM2IdForResourceSearch(mrid);
    }
    final String revision = artifact.getId().getRevision();
    final MavenTimedSnapshotVersionMatcher.MavenSnapshotRevision snapshotRevision = MavenTimedSnapshotVersionMatcher.computeIfSnapshot(revision);
    if (snapshotRevision != null) {
        final ResolvedResource rres = findSnapshotArtifact(artifact, date, mrid, snapshotRevision);
        if (rres != null) {
            return rres;
        }
    }
    return findResourceUsingPatterns(mrid, getArtifactPatterns(), artifact, getDefaultRMDParser(artifact.getModuleRevisionId().getModuleId()), date);
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) MavenTimedSnapshotVersionMatcher(org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher)

Example 23 with ResolvedResource

use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.

the class AbstractPatternsBasedResolver method findResourceUsingPatterns.

protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevision, List<String> patternList, Artifact artifact, ResourceMDParser rmdparser, Date date) {
    List<ResolvedResource> resolvedResources = new ArrayList<>();
    Set<String> foundRevisions = new HashSet<>();
    boolean dynamic = getSettings().getVersionMatcher().isDynamic(moduleRevision);
    for (String pattern : patternList) {
        ResolvedResource rres = findResourceUsingPattern(moduleRevision, pattern, artifact, rmdparser, date);
        if (rres != null && !foundRevisions.contains(rres.getRevision())) {
            // only add the first found ResolvedResource for each revision
            foundRevisions.add(rres.getRevision());
            resolvedResources.add(rres);
            if (!dynamic) {
                // stop iterating if we are not searching a dynamic revision
                break;
            }
        }
    }
    if (resolvedResources.size() > 1) {
        ResolvedResource[] rress = resolvedResources.toArray(new ResolvedResource[resolvedResources.size()]);
        return findResource(rress, rmdparser, moduleRevision, date);
    } else if (resolvedResources.size() == 1) {
        return resolvedResources.get(0);
    } else {
        return null;
    }
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with ResolvedResource

use of org.apache.ivy.plugins.resolver.util.ResolvedResource in project ant-ivy by apache.

the class RepositoryResolver method findDynamicResourceUsingPattern.

private ResolvedResource findDynamicResourceUsingPattern(ResourceMDParser rmdparser, ModuleRevisionId mrid, String pattern, Artifact artifact, Date date) {
    String name = getName();
    logAttempt(IvyPatternHelper.substitute(pattern, ModuleRevisionId.newInstance(mrid, IvyPatternHelper.getTokenString(IvyPatternHelper.REVISION_KEY)), artifact));
    ResolvedResource[] rress = listResources(repository, mrid, pattern, artifact);
    if (rress == null) {
        Message.debug("\t" + name + ": unable to list resources for " + mrid + ": pattern=" + pattern);
        return null;
    } else {
        ResolvedResource found = findResource(rress, rmdparser, mrid, date);
        if (found == null) {
            Message.debug("\t" + name + ": no resource found for " + mrid + ": pattern=" + pattern);
        }
        return found;
    }
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource)

Aggregations

ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)24 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)12 MDResolvedResource (org.apache.ivy.plugins.resolver.util.MDResolvedResource)10 File (java.io.File)9 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)8 IOException (java.io.IOException)7 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 Resource (org.apache.ivy.plugins.repository.Resource)6 ParseException (java.text.ParseException)5 ArrayList (java.util.ArrayList)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)4 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)3 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)3 IvyNode (org.apache.ivy.core.resolve.IvyNode)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2