Search in sources :

Example 1 with URLResource

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

the class BasicResolver method getArtifactRef.

protected ResolvedResource getArtifactRef(Artifact artifact, Date date) {
    IvyContext.getContext().set(getName() + ".artifact", artifact);
    try {
        ResolvedResource ret = findArtifactRef(artifact, date);
        if (ret == null && artifact.getUrl() != null) {
            URL url = artifact.getUrl();
            Message.verbose("\tusing url for " + artifact + ": " + url);
            logArtifactAttempt(artifact, url.toExternalForm());
            Resource resource;
            if ("file".equals(url.getProtocol())) {
                File f;
                try {
                    f = new File(new URI(url.toExternalForm()));
                } catch (URISyntaxException e) {
                    // unexpected, try to get the best of it
                    f = new File(url.getPath());
                }
                resource = new FileResource(new FileRepository(), f);
            } else {
                resource = new URLResource(url, this.getTimeoutConstraint());
            }
            ret = new ResolvedResource(resource, artifact.getModuleRevisionId().getRevision());
        }
        return ret;
    } finally {
        IvyContext.getContext().set(getName() + ".artifact", null);
    }
}
Also used : FileRepository(org.apache.ivy.plugins.repository.file.FileRepository) 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) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) URL(java.net.URL)

Example 2 with URLResource

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

the class JarResolver method setSettings.

@Override
public void setSettings(ResolverSettings settings) {
    super.setSettings(settings);
    if (url == null) {
        return;
    }
    // let's resolve the url
    ArtifactDownloadReport report;
    EventManager eventManager = getEventManager();
    try {
        if (eventManager != null) {
            getRepository().addTransferListener(eventManager);
        }
        Resource jarResource = new URLResource(url, this.getTimeoutConstraint());
        CacheResourceOptions options = new CacheResourceOptions();
        report = getRepositoryCacheManager().downloadRepositoryResource(jarResource, "jarrepository", "jar", "jar", options, new URLRepository());
    } finally {
        if (eventManager != null) {
            getRepository().removeTransferListener(eventManager);
        }
    }
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        throw new RuntimeException("The jar file " + url.toExternalForm() + " could not be downloaded (" + report.getDownloadDetails() + ")");
    }
    setJarFile(report.getLocalFile());
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) 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) URLRepository(org.apache.ivy.plugins.repository.url.URLRepository)

Example 3 with URLResource

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

the class MirroredURLResolver method downloadMirrorList.

private File downloadMirrorList() {
    final URLRepository urlRepository = new URLRepository(this.getTimeoutConstraint());
    if (getEventManager() != null) {
        urlRepository.addTransferListener(getEventManager());
    }
    final URLResource mirrorResource = new URLResource(mirrorListUrl, this.getTimeoutConstraint());
    CacheResourceOptions options = new CacheResourceOptions();
    ArtifactDownloadReport report = getRepositoryCacheManager().downloadRepositoryResource(mirrorResource, "mirrorlist", "text", "txt", options, urlRepository);
    return report.getLocalFile();
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) URLRepository(org.apache.ivy.plugins.repository.url.URLRepository) RelativeURLRepository(org.apache.ivy.osgi.repo.RelativeURLRepository)

Example 4 with URLResource

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

the class UpdateSiteLoader method loadFromSite.

private UpdateSiteDescriptor loadFromSite(UpdateSite site) throws IOException, SAXException {
    UpdateSiteDescriptor repoDescriptor = new UpdateSiteDescriptor(site.getUri(), ExecutionEnvironmentProfileProvider.getInstance());
    for (EclipseFeature feature : site.getFeatures()) {
        URL url = site.getUri().resolve(feature.getUrl()).toURL();
        final URLResource res = new URLResource(url, this.timeoutConstraint);
        ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, feature.getId(), "feature", "jar", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            return null;
        }
        try (InputStream in = new FileInputStream(report.getLocalFile())) {
            ZipInputStream zipped = findEntry(in, "feature.xml");
            if (zipped == null) {
                return null;
            }
            EclipseFeature f = FeatureParser.parse(zipped);
            f.setURL(feature.getUrl());
            repoDescriptor.addFeature(f);
        }
    }
    return repoDescriptor;
}
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) EclipseFeature(org.apache.ivy.osgi.updatesite.xml.EclipseFeature) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 5 with URLResource

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

the class ResolveEngine method resolve.

/**
 * Resolve dependencies of a module described by an ivy file.
 *
 * @param ivySource URL
 * @param options ResolveOptions
 * @return ResolveReport
 * @throws ParseException if something goes wrong
 * @throws IOException if something goes wrong
 */
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, IOException {
    URLResource res = new URLResource(ivySource);
    ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
    Message.verbose("using " + parser + " to parse " + ivySource);
    ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate());
    String revision = options.getRevision();
    if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) {
        revision = Ivy.getWorkingRevision();
    }
    if (revision != null) {
        md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), revision));
    }
    return resolve(md, options);
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ModuleDescriptorParser(org.apache.ivy.plugins.parser.ModuleDescriptorParser)

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