Search in sources :

Example 11 with Resource

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

the class DefaultRepositoryCacheManagerTest method testLatestIntegrationIsCachedPerResolver.

@Test
@Ignore
public void testLatestIntegrationIsCachedPerResolver() throws Exception {
    // given a module org#module
    ModuleId mi = new ModuleId("org", "module");
    // and a latest.integration mrid/dd
    ModuleRevisionId mridLatest = new ModuleRevisionId(mi, "trunk", "latest.integration");
    DependencyDescriptor ddLatest = new DefaultDependencyDescriptor(mridLatest, false);
    // and some random options
    CacheMetadataOptions options = new CacheMetadataOptions().setCheckTTL(false);
    // setup resolver1 to download the static content so we can call cacheModuleDescriptor
    MockResolver resolver = new MockResolver();
    resolver.setName("resolver1");
    resolver.setSettings(ivy.getSettings());
    ivy.getSettings().addResolver(resolver);
    ResourceDownloader downloader = new ResourceDownloader() {

        public void download(Artifact artifact, Resource resource, File dest) throws IOException {
            String content = "<ivy-module version=\"2.0\"><info organisation=\"org\" module=\"module\" status=\"integration\" revision=\"1.1\" branch=\"trunk\"/></ivy-module>";
            dest.getParentFile().mkdirs();
            FileOutputStream out = new FileOutputStream(dest);
            PrintWriter pw = new PrintWriter(out);
            pw.write(content);
            pw.flush();
            out.close();
        }
    };
    ModuleDescriptorWriter writer = new ModuleDescriptorWriter() {

        public void write(ResolvedResource originalMdResource, ModuleDescriptor md, File src, File dest) throws IOException {
            XmlModuleDescriptorWriter.write(md, dest);
        }
    };
    // latest.integration will resolve to 1.1 in resolver1
    ModuleRevisionId mrid11 = new ModuleRevisionId(mi, "trunk", "1.1");
    DefaultArtifact artifact11 = new DefaultArtifact(mrid11, new Date(), "module-1.1.ivy", "ivy", "ivy", true);
    DependencyDescriptor dd11 = new DefaultDependencyDescriptor(mrid11, false);
    BasicResource resource11 = new BasicResource("/module-1-1.ivy", true, 1, 0, true);
    ResolvedResource mdRef11 = new ResolvedResource(resource11, "1.1");
    // tell the cache about 1.1
    ResolvedModuleRevision rmr11 = cacheManager.cacheModuleDescriptor(resolver, mdRef11, dd11, artifact11, downloader, options);
    cacheManager.originalToCachedModuleDescriptor(resolver, mdRef11, artifact11, rmr11, writer);
    // and use the new overload that passes in resolver name
    cacheManager.saveResolvedRevision("resolver1", mridLatest, "1.1");
    ResolvedModuleRevision rmrFromCache = cacheManager.findModuleInCache(ddLatest, mridLatest, options, "resolver1");
    assertEquals(rmr11, rmrFromCache);
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) BasicResource(org.apache.ivy.plugins.repository.BasicResource) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ResourceDownloader(org.apache.ivy.plugins.repository.ResourceDownloader) BasicResource(org.apache.ivy.plugins.repository.BasicResource) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) FileOutputStream(java.io.FileOutputStream) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) XmlModuleDescriptorWriter(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with Resource

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

the class OSGiManifestParserTest method testFileResource.

/**
 * Tests that the
 * {@link OSGiManifestParser#parseDescriptor(ParserSettings, URL, Resource, boolean)}
 * works fine for descriptors that are backed by {@link FileResource}
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testFileResource() throws Exception {
    final File manifestFile = new File("test/repositories/osgi/module1/META-INF/MANIFEST.MF");
    assertTrue("Manifest file is either missing or not a file at " + manifestFile.getAbsolutePath(), manifestFile.isFile());
    final Resource manifestFileResource = new FileResource(null, manifestFile);
    final ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings, manifestFile.toURI().toURL(), manifestFileResource, true);
    assertNotNull("Module descriptor created through a OSGi parser was null", md);
    assertEquals("Unexpected organization name in module descriptor created through a OSGi parser", "bundle", md.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module name in module descriptor created through a OSGi parser", "module1", md.getModuleRevisionId().getName());
    assertEquals("Unexpected version in module descriptor created through a OSGi parser", "1.2.3", md.getModuleRevisionId().getRevision());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Resource(org.apache.ivy.plugins.repository.Resource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) File(java.io.File) Test(org.junit.Test)

Example 13 with Resource

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

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

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

the class RelativeURLRepository method getResource.

public Resource getResource(String source) throws IOException {
    source = encode(source);
    Resource res = resourcesCache.get(source);
    if (res == null) {
        URI uri;
        try {
            uri = new URI(source);
        } catch (URISyntaxException e) {
            // very weird URL, let's assume it is absolute
            uri = null;
        }
        if (uri == null || uri.isAbsolute()) {
            res = new URLResource(new URL(source), getTimeoutConstraint());
        } else {
            res = new URLResource(new URL(baseUrl + source), getTimeoutConstraint());
        }
        resourcesCache.put(source, res);
    }
    return res;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) Resource(org.apache.ivy.plugins.repository.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) 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