Search in sources :

Example 16 with ResolvedResource

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

the class AbstractOSGiResolver method findResource.

@Override
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
    ResolvedResource found = super.findResource(rress, rmdparser, mrid, date);
    if (found == null) {
        return null;
    }
    String osgiType = mrid.getOrganisation();
    // for non bundle requirement : log the selected bundle
    if (!BundleInfo.BUNDLE_TYPE.equals(osgiType)) {
        // several candidates with different symbolic name : make an warning about the ambiguity
        if (rress.length != 1) {
            // several candidates with different symbolic name ?
            Map<String, List<MDResolvedResource>> matching = new HashMap<>();
            for (ResolvedResource rres : rress) {
                String name = ((MDResolvedResource) rres).getResolvedModuleRevision().getDescriptor().getExtraAttribute(CAPABILITY_EXTRA_ATTR);
                List<MDResolvedResource> list = matching.get(name);
                if (list == null) {
                    list = new ArrayList<>();
                    matching.put(name, list);
                }
                list.add((MDResolvedResource) rres);
            }
            if (matching.keySet().size() != 1) {
                if (requirementStrategy == RequirementStrategy.first) {
                    Message.warn("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
                    for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
                        Message.warn("\t" + entry.getKey());
                        for (MDResolvedResource c : entry.getValue()) {
                            Message.warn("\t\t" + c.getRevision() + (found == c ? " (selected)" : ""));
                        }
                    }
                } else if (requirementStrategy == RequirementStrategy.noambiguity) {
                    Message.error("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
                    for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
                        Message.error("\t" + entry.getKey());
                        for (MDResolvedResource c : entry.getValue()) {
                            Message.error("\t\t" + c.getRevision() + (found == c ? " (best match)" : ""));
                        }
                    }
                    return null;
                }
            }
        }
        Message.info("'" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision() + " satisfied by " + ((MDResolvedResource) found).getResolvedModuleRevision().getId().getName() + ";" + found.getRevision());
    }
    return found;
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 17 with ResolvedResource

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

the class UpdateSiteResolver method init.

protected void init() {
    if (url == null) {
        throw new RuntimeException("Missing url");
    }
    CacheResourceOptions options = new CacheResourceOptions();
    if (metadataTtl != null) {
        options.setTtl(metadataTtl);
    }
    if (forceMetadataUpdate != null) {
        options.setForce(forceMetadataUpdate);
    }
    final int log;
    if (logLevel != null) {
        if ("debug".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_DEBUG;
        } else if ("verbose".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_VERBOSE;
        } else if ("info".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_INFO;
        } else if ("warn".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_WARN;
        } else if ("error".equalsIgnoreCase(logLevel)) {
            log = Message.MSG_ERR;
        } else {
            throw new RuntimeException("Unknown log level: " + logLevel);
        }
    } else {
        log = Message.MSG_INFO;
    }
    options.setListener(new DownloadListener() {

        public void startArtifactDownload(RepositoryCacheManager cache, ResolvedResource rres, Artifact artifact, ArtifactOrigin origin) {
            if (log <= Message.MSG_INFO) {
                Message.info("\tdownloading " + rres.getResource().getName());
            }
        }

        public void needArtifact(RepositoryCacheManager cache, Artifact artifact) {
            if (log <= Message.MSG_VERBOSE) {
                Message.verbose("\ttrying to download " + artifact);
            }
        }

        public void endArtifactDownload(RepositoryCacheManager cache, Artifact artifact, ArtifactDownloadReport adr, File archiveFile) {
            if (log <= Message.MSG_VERBOSE) {
                if (adr.isDownloaded()) {
                    Message.verbose("\tdownloaded to " + archiveFile.getAbsolutePath());
                } else {
                    Message.verbose("\tnothing to download");
                }
            }
        }
    });
    final UpdateSiteLoader loader = new UpdateSiteLoader(getRepositoryCacheManager(), getEventManager(), options, this.getTimeoutConstraint());
    loader.setLogLevel(log);
    RepoDescriptor repoDescriptor;
    try {
        repoDescriptor = loader.load(new URI(url));
    } catch (IOException e) {
        throw new RuntimeException("IO issue while trying to read the update site (" + e.getMessage() + ")");
    } catch (ParseException e) {
        throw new RuntimeException("Failed to parse the updatesite (" + e.getMessage() + ")", e);
    } catch (SAXException e) {
        throw new RuntimeException("Ill-formed updatesite (" + e.getMessage() + ")", e);
    } catch (URISyntaxException e) {
        throw new RuntimeException("Ill-formed url (" + e.getMessage() + ")", e);
    }
    if (repoDescriptor == null) {
        setRepoDescriptor(FAILING_REPO_DESCRIPTOR);
        throw new RuntimeException("No update site was found at the location: " + url);
    }
    setRepoDescriptor(repoDescriptor);
}
Also used : RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) URI(java.net.URI) Artifact(org.apache.ivy.core.module.descriptor.Artifact) SAXException(org.xml.sax.SAXException) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) DownloadListener(org.apache.ivy.core.cache.DownloadListener) RepoDescriptor(org.apache.ivy.osgi.repo.RepoDescriptor) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) ParseException(java.text.ParseException) File(java.io.File)

