Search in sources :

Example 1 with Version

use of org.libresonic.player.domain.Version in project libresonic by Libresonic.

the class RESTRequestParameterProcessingFilter method checkAPIVersion.

private RESTController.ErrorCode checkAPIVersion(String version) {
    Version serverVersion = new Version(jaxbWriter.getRestProtocolVersion());
    Version clientVersion = new Version(version);
    if (serverVersion.getMajor() > clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_CLIENT_TOO_OLD;
    } else if (serverVersion.getMajor() < clientVersion.getMajor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    } else if (serverVersion.getMinor() < clientVersion.getMinor()) {
        return RESTController.ErrorCode.PROTOCOL_MISMATCH_SERVER_TOO_OLD;
    }
    return null;
}
Also used : Version(org.libresonic.player.domain.Version)

Example 2 with Version

use of org.libresonic.player.domain.Version in project libresonic by Libresonic.

the class VersionService method readLatestVersion.

/**
     * Resolves the latest available Libresonic version by screen-scraping a web page.
     *
     * @throws IOException If an I/O error occurs.
     */
private void readLatestVersion() throws IOException {
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build();
    HttpGet method = new HttpGet(VERSION_URL + "?v=" + getLocalVersion());
    method.setConfig(requestConfig);
    String content;
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        content = client.execute(method, responseHandler);
    }
    Pattern finalPattern = Pattern.compile("LIBRESONIC_FULL_VERSION_BEGIN(.*)LIBRESONIC_FULL_VERSION_END");
    Pattern betaPattern = Pattern.compile("LIBRESONIC_BETA_VERSION_BEGIN(.*)LIBRESONIC_BETA_VERSION_END");
    try (BufferedReader reader = new BufferedReader(new StringReader(content))) {
        String line = reader.readLine();
        while (line != null) {
            Matcher finalMatcher = finalPattern.matcher(line);
            if (finalMatcher.find()) {
                latestFinalVersion = new Version(finalMatcher.group(1));
                LOG.info("Resolved latest Libresonic final version to: " + latestFinalVersion);
            }
            Matcher betaMatcher = betaPattern.matcher(line);
            if (betaMatcher.find()) {
                latestBetaVersion = new Version(betaMatcher.group(1));
                LOG.info("Resolved latest Libresonic beta version to: " + latestBetaVersion);
            }
            line = reader.readLine();
        }
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Version(org.libresonic.player.domain.Version) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler)

Example 3 with Version

use of org.libresonic.player.domain.Version in project libresonic by Libresonic.

the class VersionService method isNewBetaVersionAvailable.

/**
     * Returns whether a new beta version of Libresonic is available.
     *
     * @return Whether a new beta version of Libresonic is available.
     */
public boolean isNewBetaVersionAvailable() {
    Version latest = getLatestBetaVersion();
    Version local = getLocalVersion();
    if (latest == null || local == null) {
        return false;
    }
    return local.compareTo(latest) < 0;
}
Also used : Version(org.libresonic.player.domain.Version)

Example 4 with Version

use of org.libresonic.player.domain.Version in project libresonic by Libresonic.

the class VersionService method isNewFinalVersionAvailable.

/**
     * Returns whether a new final version of Libresonic is available.
     *
     * @return Whether a new final version of Libresonic is available.
     */
public boolean isNewFinalVersionAvailable() {
    Version latest = getLatestFinalVersion();
    Version local = getLocalVersion();
    if (latest == null || local == null) {
        return false;
    }
    return local.compareTo(latest) < 0;
}
Also used : Version(org.libresonic.player.domain.Version)

Example 5 with Version

use of org.libresonic.player.domain.Version in project libresonic by Libresonic.

the class VersionService method getLocalVersion.

/**
     * Returns the version number for the locally installed Libresonic version.
     *
     * @return The version number for the locally installed Libresonic version.
     */
public synchronized Version getLocalVersion() {
    if (localVersion == null) {
        try {
            localVersion = new Version(readLineFromResource("/version.txt"));
            LOG.info("Resolved local Libresonic version to: " + localVersion);
        } catch (Exception x) {
            LOG.warn("Failed to resolve local Libresonic version.", x);
        }
    }
    return localVersion;
}
Also used : Version(org.libresonic.player.domain.Version)

Aggregations

Version (org.libresonic.player.domain.Version)5 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicResponseHandler (org.apache.http.impl.client.BasicResponseHandler)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1