Search in sources :

Example 1 with CacheResourceOptions

use of org.apache.ivy.core.cache.CacheResourceOptions 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 2 with CacheResourceOptions

use of org.apache.ivy.core.cache.CacheResourceOptions 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 3 with CacheResourceOptions

use of org.apache.ivy.core.cache.CacheResourceOptions in project ant-ivy by apache.

the class UpdateSiteLoaderTest method setUp.

@Before
public void setUp() {
    IvySettings ivySettings = new IvySettings();
    cache = new File("build/cache");
    cache.mkdirs();
    ivySettings.setDefaultCache(cache);
    CacheResourceOptions options = new CacheResourceOptions();
    loader = new UpdateSiteLoader(ivySettings.getDefaultRepositoryCacheManager(), null, options, null);
}
Also used : IvySettings(org.apache.ivy.core.settings.IvySettings) CacheResourceOptions(org.apache.ivy.core.cache.CacheResourceOptions) File(java.io.File) Before(org.junit.Before)

Example 4 with CacheResourceOptions

use of org.apache.ivy.core.cache.CacheResourceOptions 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 5 with CacheResourceOptions

use of org.apache.ivy.core.cache.CacheResourceOptions 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)

Aggregations

CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)4 File (java.io.File)3 URLResource (org.apache.ivy.plugins.repository.url.URLResource)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 EventManager (org.apache.ivy.core.event.EventManager)2 Resource (org.apache.ivy.plugins.repository.Resource)2 URLRepository (org.apache.ivy.plugins.repository.url.URLRepository)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)1 DownloadListener (org.apache.ivy.core.cache.DownloadListener)1 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 IvySettings (org.apache.ivy.core.settings.IvySettings)1 RelativeURLRepository (org.apache.ivy.osgi.repo.RelativeURLRepository)1 RepoDescriptor (org.apache.ivy.osgi.repo.RepoDescriptor)1