All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.redskap.swagger.brake.maven.MavenMetadataDownloader Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package io.redskap.swagger.brake.maven;

import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import io.redskap.swagger.brake.maven.model.MavenMetadata;
import io.redskap.swagger.brake.util.ExceptionUtils;
import org.springframework.stereotype.Component;

@Component
public class MavenMetadataDownloader {
    public MavenMetadata download(String baseUrl) {
        String metadataUrl = baseUrl + "/maven-metadata.xml";
        try {
            URL url = new URL(metadataUrl);
            return (MavenMetadata) JAXBContext.newInstance(MavenMetadata.class).createUnmarshaller().unmarshal(url);
        } catch (JAXBException | MalformedURLException e) {
            Optional nfe = ExceptionUtils.findInChain(e, FileNotFoundException.class);
            if (nfe.isPresent()) {
                throw new RuntimeException("Cannot download metadata from: " + metadataUrl, e);
            } else {
                throw new RuntimeException("Cannot get metadata", e);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy