Search in sources :

Example 11 with URLResource

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

the class UpdateSiteLoader method readJarOrXml.

private boolean readJarOrXml(URI repoUri, String baseName, XMLInputParser reader) throws IOException, ParseException, SAXException {
    // the input stream from which the xml should be read
    InputStream readIn = null;
    URL contentUrl = repoUri.resolve(baseName + ".jar").toURL();
    URLResource res = new URLResource(contentUrl, this.timeoutConstraint);
    ArtifactDownloadReport report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "jar", options, urlRepository);
    if (report.getDownloadStatus() == DownloadStatus.FAILED) {
        // no jar file, try the xml one
        contentUrl = repoUri.resolve(baseName + ".xml").toURL();
        res = new URLResource(contentUrl, this.timeoutConstraint);
        report = repositoryCacheManager.downloadRepositoryResource(res, baseName, baseName, "xml", options, urlRepository);
        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
            // no xml either
            return false;
        }
        readIn = new FileInputStream(report.getLocalFile());
    } else {
        InputStream in = new FileInputStream(report.getLocalFile());
        try {
            // compressed, let's get the pointer on the actual xml
            readIn = findEntry(in, baseName + ".xml");
            if (readIn == null) {
                in.close();
                return false;
            }
        } catch (IOException e) {
            in.close();
            throw e;
        }
    }
    try {
        reader.parse(readIn);
    } finally {
        readIn.close();
    }
    return true;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 12 with URLResource

use of org.apache.ivy.plugins.repository.url.URLResource 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)

Example 13 with URLResource

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

the class IvyConvertPom method doExecute.

public void doExecute() throws BuildException {
    try {
        if (pomFile == null) {
            throw new BuildException("source pom file is required for convertpom task");
        }
        if (ivyFile == null) {
            throw new BuildException("destination ivy file is required for convertpom task");
        }
        ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(getSettings(), pomFile.toURI().toURL(), false);
        PomModuleDescriptorParser.getInstance().toIvyFile(pomFile.toURI().toURL().openStream(), new URLResource(pomFile.toURI().toURL()), getIvyFile(), md);
    } catch (MalformedURLException e) {
        throw new BuildException("unable to convert given pom file to url: " + pomFile + ": " + e, e);
    } catch (ParseException e) {
        log(e.getMessage(), Project.MSG_ERR);
        throw new BuildException("syntax errors in pom file " + pomFile + ": " + e, e);
    } catch (Exception e) {
        throw new BuildException("impossible convert given pom file to ivy file: " + e + " from=" + pomFile + " to=" + ivyFile, e);
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) URLResource(org.apache.ivy.plugins.repository.url.URLResource) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException)

Example 14 with URLResource

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

the class PomModuleDescriptorParserTest method testDependenciesWithClassifier.

@Test
public void testDependenciesWithClassifier() throws Exception {
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-dependencies-with-classifier.pom"), true);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(1, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.0.4"), dds[0].getDependencyRevisionId());
    Map<String, String> extraAtt = Collections.singletonMap("classifier", "asl");
    assertEquals(1, dds[0].getAllDependencyArtifacts().length);
    assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());
    // now we verify the conversion to an Ivy file
    PomModuleDescriptorParser.getInstance().toIvyFile(getClass().getResource("test-dependencies-with-classifier.pom").openStream(), new URLResource(getClass().getResource("test-dependencies-with-classifier.pom")), dest, md);
    assertTrue(dest.exists());
    // the converted Ivy file should be parsable with validate=true
    ModuleDescriptor md2 = XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), dest.toURI().toURL(), true);
    // and the parsed module descriptor should be similar to the original
    assertNotNull(md2);
    assertEquals(md.getModuleRevisionId(), md2.getModuleRevisionId());
    dds = md2.getDependencies();
    assertEquals(1, dds[0].getAllDependencyArtifacts().length);
    assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0].getExtraAttributes());
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) URLResource(org.apache.ivy.plugins.repository.url.URLResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Example 15 with URLResource

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

URLResource (org.apache.ivy.plugins.repository.url.URLResource)15 URL (java.net.URL)10 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)7 URI (java.net.URI)5 Resource (org.apache.ivy.plugins.repository.Resource)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 URISyntaxException (java.net.URISyntaxException)3 CacheResourceOptions (org.apache.ivy.core.cache.CacheResourceOptions)3 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)3 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)3 File (java.io.File)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 EventManager (org.apache.ivy.core.event.EventManager)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 IvySettings (org.apache.ivy.core.settings.IvySettings)2 FileResource (org.apache.ivy.plugins.repository.file.FileResource)2 URLRepository (org.apache.ivy.plugins.repository.url.URLRepository)2