public List<MavenArtifact> searchSha1(String sha1) throws IOException {
        if (null == sha1 || !sha1.matches("^[0-9A-Fa-f]{40}$")) {
            throw new IllegalArgumentException("Invalid SHA1 format");
        }
        List<MavenArtifact> result = null;
        final URL url = new URL(String.format(query, rootURL, sha1));

        LOGGER.debug("Searching Central url {}", url);

        // Determine if we need to use a proxy. The rules:
        // 1) If the proxy is set, AND the setting is set to true, use the proxy
        // 2) Otherwise, don't use the proxy (either the proxy isn't configured,
        // or proxy is specifically set to false)
        final URLConnectionFactory factory = new URLConnectionFactory(settings);
        final HttpURLConnection conn = factory.createHttpURLConnection(url, useProxy);

        conn.setDoOutput(true);

        // JSON would be more elegant, but there's not currently a dependency
        // on JSON, so don't want to add one just for this
        conn.addRequestProperty("Accept", "application/xml");
        conn.connect();

        if (conn.getResponseCode() == 200) {
            boolean missing = false;
            try {
                final DocumentBuilder builder = XmlUtils.buildSecureDocumentBuilder();
                final Document doc = builder.parse(conn.getInputStream());
                final XPath xpath = XPathFactory.newInstance().newXPath();
                final String numFound = xpath.evaluate("/response/result/@numFound", doc);
                if ("0".equals(numFound)) {
                    missing = true;
                } else {
                    result = new ArrayList<>();
                    final NodeList docs = (NodeList) xpath.evaluate("/response/result/doc", doc, XPathConstants.NODESET);
                    for (int i = 0; i < docs.getLength(); i++) {
                        final String g = xpath.evaluate("./str[@name='g']", docs.item(i));
                        LOGGER.trace("GroupId: {}", g);
                        final String a = xpath.evaluate("./str[@name='a']", docs.item(i));
                        LOGGER.trace("ArtifactId: {}", a);
                        final String v = xpath.evaluate("./str[@name='v']", docs.item(i));
                        final NodeList attributes = (NodeList) xpath.evaluate("./arr[@name='ec']/str", docs.item(i), XPathConstants.NODESET);
                        boolean pomAvailable = false;
                        boolean jarAvailable = false;
                        for (int x = 0; x < attributes.getLength(); x++) {
                            final String tmp = xpath.evaluate(".", attributes.item(x));
                            if (".pom".equals(tmp)) {
                                pomAvailable = true;
                            } else if (".jar".equals(tmp)) {
                                jarAvailable = true;
                            }
                        }

//                        attributes = (NodeList) xpath.evaluate("./arr[@name='tags']/str", docs.item(i), XPathConstants.NODESET);
//                        boolean useHTTPS = true;//false;
//                        for (int x = 0; x < attributes.getLength(); x++) {
//                            final String tmp = xpath.evaluate(".", attributes.item(x));
//                            if ("https".equals(tmp)) {
//                                useHTTPS = true;
//                            }
//                        }
                        LOGGER.trace("Version: {}", v);
                        result.add(new MavenArtifact(g, a, v, jarAvailable, pomAvailable));
                    }
                }
            } catch (ParserConfigurationException | IOException | SAXException | XPathExpressionException e) {
                // Anything else is jacked up XML stuff that we really can't recover from well
                throw new IOException(e.getMessage(), e);
            }

            if (missing) {
                throw new FileNotFoundException("Artifact not found in Central");
            }
        } else {
            final String errorMessage = "Could not connect to MavenCentral (" + conn.getResponseCode() + "): " + conn.getResponseMessage();
            throw new IOException(errorMessage);
        }
        return result;
    }
public List < MavenArtifact > searchSha1 ( String sha1 ) throws IOException { if ( null == sha1 || ! sha1 . matches ( "^[0-9A-Fa-f]{40}$" ) ) { throw new IllegalArgumentException ( "Invalid SHA1 format" ) ; } List < MavenArtifact > result = null ; final URL url = new URL ( String . format ( query , rootURL , sha1 ) ) ; LOGGER . debug ( "Searching Central url {}" , url ) ; final URLConnectionFactory factory = new URLConnectionFactory ( settings ) ; final HttpURLConnection conn = factory . createHttpURLConnection ( url , useProxy ) ; conn . setDoOutput ( true ) ; conn . addRequestProperty ( "Accept" , "application/xml" ) ; conn . connect ( ) ; if ( conn . getResponseCode ( ) == 200 ) { boolean missing = false ; try { final DocumentBuilder builder = XmlUtils . buildSecureDocumentBuilder ( ) ; final Document doc = builder . parse ( conn . getInputStream ( ) ) ; final XPath xpath = XPathFactory . newInstance ( ) . newXPath ( ) ; final String numFound = xpath . evaluate ( "/response/result/@numFound" , doc ) ; if ( "0" . equals ( numFound ) ) { missing = true ; } else { result = new ArrayList < > ( ) ; final NodeList docs = ( NodeList ) xpath . evaluate ( "/response/result/doc" , doc , XPathConstants . NODESET ) ; for ( int i = 0 ; i < docs . getLength ( ) ; i ++ ) { final String g = xpath . evaluate ( "./str[@name='g']" , docs . item ( i ) ) ; LOGGER . trace ( "GroupId: {}" , g ) ; final String a = xpath . evaluate ( "./str[@name='a']" , docs . item ( i ) ) ; LOGGER . trace ( "ArtifactId: {}" , a ) ; final String v = xpath . evaluate ( "./str[@name='v']" , docs . item ( i ) ) ; final NodeList attributes = ( NodeList ) xpath . evaluate ( "./arr[@name='ec']/str" , docs . item ( i ) , XPathConstants . NODESET ) ; boolean pomAvailable = false ; boolean jarAvailable = false ; for ( int x = 0 ; x < attributes . getLength ( ) ; x ++ ) { final String tmp = xpath . evaluate ( "." , attributes . item ( x ) ) ; if ( ".pom" . equals ( tmp ) ) { pomAvailable = true ; } else if ( ".jar" . equals ( tmp ) ) { jarAvailable = true ; } } LOGGER . trace ( "Version: {}" , v ) ; result . add ( new MavenArtifact ( g , a , v , jarAvailable , pomAvailable ) ) ; } } } catch ( ParserConfigurationException | IOException | SAXException | XPathExpressionException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } if ( missing ) { throw new FileNotFoundException ( "Artifact not found in Central" ) ; } } else { final String errorMessage = "Could not connect to MavenCentral (" + conn . getResponseCode ( ) + "): " + conn . getResponseMessage ( ) ; throw new IOException ( errorMessage ) ; } return result ; }
Searches the configured Central URL for the given SHA1 hash. If the
artifact is found, a <code>MavenArtifact</code> is populated with the
GAV.

@param sha1 the SHA-1 hash string for which to search
@return the populated Maven GAV.
@throws FileNotFoundException if the specified artifact is not found
@throws IOException if it's unable to connect to the specified repository