Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BuildConfig instead of reading version from properties file #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.apache.tools.ant.filters.ReplaceTokens

buildscript {
repositories {
mavenCentral()
Expand All @@ -16,6 +14,7 @@ plugins {
id "maven-publish"
id "org.ajoberstar.github-pages" version "1.7.2"
id "signing"
id "com.github.gmazzo.buildconfig" version "3.1.0"
}

def getProperty = { property ->
Expand Down Expand Up @@ -56,10 +55,8 @@ dependencies {
}


processResources {
filter(ReplaceTokens, tokens: [
version: project.version
])
buildConfig {
buildConfigField("String", "APP_VERSION", provider { "\"${project.version}\"" })
}


Expand Down
41 changes: 3 additions & 38 deletions src/main/java/com/pusher/client/PusherOptions.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.pusher.client;

import java.io.IOException;
import java.io.InputStream;
import com.pusher.pusher_websocket_java.BuildConfig;

import java.net.Proxy;
import java.util.Properties;

/**
* Configuration for a {@link com.pusher.client.Pusher} instance.
*/
public class PusherOptions {

private static final String SRC_LIB_DEV_VERSION = "@version@";
private static final String LIB_DEV_VERSION = "0.0.0-dev";
public static final String LIB_VERSION = readVersionFromProperties();
public static final String LIB_VERSION = BuildConfig.APP_VERSION;

private static final String URI_SUFFIX = "?client=java-client&protocol=5&version=" + LIB_VERSION;
private static final String WS_SCHEME = "ws";
Expand Down Expand Up @@ -315,36 +312,4 @@ public int getMaxReconnectionAttempts() {
public int getMaxReconnectGapInSeconds() {
return maxReconnectGapInSeconds;
}

private static String readVersionFromProperties() {
InputStream inStream = null;
try {
final Properties p = new Properties();
inStream = PusherOptions.class.getResourceAsStream("/pusher.properties");
p.load(inStream);
String version = (String) p.get("version");

// If the properties file contents indicates the version is being run
// from source then replace with a dev indicator. Otherwise the Pusher
// Socket API will reject the connection.
if (version.equals(SRC_LIB_DEV_VERSION)) {
version = LIB_DEV_VERSION;
}

if (version != null && version.length() > 0) {
return version;
}
} catch (final Exception e) {
// Fall back to fixed value
} finally {
try {
if (inStream != null) {
inStream.close();
}
} catch (final IOException e) {
// Ignore problem closing stream
}
}
return "0.0.0";
}
}
2 changes: 0 additions & 2 deletions src/main/resources/pusher.properties

This file was deleted.