Search in sources :

Example 1 with Resource

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

the class BasicResolver method getDefaultRMDParser.

protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
    return new ResourceMDParser() {

        public MDResolvedResource parse(Resource resource, String rev) {
            DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev));
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(BasicResolver.this, BasicResolver.this, md, madr, isForce()));
        }
    };
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResourceMDParser(org.apache.ivy.plugins.resolver.util.ResourceMDParser) 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) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 2 with Resource

use of org.apache.ivy.plugins.repository.Resource 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 3 with Resource

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

the class IBiblioResolver method listResources.

@Override
protected ResolvedResource[] listResources(Repository repository, ModuleRevisionId mrid, String pattern, Artifact artifact) {
    if (shouldUseMavenMetadata(pattern)) {
        List<String> revs = listRevisionsWithMavenMetadata(repository, mrid.getModuleId().getAttributes());
        if (revs != null) {
            Message.debug("\tfound revs: " + revs);
            List<ResolvedResource> rres = new ArrayList<>();
            for (String rev : revs) {
                ModuleRevisionId historicalMrid = ModuleRevisionId.newInstance(mrid, rev);
                String patternForRev = pattern;
                if (rev.endsWith("SNAPSHOT")) {
                    String snapshotVersion = findTimestampedSnapshotVersion(historicalMrid);
                    if (snapshotVersion != null) {
                        patternForRev = pattern.replaceFirst("\\-\\[revision\\]", "-" + snapshotVersion);
                    }
                }
                String resolvedPattern = IvyPatternHelper.substitute(patternForRev, historicalMrid, artifact);
                try {
                    Resource res = repository.getResource(resolvedPattern);
                    if (res != null) {
                        // we do not test if the resource actually exist here, it would cause
                        // a lot of checks which are not always necessary depending on the usage
                        // which is done of the returned ResolvedResource array
                        rres.add(new ResolvedResource(res, rev));
                    }
                } catch (IOException e) {
                    Message.warn("impossible to get resource from name listed by maven-metadata.xml:" + rres, e);
                }
            }
            return rres.toArray(new ResolvedResource[rres.size()]);
        } else {
            // use default listing capability
            return super.listResources(repository, mrid, pattern, artifact);
        }
    } else {
        return super.listResources(repository, mrid, pattern, artifact);
    }
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) ArrayList(java.util.ArrayList) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IOException(java.io.IOException)

Example 4 with Resource

use of org.apache.ivy.plugins.repository.Resource 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 5 with Resource

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

the class URLRepository method getResource.

public Resource getResource(String source) throws IOException {
    Resource res = resourcesCache.get(source);
    if (res == null) {
        res = new URLResource(new URL(source), this.getTimeoutConstraint());
        resourcesCache.put(source, res);
    }
    return res;
}
Also used : Resource(org.apache.ivy.plugins.repository.Resource) URL(java.net.URL)

Aggregations

Resource (org.apache.ivy.plugins.repository.Resource)20 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)10 File (java.io.File)9 IOException (java.io.IOException)8 URL (java.net.URL)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)5 ArrayList (java.util.ArrayList)4 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)4 FileResource (org.apache.ivy.plugins.repository.file.FileResource)4 MDResolvedResource (org.apache.ivy.plugins.resolver.util.MDResolvedResource)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)2