private static UpdateInfo getLatestUpdateInfo(URL repoBaseURL, String mavenGroupID, String mavenArtifactID,
                                                  String mavenClassifier, String packaging) throws JDOMException, IOException {
        UpdateInfo res = new UpdateInfo();

        Document mavenMetadata = getMavenMetadata(repoBaseURL, mavenGroupID, mavenArtifactID);

        // get version number
        res.toVersion = new Version(
                mavenMetadata.getRootElement().getChild("versioning").getChild("latest").getValue());

        // get file size
        String url;
        if (!mavenClassifier.equals("")) {
            // classifier specified
            url = repoBaseURL.toString() + "/" + mavenGroupID.replace('.', '/') + "/" + mavenArtifactID + "/"
                    + res.toVersion + "/" + mavenArtifactID + "-" + res.toVersion + "-" + mavenClassifier + "."
                    + packaging;
        } else {
            url = repoBaseURL.toString() + "/" + mavenGroupID.replace('.', '/') + "/" + mavenArtifactID + "/"
                    + res.toVersion + "/" + mavenArtifactID + "-" + res.toVersion + "." + packaging;
        }

        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod("HEAD");
        res.fileSizeInMB = connection.getContentLength();

        if (res.fileSizeInMB != -1) {
            // File size is already known, convert it to mb
            res.fileSizeInMB = res.fileSizeInMB / 1024.0 / 1024.0;
        } else {
            // File size is not known
            try {
                // Try to get redirects
                URLConnection redirURLconn = new URL(connection.getHeaderField("Location")).openConnection();
                res.fileSizeInMB = redirURLconn.getContentLength();

                if (res.fileSizeInMB != -1) {
                    // File size is already known, convert it to mb
                    res.fileSizeInMB = res.fileSizeInMB / 1024.0 / 1024.0;
                }
            } catch (Exception e) {
                FOKLogger.log(UpdateChecker.class.getName(), Level.SEVERE, FOKLogger.DEFAULT_ERROR_TEXT, e);
                res.fileSizeInMB = -1;
            }
        }

        res.mavenArtifactID = mavenArtifactID;
        res.mavenGroupID = mavenGroupID;
        res.mavenClassifier = mavenClassifier;
        res.mavenRepoBaseURL = repoBaseURL;
        res.packaging = packaging;

        return res;
    }
private static UpdateInfo getLatestUpdateInfo ( URL repoBaseURL , String mavenGroupID , String mavenArtifactID , String mavenClassifier , String packaging ) throws JDOMException , IOException { UpdateInfo res = new UpdateInfo ( ) ; Document mavenMetadata = getMavenMetadata ( repoBaseURL , mavenGroupID , mavenArtifactID ) ; res . toVersion = new Version ( mavenMetadata . getRootElement ( ) . getChild ( "versioning" ) . getChild ( "latest" ) . getValue ( ) ) ; String url ; if ( ! mavenClassifier . equals ( "" ) ) { url = repoBaseURL . toString ( ) + "/" + mavenGroupID . replace ( '.' , '/' ) + "/" + mavenArtifactID + "/" + res . toVersion + "/" + mavenArtifactID + "-" + res . toVersion + "-" + mavenClassifier + "." + packaging ; } else { url = repoBaseURL . toString ( ) + "/" + mavenGroupID . replace ( '.' , '/' ) + "/" + mavenArtifactID + "/" + res . toVersion + "/" + mavenArtifactID + "-" + res . toVersion + "." + packaging ; } HttpURLConnection connection = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ; connection . setRequestMethod ( "HEAD" ) ; res . fileSizeInMB = connection . getContentLength ( ) ; if ( res . fileSizeInMB != - 1 ) { res . fileSizeInMB = res . fileSizeInMB / 1024.0 / 1024.0 ; } else { try { URLConnection redirURLconn = new URL ( connection . getHeaderField ( "Location" ) ) . openConnection ( ) ; res . fileSizeInMB = redirURLconn . getContentLength ( ) ; if ( res . fileSizeInMB != - 1 ) { res . fileSizeInMB = res . fileSizeInMB / 1024.0 / 1024.0 ; } } catch ( Exception e ) { FOKLogger . log ( UpdateChecker . class . getName ( ) , Level . SEVERE , FOKLogger . DEFAULT_ERROR_TEXT , e ) ; res . fileSizeInMB = - 1 ; } } res . mavenArtifactID = mavenArtifactID ; res . mavenGroupID = mavenGroupID ; res . mavenClassifier = mavenClassifier ; res . mavenRepoBaseURL = repoBaseURL ; res . packaging = packaging ; return res ; }
Retrieves the {@link UpdateInfo} for the latest version available on the
specified maven repo for the specified artifact.

@param repoBaseURL     The base url where the repo can be reached. For Maven Central,
this is <a href="http://repo1.maven.org/maven/">http://repo1.maven.org/maven/</a>
@param mavenGroupID    The groupID of the artifact to be looked up.
@param mavenArtifactID The artifactId of the artifact to be looked up.
@param mavenClassifier The classifier of the artifact to be looked up.
@return The {@link UpdateInfo} of the latest version of the artifact
available at the specified repository.
@throws JDOMException If mavens {@code maven-metadata.xml} is not parseable (Which
will never be the case unless you don't modify it manually).
@throws IOException   In case mavens {@code maven-metadata.xml} cannot be retrieved
for any other reason.