Search in sources :

Example 6 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.

the class PomModuleDescriptorParserTest method createIvySettingsForParentLicenseTesting.

private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName, final String parentModuleName) throws Exception {
    final URL parentPomURL = this.getClass().getResource(parentPomFileName);
    assertNotNull("Could not find " + parentPomFileName, parentPomURL);
    final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL));
    final License[] parentLicenses = parentPomReader.getLicenses();
    assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses);
    assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length);
    final DependencyResolver dependencyResolver = new MockedDependencyResolver() {

        @Override
        protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
            final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation();
            final String depModuleName = dependencyDescriptor.getDependencyId().getName();
            if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) {
                final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
                for (final License license : parentLicenses) {
                    moduleDescriptor.addLicense(license);
                }
                return moduleDescriptor;
            } else {
                return super.getModuleDescriptor(dependencyDescriptor);
            }
        }
    };
    final IvySettings ivySettings = new IvySettings();
    ivySettings.setDictatorResolver(dependencyResolver);
    return ivySettings;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) License(org.apache.ivy.core.module.descriptor.License) IvySettings(org.apache.ivy.core.settings.IvySettings) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) URL(java.net.URL) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 7 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.

the class AbstractOSGiResolver method findArtifactRef.

@Override
public ResolvedResource findArtifactRef(Artifact artifact, Date date) {
    URL url = artifact.getUrl();
    if (url == null) {
        // not an artifact resolved by this resolver
        return null;
    }
    Message.verbose("\tusing url for " + artifact + ": " + url);
    logArtifactAttempt(artifact, url.toExternalForm());
    final Resource resource = new URLResource(url, this.getTimeoutConstraint());
    return new ResolvedResource(resource, artifact.getModuleRevisionId().getRevision());
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) URL(java.net.URL)

Example 8 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.

the class OBRResolver method init.

@Override
protected void init() {
    if (repoXmlFile != null && repoXmlURL != null) {
        throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlFile and repoXmlUrl cannot be set both");
    }
    if (repoXmlFile != null) {
        File f = new File(repoXmlFile);
        loadRepoFromFile(f.getParentFile().toURI(), f, repoXmlFile);
    } else if (repoXmlURL != null) {
        final URL url;
        try {
            url = new URL(repoXmlURL);
        } catch (MalformedURLException e) {
            throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlURL '" + repoXmlURL + "' is not an URL");
        }
        ArtifactDownloadReport report;
        EventManager eventManager = getEventManager();
        try {
            if (eventManager != null) {
                getRepository().addTransferListener(eventManager);
            }
            final Resource obrResource = new URLResource(url, this.getTimeoutConstraint());
            CacheResourceOptions options = new CacheResourceOptions();
            if (metadataTtl != null) {
                options.setTtl(metadataTtl);
            }
            if (forceMetadataUpdate != null) {
                options.setForce(forceMetadataUpdate);
            }
            report = getRepositoryCacheManager().downloadRepositoryResource(obrResource, "obr", "obr", "xml", options, getRepository());
        } finally {
            if (eventManager != null) {
                getRepository().removeTransferListener(eventManager);
            }
        }
        URI baseURI;
        try {
            baseURI = new URI(repoXmlURL);
        } catch (URISyntaxException e) {
            throw new RuntimeException("illegal uri");
        }
        loadRepoFromFile(baseURI, report.getLocalFile(), repoXmlURL);
    } else {
        throw new RuntimeException("The OBR repository resolver " + getName() + " couldn't be configured: repoXmlFile or repoXmlUrl is missing");
    }
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) MalformedURLException(java.net.MalformedURLException) EventManager(org.apache.ivy.core.event.EventManager) Resource(org.apache.ivy.plugins.repository.Resource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) URL(java.net.URL)

Example 9 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.

the class UpdateSiteLoader method loadSite.

private UpdateSite loadSite(URI repoUri) throws IOException, SAXException {
    URI siteUri = normalizeSiteUri(repoUri, null);
    URL u = siteUri.resolve("site.xml").toURL();
    final URLResource res = new URLResource(u, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, "site", "updatesite", "xml", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        UpdateSite site = EclipseUpdateSiteParser.parse(in);
        site.setUri(normalizeSiteUri(site.getUri(), siteUri));
        return site;
    }
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) URI(java.net.URI) UpdateSite(org.apache.ivy.osgi.updatesite.xml.UpdateSite) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 10 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource in project ant-ivy by apache.

the class UpdateSiteLoader method loadFromDigest.

private UpdateSiteDescriptor loadFromDigest(UpdateSite site) throws IOException, SAXException {
    URI digestBaseUri = site.getDigestUri();
    if (digestBaseUri == null) {
        digestBaseUri = site.getUri();
    } else if (!digestBaseUri.isAbsolute()) {
        digestBaseUri = site.getUri().resolve(digestBaseUri);
    }
    URL digest = digestBaseUri.resolve("digest.zip").toURL();
    Message.verbose("\tReading " + digest);
    final URLResource res = new URLResource(digest, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, "digest", "digest", "zip", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        return null;
    }
    try (InputStream in = new FileInputStream(report.getLocalFile())) {
        ZipInputStream zipped = findEntry(in, "digest.xml");
        if (zipped == null) {
            return null;
        }
        return UpdateSiteDigestParser.parse(zipped, site);
    }
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) URI(java.net.URI) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Aggregations

URLResource (org.apache.ivy.plugins.repository.url.URLResource)15 URL (java.net.URL)10 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)7 URI (java.net.URI)5 Resource (org.apache.ivy.plugins.repository.Resource)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 URISyntaxException (java.net.URISyntaxException)3 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)3 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)3 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)3 File (java.io.File)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 EventManager (org.apache.ivy.core.event.EventManager)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 IvySettings (org.apache.ivy.core.settings.IvySettings)2 FileResource (org.apache.ivy.plugins.repository.file.FileResource)2 URLRepository (org.apache.ivy.plugins.repository.url.URLRepository)2