Example 18 with ResolvedResource

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

the class PackagerResolver method findArtifactRef.

// @Override
public synchronized ResolvedResource findArtifactRef(Artifact artifact, Date date) {
    // For our special packager.xml file, defer to superclass
    if (PACKAGER_ARTIFACT_NAME.equals(artifact.getName()) && PACKAGER_ARTIFACT_TYPE.equals(artifact.getType()) && PACKAGER_ARTIFACT_EXT.equals(artifact.getExt())) {
        return super.findArtifactRef(artifact, date);
    }
    // Check the cache
    ModuleRevisionId mr = artifact.getModuleRevisionId();
    PackagerCacheEntry entry = packagerCache.get(mr);
    // Ignore invalid entries
    if (entry != null && !entry.isBuilt()) {
        packagerCache.remove(mr);
        entry.cleanup();
        entry = null;
    }
    // Build the artifacts (if not done already)
    if (entry == null) {
        ResolvedResource packager = findArtifactRef(new DefaultArtifact(mr, null, PACKAGER_ARTIFACT_NAME, PACKAGER_ARTIFACT_TYPE, PACKAGER_ARTIFACT_EXT), date);
        if (packager == null) {
            return null;
        }
        entry = new PackagerCacheEntry(mr, this.buildRoot, this.resourceCache, this.resourceURL, this.validate, this.preserve, this.restricted, this.verbose, this.quiet);
        try {
            entry.build(packager.getResource(), properties);
        } catch (IOException e) {
            throw new RuntimeException("can't build artifact " + artifact, e);
        }
        packagerCache.put(mr, entry);
    }
    // Return reference to desired artifact
    return entry.getBuiltArtifact(artifact);
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IOException(java.io.IOException) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Example 19 with ResolvedResource

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

the class FileSystemResolverTest method testFindIvyFileRefWithMultipleIvyPatterns.

/**
 * Test case for IVY-676.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-676">IVY-676</a>
 */
@Test
public void testFindIvyFileRefWithMultipleIvyPatterns() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/multi-ivypattern/ivy1/ivy-[revision].xml");
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/multi-ivypattern/ivy2/ivy-[revision].xml");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0+");
    ResolvedResource ivyRef = resolver.findIvyFileRef(new DefaultDependencyDescriptor(mrid, false), data);
    // check that the found ivy file is the one from the first pattern!
    assertEquals(new File("test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml").getCanonicalPath(), new File(ivyRef.getResource().getName()).getCanonicalPath());
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Test(org.junit.Test)

Example 20 with ResolvedResource

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

the class BasicResolver method locate.

@Override
public ArtifactOrigin locate(Artifact artifact) {
    ArtifactOrigin origin = getRepositoryCacheManager().getSavedArtifactOrigin(toSystem(artifact));
    if (!ArtifactOrigin.isUnknown(origin)) {
        return origin;
    }
    ResolvedResource artifactRef = getArtifactRef(artifact, null);
    if (artifactRef != null && artifactRef.getResource().exists()) {
        return new ArtifactOrigin(artifact, artifactRef.getResource().isLocal(), artifactRef.getResource().getName());
    }
    return null;
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin)

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