Search in sources :

Example 1 with FileResource

use of org.apache.ivy.plugins.repository.file.FileResource 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 FileResource

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

the class CacheResolver method download.

@Override
public DownloadReport download(Artifact[] artifacts, DownloadOptions options) {
    ensureConfigured();
    clearArtifactAttempts();
    DownloadReport dr = new DownloadReport();
    for (Artifact artifact : artifacts) {
        final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
        dr.addArtifactReport(adr);
        ResolvedResource artifactRef = getArtifactRef(artifact, null);
        if (artifactRef != null) {
            Message.verbose("\t[NOT REQUIRED] " + artifact);
            ArtifactOrigin origin = new ArtifactOrigin(artifact, true, artifactRef.getResource().getName());
            File archiveFile = ((FileResource) artifactRef.getResource()).getFile();
            adr.setDownloadStatus(DownloadStatus.NO);
            adr.setSize(archiveFile.length());
            adr.setArtifactOrigin(origin);
            adr.setLocalFile(archiveFile);
        } else {
            adr.setDownloadStatus(DownloadStatus.FAILED);
        }
    }
    return dr;
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 3 with FileResource

use of org.apache.ivy.plugins.repository.file.FileResource 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 4 with FileResource

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

the class XmlModuleDescriptorUpdater method update.

public static void update(InputStream in, Resource res, File destFile, UpdateOptions options) throws IOException, SAXException {
    if (destFile.getParentFile() != null) {
        destFile.getParentFile().mkdirs();
    }
    OutputStream fos = new FileOutputStream(destFile);
    try {
        // TODO: use resource as input stream context?
        URL inputStreamContext = null;
        if (res instanceof URLResource) {
            inputStreamContext = ((URLResource) res).getURL();
        } else if (res instanceof FileResource) {
            inputStreamContext = ((FileResource) res).getFile().toURI().toURL();
        }
        update(inputStreamContext, in, fos, options);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            Message.warn("failed to close a stream : " + e.toString());
        }
        try {
            fos.close();
        } catch (IOException e) {
            Message.warn("failed to close a stream : " + e.toString());
        }
    }
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileResource(org.apache.ivy.plugins.repository.file.FileResource) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

FileResource (org.apache.ivy.plugins.repository.file.FileResource)4 File (java.io.File)3 URL (java.net.URL)2 Resource (org.apache.ivy.plugins.repository.Resource)2 URLResource (org.apache.ivy.plugins.repository.url.URLResource)2 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)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 DownloadReport (org.apache.ivy.core.report.DownloadReport)1 FileRepository (org.apache.ivy.plugins.repository.file.FileRepository)1 MDResolvedResource (org.apache.ivy.plugins.resolver.util.MDResolvedResource)1 Test (org.junit.Test)1