Search in sources :

Example 6 with RepoDescriptor

use of org.apache.ivy.osgi.repo.RepoDescriptor 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

RepoDescriptor (org.apache.ivy.osgi.repo.RepoDescriptor)6 URI (java.net.URI)5 Test (org.junit.Test)4 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)1 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)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 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 ModuleDescriptorWrapper (org.apache.ivy.osgi.repo.ModuleDescriptorWrapper)1 UpdateSite (org.apache.ivy.osgi.updatesite.xml.UpdateSite)1 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)1 Ignore (org.junit.Ignore)1 SAXException (org.xml.sax.SAXException)1