Skip to content
Merged
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
20 changes: 4 additions & 16 deletions core-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
id 'de.fuerstenau.buildconfig' version '1.1.7'
}

dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: jacksonVersion
Expand All @@ -16,16 +12,8 @@ dependencies {
provided group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion, optional
}

apply plugin: 'de.fuerstenau.buildconfig'
apply plugin: 'maven-publish'

buildConfig {
appName = 'core-api'
version = rootProject.version
build << {
// add the build version information into a file that'll go into the distribution
ext.buildVersion = new File(projectDir, "src/main/resources/optimizely-build-version")
buildVersion.text = version
}

sourceSets {
main {
java.srcDir "${buildDir}/gen/buildconfig/src/main/"
}
}
3 changes: 2 additions & 1 deletion core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.optimizely.ab.error.RaiseExceptionErrorHandler;
import com.optimizely.ab.event.EventHandler;
import com.optimizely.ab.event.LogEvent;
import com.optimizely.ab.event.internal.BuildVersionInfo;
import com.optimizely.ab.event.internal.EventBuilder;
import com.optimizely.ab.event.internal.EventBuilderV1;
import com.optimizely.ab.event.internal.EventBuilderV2;
Expand Down Expand Up @@ -695,7 +696,7 @@ public Optimizely build() throws ConfigParseException {
}

if (clientVersion == null) {
clientVersion = BuildConfig.VERSION;
clientVersion = BuildVersionInfo.VERSION;
}

if (eventBuilder == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
*
* Copyright 2016, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.optimizely.ab.event.internal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

import javax.annotation.concurrent.Immutable;

/**
* Helper class to retrieve the SDK version information.
*/
@Immutable
public final class BuildVersionInfo {

private static final Logger logger = LoggerFactory.getLogger(BuildVersionInfo.class);

public final static String VERSION = readVersionNumber();
private static String readVersionNumber() {
BufferedReader bufferedReader =
new BufferedReader(
new InputStreamReader(BuildVersionInfo.class.getResourceAsStream("/optimizely-build-version"),
Charset.forName("UTF-8")));
try {
return bufferedReader.readLine();
} catch (IOException e) {
logger.error("unable to read version number");
return "unknown";
} finally {
try {
bufferedReader.close();
} catch (IOException e) {
logger.error("unable to close reader cleanly");
}
}
}

private BuildVersionInfo() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.optimizely.ab.event.internal;

import com.optimizely.ab.BuildConfig;
import com.optimizely.ab.event.LogEvent;
import com.optimizely.ab.internal.ProjectValidationUtils;
import com.optimizely.ab.bucketing.Bucketer;
Expand Down Expand Up @@ -52,7 +51,7 @@ public class EventBuilderV1 extends EventBuilder {

// offline conversion parameter names and prefixes
private static final String ACCOUNT_ID_PARAM = "d";
private static final String BUILD_VERSION = "java-sdk-" + BuildConfig.VERSION;
private static final String BUILD_VERSION = "java-sdk-" + BuildVersionInfo.VERSION;
private static final String EMPTY_BODY = "";
private static final String EXPERIMENT_PARAM_PREFIX = "x";
private static final String GOAL_ID_PARAM = "g";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.optimizely.ab.event.internal;

import com.optimizely.ab.BuildConfig;
import com.optimizely.ab.annotations.VisibleForTesting;
import com.optimizely.ab.bucketing.Bucketer;
import com.optimizely.ab.config.Attribute;
Expand Down Expand Up @@ -64,7 +63,7 @@ public class EventBuilderV2 extends EventBuilder {
private Serializer serializer;

public EventBuilderV2() {
this(ClientEngine.JAVA_SDK, BuildConfig.VERSION);
this(ClientEngine.JAVA_SDK, BuildVersionInfo.VERSION);
}

public EventBuilderV2(ClientEngine clientEngine, String clientVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.fasterxml.jackson.annotation.JsonValue;

import com.optimizely.ab.BuildConfig;
import com.optimizely.ab.event.internal.BuildVersionInfo;

public class Event {

Expand All @@ -39,7 +39,7 @@ public String getClientEngineValue() {
}

String clientEngine = ClientEngine.JAVA_SDK.getClientEngineValue();
String clientVersion = BuildConfig.VERSION;
String clientVersion = BuildVersionInfo.VERSION;

public String getClientEngine() {
return clientEngine;
Expand Down
2 changes: 1 addition & 1 deletion core-api/src/main/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@

optimizely-build-version
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.optimizely.ab.error.ErrorHandler;
import com.optimizely.ab.error.NoOpErrorHandler;
import com.optimizely.ab.event.EventHandler;
import com.optimizely.ab.event.internal.BuildVersionInfo;
import com.optimizely.ab.event.internal.EventBuilderV2;
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;

Expand Down Expand Up @@ -142,7 +143,7 @@ public void withDefaultClientVersion() throws Exception {
Optimizely optimizelyClient = Optimizely.builder(validConfigJsonV2(), mockEventHandler)
.build();

assertThat(((EventBuilderV2)optimizelyClient.eventBuilder).clientVersion, is(BuildConfig.VERSION));
assertThat(((EventBuilderV2)optimizelyClient.eventBuilder).clientVersion, is(BuildVersionInfo.VERSION));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.gson.Gson;

import com.optimizely.ab.BuildConfig;
import com.optimizely.ab.bucketing.Bucketer;
import com.optimizely.ab.event.LogEvent;
import com.optimizely.ab.config.Attribute;
Expand Down Expand Up @@ -98,7 +97,7 @@ public void createImpressionEvent() throws Exception {
assertThat(impression.getAccountId(), is(projectConfig.getAccountId()));
assertThat(impression.getUserFeatures(), is(expectedUserFeatures));
assertThat(impression.getClientEngine(), is(ClientEngine.JAVA_SDK.getClientEngineValue()));
assertThat(impression.getClientVersion(), is(BuildConfig.VERSION));
assertThat(impression.getClientVersion(), is(BuildVersionInfo.VERSION));
}

/**
Expand Down Expand Up @@ -211,7 +210,7 @@ public void createConversionEvent() throws Exception {
assertFalse(conversion.getIsGlobalHoldback());
assertThat(conversion.getAnonymizeIP(), is(projectConfig.getAnonymizeIP()));
assertThat(conversion.getClientEngine(), is(ClientEngine.JAVA_SDK.getClientEngineValue()));
assertThat(conversion.getClientVersion(), is(BuildConfig.VERSION));
assertThat(conversion.getClientVersion(), is(BuildVersionInfo.VERSION));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions gradle/license.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ subprojects {
apply plugin: 'license'
license {
header rootProject.file('gradle/HEADER')
excludes(['**/*.properties', '**/*.txt', '**/*.conf', '**/*.xml', '**/*.json', '**/LogbackVerifier.java',
'**/BuildConfig.java'])
excludes(['**/*.properties', '**/*.txt', '**/*.conf', '**/*.xml', '**/*.json', '**/LogbackVerifier.java'])
ext.year = '2016' // year that the project was created
}
}